1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.geometry.core;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
22
23 import org.apache.commons.geometry.core.partitioning.test.PartitionTestUtils;
24 import org.apache.commons.geometry.core.partitioning.test.TestLine;
25 import org.apache.commons.geometry.core.partitioning.test.TestPoint1D;
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 EmbeddingTest {
31
32 @Test
33 void testToSubspace_collection_emptyInput() {
34
35 final TestLine line = TestLine.Y_AXIS;
36
37
38 final List<TestPoint1D> result = line.toSubspace(new ArrayList<>());
39
40
41 Assertions.assertEquals(0, result.size());
42 }
43
44 @Test
45 void testToSubspace_collection() {
46
47 final List<TestPoint2D> pts = Arrays.asList(
48 new TestPoint2D(0, 0),
49 new TestPoint2D(1, 0.25),
50 new TestPoint2D(0.5, 1)
51 );
52
53 final TestLine line = TestLine.Y_AXIS;
54
55
56 final List<TestPoint1D> result = line.toSubspace(pts);
57
58
59 Assertions.assertEquals(3, result.size());
60 Assertions.assertEquals(0, result.get(0).getX(), PartitionTestUtils.EPS);
61 Assertions.assertEquals(0.25, result.get(1).getX(), PartitionTestUtils.EPS);
62 Assertions.assertEquals(1, result.get(2).getX(), PartitionTestUtils.EPS);
63 }
64
65 @Test
66 void testToSpace_collection_emptyInput() {
67
68 final TestLine line = TestLine.Y_AXIS;
69
70
71 final List<TestPoint2D> result = line.toSpace(new ArrayList<>());
72
73
74 Assertions.assertEquals(0, result.size());
75 }
76
77 @Test
78 void testToSpace_collection() {
79
80 final List<TestPoint1D> pts = Arrays.asList(
81 new TestPoint1D(0),
82 new TestPoint1D(1),
83 new TestPoint1D(0.5)
84 );
85
86 final TestLine line = TestLine.Y_AXIS;
87
88
89 final List<TestPoint2D> result = line.toSpace(pts);
90
91
92 Assertions.assertEquals(3, result.size());
93 PartitionTestUtils.assertPointsEqual(new TestPoint2D(0, 0), result.get(0));
94 PartitionTestUtils.assertPointsEqual(new TestPoint2D(0, 1), result.get(1));
95 PartitionTestUtils.assertPointsEqual(new TestPoint2D(0, 0.5), result.get(2));
96 }
97 }