use of com.github.mikephil.charting.data.ScatterDataSet in project MPAndroidChart by PhilJay.
the class DataSetTest method testGetEntryForXValueWithDuplicates.
@Test
public void testGetEntryForXValueWithDuplicates() {
// sorted list of values (by x position)
List<Entry> values = new ArrayList<Entry>();
values.add(new Entry(0, 10));
values.add(new Entry(1, 20));
values.add(new Entry(2, 30));
values.add(new Entry(3, 40));
// duplicate
values.add(new Entry(3, 50));
values.add(new Entry(4, 60));
// duplicate
values.add(new Entry(4, 70));
values.add(new Entry(5, 80));
values.add(new Entry(6, 90));
values.add(new Entry(7, 100));
values.add(new Entry(8, 110));
// duplicate
values.add(new Entry(8, 120));
ScatterDataSet set = new ScatterDataSet(values, "");
Entry closest = set.getEntryForXValue(0, Float.NaN, DataSet.Rounding.CLOSEST);
assertEquals(0, closest.getX(), 0.01f);
assertEquals(10, closest.getY(), 0.01f);
closest = set.getEntryForXValue(5, Float.NaN, DataSet.Rounding.CLOSEST);
assertEquals(5, closest.getX(), 0.01f);
assertEquals(80, closest.getY(), 0.01f);
closest = set.getEntryForXValue(5.4f, Float.NaN, DataSet.Rounding.CLOSEST);
assertEquals(5, closest.getX(), 0.01f);
assertEquals(80, closest.getY(), 0.01f);
closest = set.getEntryForXValue(4.6f, Float.NaN, DataSet.Rounding.CLOSEST);
assertEquals(5, closest.getX(), 0.01f);
assertEquals(80, closest.getY(), 0.01f);
closest = set.getEntryForXValue(7, Float.NaN, DataSet.Rounding.CLOSEST);
assertEquals(7, closest.getX(), 0.01f);
assertEquals(100, closest.getY(), 0.01f);
closest = set.getEntryForXValue(4f, Float.NaN, DataSet.Rounding.CLOSEST);
assertEquals(4, closest.getX(), 0.01f);
assertEquals(60, closest.getY(), 0.01f);
List<Entry> entries = set.getEntriesForXValue(4f);
assertEquals(2, entries.size());
assertEquals(60, entries.get(0).getY(), 0.01f);
assertEquals(70, entries.get(1).getY(), 0.01f);
entries = set.getEntriesForXValue(3.5f);
assertEquals(0, entries.size());
entries = set.getEntriesForXValue(2f);
assertEquals(1, entries.size());
assertEquals(30, entries.get(0).getY(), 0.01f);
}
Aggregations