2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.sparky.analytics;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.aai.sparky.analytics.HistoricalCounter;
31 public class HistoricalCounterTest {
34 private HistoricalCounter historicalCounter;
35 private HistoricalCounter historicalCount;
37 public void init() throws Exception {
38 historicalCounter = new HistoricalCounter(true);
39 historicalCount = new HistoricalCounter(false);
43 public void successfullInitialization() {
44 assertEquals(-1, historicalCounter.getMin(),0);
45 assertEquals(0, historicalCounter.getMax(),0);
46 assertEquals(0, historicalCounter.getNumSamples(),0);
47 assertEquals(0, historicalCounter.getNumSamples(),0);
48 assertEquals(0.0, historicalCounter.getValue(),0);
49 assertEquals(0, historicalCounter.getAvg(),0);
50 assertTrue(historicalCounter.isSingleValue());
55 public void updateValuesAndReset() {
56 historicalCounter.update(-1);
57 assertEquals(0, historicalCounter.getValue(),0);
58 historicalCounter.update(10);
59 assertEquals(10, historicalCounter.getValue(),0);
60 historicalCounter.reset();
61 assertEquals(-1, historicalCounter.getMin(),0);
62 assertEquals(0, historicalCounter.getMax(),0);
63 assertEquals(0, historicalCounter.getNumSamples(),0);
64 assertEquals(0, historicalCounter.getNumSamples(),0);
65 assertEquals(0.0, historicalCounter.getValue(),0);
70 public void updateValues() {
71 historicalCount.update(2);
72 assertEquals(2, historicalCount.getMin(),0);
73 historicalCount.setMin(10);
74 historicalCount.update(3);
75 assertEquals(3, historicalCount.getMin(),0);
76 historicalCount.setMax(1);
77 historicalCount.update(4);
78 assertEquals(4, historicalCount.getMax(),0);
79 historicalCount.setTotalOfSamples(10);
80 historicalCount.setNumSamples(2);
81 assertEquals(5, historicalCount.getAvg(),0);
82 historicalCount.setTotalOfSamples(10);
83 assertEquals(10, historicalCount.getTotalOfSamples(),0);
84 historicalCount.setMaintainSingleValue(true);
85 assertTrue(historicalCounter.isSingleValue());