1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.geometry.core.partitioning;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.stream.Collectors;
24
25 import org.apache.commons.geometry.core.partitioning.test.TestLineSegment;
26 import org.apache.commons.geometry.core.partitioning.test.TestPoint2D;
27 import org.junit.jupiter.api.Assertions;
28 import org.junit.jupiter.api.Test;
29
30 class BoundaryListTest {
31
32 @Test
33 void testBoundaries() {
34
35 final List<TestLineSegment> boundaries = new ArrayList<>();
36 boundaries.add(new TestLineSegment(0, 0, 1, 1));
37 boundaries.add(new TestLineSegment(1, 1, 0, 2));
38
39
40 final BoundaryList<TestPoint2D, TestLineSegment> list = new BoundaryList<>(boundaries);
41
42
43 Assertions.assertNotSame(boundaries, list.getBoundaries());
44 Assertions.assertEquals(boundaries, list.getBoundaries());
45 Assertions.assertEquals(boundaries, list.boundaryStream().collect(Collectors.toList()));
46 }
47
48 @Test
49 void testGetBoundaries_listCannotBeModified() {
50
51 final List<TestLineSegment> boundaries = new ArrayList<>();
52 boundaries.add(new TestLineSegment(0, 0, 1, 1));
53
54 final BoundaryList<TestPoint2D, TestLineSegment> list = new BoundaryList<>(boundaries);
55 final List<TestLineSegment> items = list.getBoundaries();
56 final TestLineSegment segment = new TestLineSegment(1, 1, 0, 2);
57
58
59 Assertions.assertThrows(UnsupportedOperationException.class, () -> items.add(segment));
60 }
61
62 @Test
63 void testCount() {
64
65 Assertions.assertEquals(0, new BoundaryList<>(Collections.emptyList()).count());
66 Assertions.assertEquals(1, new BoundaryList<>(Collections.singletonList(
67 new TestLineSegment(0, 0, 1, 1)
68 )).count());
69 Assertions.assertEquals(2, new BoundaryList<>(Arrays.asList(
70 new TestLineSegment(0, 0, 1, 1),
71 new TestLineSegment(1, 1, 0, 2)
72 )).count());
73 }
74
75 @Test
76 void testToString() {
77
78 final BoundaryList<TestPoint2D, TestLineSegment> empty = new BoundaryList<>(Collections.emptyList());
79 final BoundaryList<TestPoint2D, TestLineSegment> single = new BoundaryList<>(Collections.singletonList(
80 new TestLineSegment(0, 0, 1, 1)
81 ));
82
83
84 Assertions.assertEquals("BoundaryList[count= 0]", empty.toString());
85 Assertions.assertEquals("BoundaryList[count= 1]", single.toString());
86 }
87 }