blob: 0a87635a7efa718eae862fd33b84cf336fa854b5 [file] [log] [blame]
Jian Lib6859e12016-03-01 09:29:24 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jian Lib6859e12016-03-01 09:29:24 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ui.chart;
17
18import org.junit.Test;
19
Jian Lib6859e12016-03-01 09:29:24 -080020import static org.junit.Assert.assertEquals;
Jian Lib6859e12016-03-01 09:29:24 -080021
22/**
23 * Unit tests for {@link ChartModel}.
24 */
25public class ChartModelTest {
26
27 private static final String FOO = "foo";
28 private static final String BAR = "bar";
29 private static final String ZOO = "zoo";
30
31 private static final Double[] VALUES1 = {0D, 1D, 2D};
32 private static final Double[] VALUES2 = {3D, 4D, 5D};
33 private static final Double[] VALUES3 = {6D, 7D, 8D};
34
Jian Lib6859e12016-03-01 09:29:24 -080035 private ChartModel cm;
36
37 @Test(expected = NullPointerException.class)
38 public void guardAgainstNullSeries() {
Jian Li15468822016-04-15 16:28:11 -070039 cm = new ChartModel(null);
Jian Lib6859e12016-03-01 09:29:24 -080040 }
41
42 @Test
43 public void testSeriesCount() {
Jian Li15468822016-04-15 16:28:11 -070044 cm = new ChartModel(FOO, BAR, ZOO);
Jian Lib6859e12016-03-01 09:29:24 -080045 assertEquals("Wrong series count", 3, cm.seriesCount());
46 }
47
48 @Test
Jian Li15468822016-04-15 16:28:11 -070049 public void emptyLabel() {
50 cm = new ChartModel(FOO, BAR, ZOO);
51 cm.addDataPoint(System.currentTimeMillis());
52
53 assertEquals("bad data point count", 1, cm.dataPointCount());
54 }
55
56 @Test(expected = IllegalArgumentException.class)
57 public void dataPointBandSeries() {
58 cm = new ChartModel(FOO, BAR);
59
60 cm.addDataPoint(System.currentTimeMillis())
61 .data(ZOO, VALUES3[0]);
62 }
63
64 @Test
Jian Lib6859e12016-03-01 09:29:24 -080065 public void testAddDataPoint() {
Jian Li15468822016-04-15 16:28:11 -070066 cm = new ChartModel(FOO, BAR, ZOO);
Jian Lib6859e12016-03-01 09:29:24 -080067
Jian Li15468822016-04-15 16:28:11 -070068 long time = System.currentTimeMillis();
Jian Lib6859e12016-03-01 09:29:24 -080069
Jian Li15468822016-04-15 16:28:11 -070070 cm.addDataPoint(time)
71 .data(FOO, VALUES1[0])
72 .data(BAR, VALUES2[0])
73 .data(ZOO, VALUES3[0]);
Jian Lib6859e12016-03-01 09:29:24 -080074
Jian Li15468822016-04-15 16:28:11 -070075 cm.addDataPoint(time + 1)
76 .data(FOO, VALUES1[1])
77 .data(BAR, VALUES2[1])
78 .data(ZOO, VALUES3[1]);
Jian Lib6859e12016-03-01 09:29:24 -080079
Jian Li15468822016-04-15 16:28:11 -070080 cm.addDataPoint(time + 2)
81 .data(FOO, VALUES1[2])
82 .data(BAR, VALUES2[2])
83 .data(ZOO, VALUES3[2]);
84
85 assertEquals("Wrong result", 3, cm.getDataPoints()[0].size());
86 assertEquals("Wrong result", 3, cm.getDataPoints()[1].size());
87 assertEquals("Wrong result", 3, cm.getDataPoints()[2].size());
88 assertEquals("Wrong result", 3, cm.getDataPoints().length);
Jian Lib6859e12016-03-01 09:29:24 -080089 }
90
91 @Test
Jian Li15468822016-04-15 16:28:11 -070092 public void testGetDataPoint() {
93 cm = new ChartModel(FOO, BAR);
Jian Lib6859e12016-03-01 09:29:24 -080094
Jian Li15468822016-04-15 16:28:11 -070095 long time = System.currentTimeMillis();
Jian Lib6859e12016-03-01 09:29:24 -080096
Jian Li15468822016-04-15 16:28:11 -070097 cm.addDataPoint(time)
98 .data(FOO, VALUES1[0])
99 .data(BAR, VALUES2[0]);
100
101 cm.addDataPoint(time + 1)
102 .data(FOO, VALUES1[1])
103 .data(BAR, VALUES2[1]);
104
105 assertEquals("Wrong result", (Double) 0D, cm.getDataPoints()[0].get(FOO));
106 assertEquals("Wrong result", (Double) 1D, cm.getDataPoints()[1].get(FOO));
107 assertEquals("Wrong result", (Double) 3D, cm.getDataPoints()[0].get(BAR));
108 assertEquals("Wrong result", (Double) 4D, cm.getDataPoints()[1].get(BAR));
Jian Lib6859e12016-03-01 09:29:24 -0800109 }
110
111 @Test
Jian Li15468822016-04-15 16:28:11 -0700112 public void testGetLastDataPoint() {
113 cm = new ChartModel(FOO, BAR);
Jian Lib6859e12016-03-01 09:29:24 -0800114
Jian Li15468822016-04-15 16:28:11 -0700115 long time = System.currentTimeMillis();
116
117 cm.addDataPoint(time)
118 .data(FOO, VALUES1[0])
119 .data(BAR, VALUES2[0]);
120
121 cm.addDataPoint(time + 1)
122 .data(FOO, VALUES1[1])
123 .data(BAR, VALUES2[1]);
124
125 assertEquals("Wrong result", VALUES1[1], cm.getLastDataPoint().get(FOO));
126 assertEquals("Wrong result", VALUES2[1], cm.getLastDataPoint().get(BAR));
Jian Lib6859e12016-03-01 09:29:24 -0800127 }
128}