1 package uk.co.jezuk.mango; 2 3 import junit.framework.*; 4 5 public class CountIfTest extends TestCase 6 { 7 java.util.List list; 8 9 public CountIfTest(String name) { super(name); } 10 public static Test suite() { return new TestSuite(CountIfTest.class); } 11 12 protected void setUp() 13 { 14 list = new java.util.ArrayList (); 15 for(int i = 0; i < 10; ++i) 16 list.add(new Integer (i)); 17 } 19 public void test1() 20 { 21 assertEquals(0, Algorithms.countIf(list, Bind.First(Predicates.EqualTo(), new String ("hello")))); 22 assertEquals(0, Algorithms.countIf(list, Bind.First(Predicates.EqualTo(), null))); 23 assertEquals(1, Algorithms.countIf(list, Bind.First(Predicates.EqualTo(), new Integer (5)))); 24 list.add(new Integer (5)); 25 list.add(new Integer (5)); 26 list.add(new Integer (5)); 27 list.add(new Integer (5)); 28 assertEquals(5, Algorithms.countIf(list, Bind.First(Predicates.EqualTo(), new Integer (5)))); 29 } 31 public void test2() 32 { 33 assertEquals(10, Algorithms.countIf(list, Bind.First(Predicates.NotEqualTo(), new String ("hello")))); 34 assertEquals(10, Algorithms.countIf(list, Bind.First(Predicates.NotEqualTo(), null))); 35 assertEquals(9, Algorithms.countIf(list, Bind.First(Predicates.NotEqualTo(), new Integer (5)))); 36 list.add(new Integer (5)); 37 list.add(new Integer (5)); 38 list.add(new Integer (5)); 39 list.add(new Integer (5)); 40 assertEquals(9, Algorithms.countIf(list, Bind.First(Predicates.NotEqualTo(), new Integer (5)))); 41 } } | Popular Tags |