1 package net.sourceforge.jpotpourri.fprog;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7 import junit.framework.TestCase;
8 import net.sourceforge.jpotpourri.fprog.predsfuncs.IBinaryFunction;
9
10
11
12
13 public class FpTest extends TestCase {
14
15
16
17
18
19
20
21
22
23 public final void testReduce() {
24 List<Integer> list = new ArrayList<Integer>();
25 list.add(3);
26 list.add(6);
27 list.add(2);
28 list = Collections.unmodifiableList(list);
29
30 final IBinaryFunction<Integer, Integer> reduceNums = new IBinaryFunction<Integer, Integer>() {
31 public Integer execute(final Integer t1, final Integer t2) {
32 return t1.intValue() + t2.intValue();
33 }
34 };
35
36 assertEquals(11, Fp.reduce(reduceNums, list, 0).intValue());
37 assertEquals(21, Fp.reduce(reduceNums, list, 10).intValue());
38
39 }
40
41 }