-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathMapFuncTest.java
More file actions
35 lines (30 loc) · 1.12 KB
/
MapFuncTest.java
File metadata and controls
35 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package MapFunc;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
public class MapFuncTest {
@Test
public void testSingleTypeMap() throws Exception {
// Given an integer array list
ArrayList<Integer> intList = new ArrayList<>();
intList.add(1);
intList.add(2);
// When it's mapped with a function to double the value
ArrayList<Integer> mappedList = MapFunc.map(intList, num -> num * 2);
// Then all the values are doubled
Assert.assertEquals(new Integer(2), mappedList.get(0));
Assert.assertEquals(new Integer(4), mappedList.get(1));
}
@Test
public void testMultipleTypeMap() throws Exception {
// Given an integer array list
ArrayList<Integer> intList = new ArrayList<>();
intList.add(1);
intList.add(2);
// When it's mapped with to string
ArrayList<String> mappedList = MapFunc.map(intList, num -> num.toString());
// Then all the values are doubled
Assert.assertEquals("1", mappedList.get(0));
Assert.assertEquals("2", mappedList.get(1));
}
}