You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Alex Herbert <al...@gmail.com> on 2019/09/27 19:29:32 UTC
Re: [commons-geometry] branch master updated: Unit tests.
> On 27 Sep 2019, at 17:10, erans@apache.org wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> erans pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/commons-geometry.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
> new 7178525 Unit tests.
> 7178525 is described below
>
> commit 7178525a1c4327cf37db5d71b4ebceba3440041d
> Author: Gilles Sadowski <gi...@harfang.homelinux.org>
> AuthorDate: Fri Sep 27 18:09:52 2019 +0200
>
> Unit tests.
> ---
> .../org/apache/commons/geometry/euclidean/oned/Vector1DTest.java | 7 +++++++
> .../org/apache/commons/geometry/euclidean/threed/Vector3DTest.java | 7 +++++++
> .../org/apache/commons/geometry/euclidean/twod/Vector2DTest.java | 7 +++++++
> 3 files changed, 21 insertions(+)
>
> diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
> index 1b58077..e1fc1f6 100644
> --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
> +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/oned/Vector1DTest.java
> @@ -684,6 +684,13 @@ public class Vector1DTest {
> -17, Vector1D.of(19)), -139);
> }
>
> + @Test
> + public void testUnitFactoryOptimization() {
> + // An already normalized vector will avoid unnecessary creation.
> + final Vector1D v = Vector1D.of(3).normalize();
> + Assert.assertTrue(v.normalize() == v);
Assert.assertSame(v, v.normalize());
Yes, it does the same thing but assertTrue only when there is not a more explicit assertion. You get a better fail message if it does ever fail.
> + }
> +
> private void checkVector(Vector1D v, double x) {
> Assert.assertEquals(x, v.getX(), TEST_TOLERANCE);
> }
> diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java
> index f876dff..03f90c0 100644
> --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java
> +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/threed/Vector3DTest.java
> @@ -1207,6 +1207,13 @@ public class Vector3DTest {
> checkVector(Vector3D.linearCombination(-3, p1, 2, p2, -4, p3, 5, p4), -64, -78, -2);
> }
>
> + @Test
> + public void testUnitFactoryOptimization() {
> + // An already normalized vector will avoid unnecessary creation.
> + final Vector3D v = Vector3D.of(3, 4, 5).normalize();
> + Assert.assertTrue(v.normalize() == v);
> + }
> +
> private void checkVector(Vector3D v, double x, double y, double z) {
> Assert.assertEquals(x, v.getX(), EPS);
> Assert.assertEquals(y, v.getY(), EPS);
> diff --git a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java
> index 70adf0b..d693a5a 100644
> --- a/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java
> +++ b/commons-geometry-euclidean/src/test/java/org/apache/commons/geometry/euclidean/twod/Vector2DTest.java
> @@ -1023,6 +1023,13 @@ public class Vector2DTest {
> checkVector(Vector2D.linearCombination(-3, p1, 2, p2, -4, p3, 5, p4), -64, -78);
> }
>
> + @Test
> + public void testUnitFactoryOptimization() {
> + // An already normalized vector will avoid unnecessary creation.
> + final Vector2D v = Vector2D.of(4, 5).normalize();
> + Assert.assertTrue(v.normalize() == v);
> + }
> +
> private void checkVector(Vector2D v, double x, double y) {
> checkVector(v, x, y, EPS);
> }
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org