Added testLocalDateLocalDateTimeConsistency().
@@ -7,12 +7,15 @@ package net.finmath.time;
import java.time.LocalDate;
import java.time.LocalDateTime;
+import java.time.LocalTime;
import org.junit.Assert;
import org.junit.Test;
public class FloatingpointDateTest {
+ private static final long SECONDS_PER_DAY = 365*24*60*60;
+
/**
* Unit test for a roundtrip that the double representation is 1:1 to a LocalDate representation (up to days).
*/
@@ -29,6 +32,22 @@ public class FloatingpointDateTest {
}
}
+ /**
+ * Unit test comparing the LocalDate function to the LocalDateTime function.
+ */
+ @Test
+ public void testLocalDateLocalDateTimeConsistency() {
+ LocalDate referenceDate = LocalDate.of(2016, 01, 01);
+ for(int i=0; i<1000; i++) {
+ LocalDate date = referenceDate.plusDays(i);
+
+ double floatingPointDate = FloatingpointDate.getFloatingPointDateFromDate(referenceDate, date);
+ double floatingPointDateTime = FloatingpointDate.getFloatingPointDateFromDate(LocalDateTime.of(referenceDate, LocalTime.of(12, 00)), LocalDateTime.of(date, LocalTime.of(12, 00)));
+
+ Assert.assertEquals("Comparing Date to DateTime", floatingPointDate, floatingPointDateTime, 0.2/SECONDS_PER_DAY);
+ }
+ }
+
/**
* Unit test for a roundtrip that the double representation is 1:1 to a LocalDate representation (up to days).
*/
