View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    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.Assert;
    28  import org.junit.Test;
    29
    30  public class EmbeddingTest {
    31
    32      @Test
    33      public void testToSubspace_collection_emptyInput() {
    34          // arrange
    35          final TestLine line = TestLine.Y_AXIS;
    36
    37          // act
    38          final List<TestPoint1D> result = line.toSubspace(new ArrayList<>());
    39
    40          // assert
    41          Assert.assertEquals(0, result.size());
    42      }
    43
    44      @Test
    45      public void testToSubspace_collection() {
    46          // arrange
    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          // act
    56          final List<TestPoint1D> result = line.toSubspace(pts);
    57
    58          // assert
    59          Assert.assertEquals(3, result.size());
    60          Assert.assertEquals(0, result.get(0).getX(), PartitionTestUtils.EPS);
    61          Assert.assertEquals(0.25, result.get(1).getX(), PartitionTestUtils.EPS);
    62          Assert.assertEquals(1, result.get(2).getX(), PartitionTestUtils.EPS);
    63      }
    64
    65      @Test
    66      public void testToSpace_collection_emptyInput() {
    67          // arrange
    68          final TestLine line = TestLine.Y_AXIS;
    69
    70          // act
    71          final List<TestPoint2D> result = line.toSpace(new ArrayList<>());
    72
    73          // assert
    74          Assert.assertEquals(0, result.size());
    75      }
    76
    77      @Test
    78      public void testToSpace_collection() {
    79          // arrange
    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          // act
    89          final List<TestPoint2D> result = line.toSpace(pts);
    90
    91          // assert
    92          Assert.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  }