1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.chromium.latency.walt;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
@RunWith(PowerMockRunner.class)
@PrepareForTest(android.graphics.Color.class)
public class HistogramChartTest {
private BarData barData;
private HistogramChart.HistogramData data;
@Before
public void setUp() {
mockStatic(android.graphics.Color.class);
when(android.graphics.Color.rgb(anyInt(), anyInt(), anyInt())).thenReturn(0);
barData = new BarData();
barData.setBarWidth((1f - HistogramChart.GROUP_SPACE)/1);
barData.addDataSet(new BarDataSet(new ArrayList<BarEntry>(), "SomeLabel"));
data = new HistogramChart.HistogramData(1, 5f);
data.addEntry(barData, 0, 12);
data.addEntry(barData, 0, 14);
data.addEntry(barData, 0, 16);
data.addEntry(barData, 0, 21);
}
@Test
public void testBinHeights() {
final IBarDataSet barDataSet = barData.getDataSetByIndex(0);
assertEquals(3, barDataSet.getEntryCount());
assertEquals(2d, barDataSet.getEntryForIndex(0).getY(), 0.000001);
assertEquals(1d, barDataSet.getEntryForIndex(1).getY(), 0.000001);
assertEquals(1d, barDataSet.getEntryForIndex(2).getY(), 0.000001);
}
@Test
public void testBinXPositions() {
final IBarDataSet barDataSet = barData.getDataSetByIndex(0);
assertEquals(3, barDataSet.getEntryCount());
assertEquals(0d + 0.05d + 0.45d, barDataSet.getEntryForIndex(0).getX(), 0.000001);
assertEquals(1d + 0.05d + 0.45d, barDataSet.getEntryForIndex(1).getX(), 0.000001);
assertEquals(2d + 0.05d + 0.45d, barDataSet.getEntryForIndex(2).getX(), 0.000001);
}
@Test
public void testDisplayValue() {
assertEquals(10d, data.getMinBin(), 0.000001);
assertEquals(15d, data.getDisplayValue(1), 0.000001);
}
}
|