EmptyTest.java (941B)
1 import org.junit.jupiter.api.Test; 2 3 import static org.junit.jupiter.api.Assertions.*; 4 5 class EmptyTest { 6 7 Cons<Integer> empty = new Empty<>(); 8 9 @Test 10 void testFirst() { 11 assertThrows(UnsupportedOperationException.class, () -> empty.first()); 12 } 13 14 @Test 15 void testRest() { 16 assertThrows(UnsupportedOperationException.class, () -> empty.rest()); 17 } 18 19 @Test 20 void testMap() { 21 assertEquals(new Empty<>(), empty.map(n -> n+1)); 22 } 23 24 @Test 25 void testFilter() { 26 assertEquals(new Empty<>(), empty.filter(n -> n>4)); 27 } 28 29 @Test 30 void testFoldl() { 31 assertEquals(4, empty.foldl(Integer::sum, 4)); 32 } 33 34 @Test 35 void testFoldr() { 36 assertEquals(4, empty.foldr(Integer::sum, 4)); 37 } 38 39 @Test 40 void testEmpty() { 41 assertTrue(empty.empty()); 42 } 43 44 @Test 45 void testToString() { 46 assertEquals("empty", empty.toString()); 47 } 48 }