KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > co > jezuk > mango > CountIfTest


1 package uk.co.jezuk.mango;
2
3 import junit.framework.*;
4
5 public class CountIfTest extends TestCase
6 {
7   java.util.List JavaDoc list;
8
9   public CountIfTest(String JavaDoc 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 JavaDoc();
15     for(int i = 0; i < 10; ++i)
16       list.add(new Integer JavaDoc(i));
17   } // setUp
18

19   public void test1()
20   {
21     assertEquals(0, Algorithms.countIf(list, Bind.First(Predicates.EqualTo(), new String JavaDoc("hello"))));
22     assertEquals(0, Algorithms.countIf(list, Bind.First(Predicates.EqualTo(), null)));
23     assertEquals(1, Algorithms.countIf(list, Bind.First(Predicates.EqualTo(), new Integer JavaDoc(5))));
24     list.add(new Integer JavaDoc(5));
25     list.add(new Integer JavaDoc(5));
26     list.add(new Integer JavaDoc(5));
27     list.add(new Integer JavaDoc(5));
28     assertEquals(5, Algorithms.countIf(list, Bind.First(Predicates.EqualTo(), new Integer JavaDoc(5))));
29   } //
30

31   public void test2()
32   {
33     assertEquals(10, Algorithms.countIf(list, Bind.First(Predicates.NotEqualTo(), new String JavaDoc("hello"))));
34     assertEquals(10, Algorithms.countIf(list, Bind.First(Predicates.NotEqualTo(), null)));
35     assertEquals(9, Algorithms.countIf(list, Bind.First(Predicates.NotEqualTo(), new Integer JavaDoc(5))));
36     list.add(new Integer JavaDoc(5));
37     list.add(new Integer JavaDoc(5));
38     list.add(new Integer JavaDoc(5));
39     list.add(new Integer JavaDoc(5));
40     assertEquals(9, Algorithms.countIf(list, Bind.First(Predicates.NotEqualTo(), new Integer JavaDoc(5))));
41   } //
42
} // CountIfTest
43
Popular Tags