assertEquals(10, top2.length);
}
@Test
public void testFiltering() {
DiscreteDistribution d1 = new DiscreteDistribution(new int[] {1,1,1,8,8,8,9,22,22,22,22,22,333,333,333,333,333,333,333,333});
assertEquals(3, d1.getCount(1));
assertEquals(3, d1.getCount(8));
assertEquals(1, d1.getCount(9));
assertEquals(5, d1.getCount(22));
assertEquals(8, d1.getCount(333));
DiscreteDistribution notReallyFiltered = d1.filteredAndShift(1);
assertTrue(notReallyFiltered == d1);
DiscreteDistribution filtered = d1.filteredAndShift(4);
assertEquals(0, filtered.getCount(1));
assertEquals(0, filtered.getCount(8));
assertEquals(0, filtered.getCount(9));
assertEquals(5 - 3, filtered.getCount(22));
assertEquals(8 - 3, filtered.getCount(333));
assertEquals(2, filtered.size());
// Check that avoided ones are not filtered
DiscreteDistribution filteredWithAnAvoid = DiscreteDistribution.merge(d1,
DiscreteDistribution.createAvoidanceDistribution(new int[]{99, 108})).filteredAndShift(4);
assertEquals(0, filteredWithAnAvoid.getCount(1));
assertEquals(0, filteredWithAnAvoid.getCount(8));
assertEquals(0, filteredWithAnAvoid.getCount(9));
assertEquals(5 - 3, filteredWithAnAvoid.getCount(22));
assertEquals(8 - 3, filteredWithAnAvoid.getCount(333));
assertEquals(-1, filteredWithAnAvoid.getCount(99));
assertEquals(-1, filteredWithAnAvoid.getCount(108));
DiscreteDistribution filteredAll = d1.filteredAndShift(100);
DiscreteDistribution filteredAll2 = filtered.filteredAndShift(100);
assertEquals(0, filteredAll.getCount(1));
assertEquals(0, filteredAll.getCount(8));
assertEquals(0, filteredAll.getCount(9));
assertEquals(0, filteredAll.getCount(22));
assertEquals(0, filteredAll.getCount(333));
assertEquals(0, filteredAll2.getCount(1));
assertEquals(0, filteredAll2.getCount(8));
assertEquals(0, filteredAll2.getCount(9));
assertEquals(0, filteredAll2.getCount(22));
assertEquals(0, filteredAll2.getCount(333));
assertEquals(0, filteredAll.size());
assertEquals(0, filteredAll2.size());
}