sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: More tests about temporal functions.
Date Mon, 26 Aug 2019 12:37:13 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new b4d7b41  More tests about temporal functions.
b4d7b41 is described below

commit b4d7b415c32bb0db1241c79b9c5e45af0e003cf1
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Aug 26 14:36:54 2019 +0200

    More tests about temporal functions.
---
 .../java/org/apache/sis/filter/PeriodLiteral.java  | 19 +++---
 .../apache/sis/filter/TemporalFunctionTest.java    | 73 ++++++++++++++++++++--
 2 files changed, 77 insertions(+), 15 deletions(-)

diff --git a/core/sis-feature/src/test/java/org/apache/sis/filter/PeriodLiteral.java b/core/sis-feature/src/test/java/org/apache/sis/filter/PeriodLiteral.java
index e626ff2..2b587a9 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/filter/PeriodLiteral.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/filter/PeriodLiteral.java
@@ -17,7 +17,6 @@
 package org.apache.sis.filter;
 
 import java.util.Date;
-import java.util.Objects;
 import java.io.Serializable;
 import org.opengis.temporal.Period;
 import org.opengis.temporal.Duration;
@@ -43,10 +42,9 @@ import org.apache.sis.test.TestUtilities;
 @SuppressWarnings("serial")
 final strictfp class PeriodLiteral implements Period, Literal, Serializable {
     /**
-     * Period beginning and ending.
-     * Pattern is {@code "yyyy-MM-dd HH:mm:ss"} in UTC timezone.
+     * Period beginning and ending, in milliseconds since Java epoch.
      */
-    public String begin, end;
+    public long begin, end;
 
     /**
      * Returns the constant value held by this object.
@@ -66,10 +64,10 @@ final strictfp class PeriodLiteral implements Period, Literal, Serializable
{
     @Override public org.opengis.temporal.Instant getEnding()    {return instant(end);}
 
     /** Wraps the value that defines a period. */
-    private static org.opengis.temporal.Instant instant(final String t) {
+    private static org.opengis.temporal.Instant instant(final long t) {
         return new org.opengis.temporal.Instant() {
-            @Override public Date   getDate()  {return TestUtilities.date(t);}
-            @Override public String toString() {return "Instant[" + t + '[';}
+            @Override public Date   getDate()  {return new Date(t);}
+            @Override public String toString() {return "Instant[" + TestUtilities.format(getDate())
+ '[';}
 
             /** Not needed for the tests. */
             @Override public Identifier       getName()                              {throw
new UnsupportedOperationException();}
@@ -91,7 +89,7 @@ final strictfp class PeriodLiteral implements Period, Literal, Serializable
{
      */
     @Override
     public int hashCode() {
-        return Objects.hash(begin, end);
+        return Long.hashCode(begin) + Long.hashCode(end) * 7;
     }
 
     /**
@@ -101,7 +99,7 @@ final strictfp class PeriodLiteral implements Period, Literal, Serializable
{
     public boolean equals(final Object other) {
         if (other instanceof PeriodLiteral) {
             final PeriodLiteral p = (PeriodLiteral) other;
-            return Objects.equals(begin, p.begin) && Objects.equals(end, p.end);
+            return begin == p.begin && end == p.end;
         }
         return false;
     }
@@ -111,6 +109,7 @@ final strictfp class PeriodLiteral implements Period, Literal, Serializable
{
      */
     @Override
     public String toString() {
-        return "Period[" + begin + " ... " + end + ']';
+        return "Period[" + TestUtilities.format(new Date(begin)) +
+                 " ... " + TestUtilities.format(new Date(end)) + ']';
     }
 }
diff --git a/core/sis-feature/src/test/java/org/apache/sis/filter/TemporalFunctionTest.java
b/core/sis-feature/src/test/java/org/apache/sis/filter/TemporalFunctionTest.java
index 057d604..c46c512 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/filter/TemporalFunctionTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/filter/TemporalFunctionTest.java
@@ -18,10 +18,12 @@ package org.apache.sis.filter;
 
 import org.opengis.filter.FilterFactory;
 import org.opengis.filter.temporal.BinaryTemporalOperator;
+import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
+import static org.apache.sis.internal.util.StandardDateFormat.MILLISECONDS_PER_DAY;
 
 
 /**
@@ -48,7 +50,6 @@ public final strictfp class TemporalFunctionTest extends TestCase {
     /**
      * The expression to test. They are the arguments to be given to {@link #factory} method.
      * Each expression will return a period made of {@link PeriodLiteral#begin} and {@link
PeriodLiteral#end}.
-     * Date pattern is {@code "yyyy-MM-dd HH:mm:ss"} in UTC timezone.
      */
     private final PeriodLiteral expression1, expression2;
 
@@ -59,10 +60,8 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         factory = new DefaultFilterFactory();
         expression1 = new PeriodLiteral();
         expression2 = new PeriodLiteral();
-        expression1.begin = expression2.begin = "2010-04-20 10:00:00";
-        expression1.end   = expression2.end   = "2010-04-25 15:00:00";
-        expression1.begin = expression2.begin = "2010-04-20 10:00:00";
-        expression1.end   = expression2.end   = "2010-04-25 15:00:00";
+        expression1.begin = expression2.begin = TestUtilities.date("2000-01-01 09:00:00").getTime();
+        expression1.end   = expression2.end   = TestUtilities.date("2000-01-05 10:00:00").getTime();
     }
 
     /**
@@ -94,6 +93,8 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.tequals(expression1, expression2);
         validate("TEquals");
         assertTrue(evaluate());
+        expression1.end++;
+        assertFalse(evaluate());
     }
 
     /**
@@ -104,6 +105,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.before(expression1, expression2);
         validate("Before");
         assertFalse(evaluate());
+        expression1.begin -= 10 * MILLISECONDS_PER_DAY;
+        expression1.end   -= 10 * MILLISECONDS_PER_DAY;
+        assertTrue(evaluate());
+        expression1.end = expression2.begin;
+        assertFalse(evaluate());
     }
 
     /**
@@ -114,6 +120,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.after(expression1, expression2);
         validate("After");
         assertFalse(evaluate());
+        expression1.begin += 10 * MILLISECONDS_PER_DAY;
+        expression1.end   += 10 * MILLISECONDS_PER_DAY;
+        assertTrue(evaluate());
+        expression1.begin = expression2.end;
+        assertFalse(evaluate());
     }
 
     /**
@@ -124,6 +135,10 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.begins(expression1, expression2);
         validate("Begins");
         assertFalse(evaluate());
+        expression1.end--;
+        assertTrue(evaluate());
+        expression1.begin++;
+        assertFalse(evaluate());
     }
 
     /**
@@ -134,6 +149,10 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.ends(expression1, expression2);
         validate("Ends");
         assertFalse(evaluate());
+        expression1.begin++;
+        assertTrue(evaluate());
+        expression1.end--;
+        assertFalse(evaluate());
     }
 
     /**
@@ -144,6 +163,10 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.begunBy(expression1, expression2);
         validate("BegunBy");
         assertFalse(evaluate());
+        expression1.end++;
+        assertTrue(evaluate());
+        expression1.begin--;
+        assertFalse(evaluate());
     }
 
     /**
@@ -154,6 +177,10 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.endedBy(expression1, expression2);
         validate("EndedBy");
         assertFalse(evaluate());
+        expression1.begin--;
+        assertTrue(evaluate());
+        expression1.end++;
+        assertFalse(evaluate());
     }
 
     /**
@@ -164,6 +191,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.meets(expression1, expression2);
         validate("Meets");
         assertFalse(evaluate());
+        expression1.begin -= 10 * MILLISECONDS_PER_DAY;
+        expression1.end   -= 10 * MILLISECONDS_PER_DAY;
+        assertFalse(evaluate());
+        expression1.end = expression2.begin;
+        assertTrue(evaluate());
     }
 
     /**
@@ -174,6 +206,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.metBy(expression1, expression2);
         validate("MetBy");
         assertFalse(evaluate());
+        expression1.begin += 10 * MILLISECONDS_PER_DAY;
+        expression1.end   += 10 * MILLISECONDS_PER_DAY;
+        assertFalse(evaluate());
+        expression1.begin = expression2.end;
+        assertTrue(evaluate());
     }
 
     /**
@@ -184,6 +221,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.during(expression1, expression2);
         validate("During");
         assertFalse(evaluate());
+        expression1.begin++;
+        expression1.end--;
+        assertTrue(evaluate());
+        expression1.end += 2;
+        assertFalse(evaluate());
     }
 
     /**
@@ -194,6 +236,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.tcontains(expression1, expression2);
         validate("TContains");
         assertFalse(evaluate());
+        expression1.begin--;
+        expression1.end++;
+        assertTrue(evaluate());
+        expression1.end -= 2;
+        assertFalse(evaluate());
     }
 
     /**
@@ -204,6 +251,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.toverlaps(expression1, expression2);
         validate("TOverlaps");
         assertFalse(evaluate());
+        expression1.begin--;
+        expression1.end--;
+        assertTrue(evaluate());
+        expression1.end += 2;
+        assertFalse(evaluate());
     }
 
     /**
@@ -214,6 +266,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.overlappedBy(expression1, expression2);
         validate("OverlappedBy");
         assertFalse(evaluate());
+        expression1.begin++;
+        expression1.end++;
+        assertTrue(evaluate());
+        expression1.end -= 2;
+        assertFalse(evaluate());
     }
 
     /**
@@ -224,5 +281,11 @@ public final strictfp class TemporalFunctionTest extends TestCase {
         filter = factory.anyInteracts(expression1, expression2);
         validate("AnyInteracts");
         assertTrue(evaluate());
+        expression1.begin++;
+        assertTrue(evaluate());
+        expression1.begin -= 2;
+        assertTrue(evaluate());
+        expression1.end += 2;
+        assertTrue(evaluate());
     }
 }


Mime
View raw message