Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

flaky fixes #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/test/java/com/zavtech/morpheus/array/ArrayBuilderTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
Expand Down Expand Up @@ -349,11 +350,11 @@ public void testWithLocalDateTimes(int initialSize) {
Assert.assertEquals(actual.length(), expected.length, "The lengths match");
Assert.assertEquals(actual.typeCode(), ArrayType.LOCAL_DATETIME, "The array type is as expected");
for (int i=0; i<expected.length; ++i) {
Assert.assertEquals(actual.getValue(i), expected[i], "The values match at " + i);
Assert.assertEquals(actual.getValue(i), expected[i].truncatedTo(ChronoUnit.MILLIS), "The values match at " + i);
}
final Array<LocalDateTime> collected = Stream.of(expected).collect(ArrayUtils.toArray(expected.length));
for (int i=0; i<expected.length; ++i) {
Assert.assertEquals(collected.getValue(i), expected[i], "The values match at " + i);
Assert.assertEquals(collected.getValue(i), expected[i].truncatedTo(ChronoUnit.MILLIS), "The values match at " + i);
}
}

Expand All @@ -370,11 +371,11 @@ public void testWithZonedDateTimes(int initialSize) {
Assert.assertEquals(actual.length(), expected.length, "The lengths match");
Assert.assertEquals(actual.typeCode(), ArrayType.ZONED_DATETIME, "The array type is as expected");
for (int i=0; i<expected.length; ++i) {
Assert.assertEquals(actual.getValue(i), expected[i], "The values match at " + i);
Assert.assertEquals(actual.getValue(i), expected[i].truncatedTo(ChronoUnit.MILLIS), "The values match at " + i);
}
final Array<ZonedDateTime> collected = Stream.of(expected).collect(ArrayUtils.toArray(expected.length));
for (int i=0; i<expected.length; ++i) {
Assert.assertEquals(collected.getValue(i), expected[i], "The values match at " + i);
Assert.assertEquals(collected.getValue(i), expected[i].truncatedTo(ChronoUnit.MILLIS), "The values match at " + i);
}
}

Expand Down Expand Up @@ -408,11 +409,19 @@ public void testWithMixedTypes(int initialSize) {
Assert.assertEquals(actual.length(), expected.length, "The lengths match");
Assert.assertEquals(actual.typeCode(), ArrayType.OBJECT, "The array type is as expected");
for (int i=0; i<expected.length; ++i) {
Assert.assertEquals(actual.getValue(i), expected[i], "The values match at " + i);
Object frmtValue = expected[i];
if(expected[i].getClass().getName() == "java.time.ZonedDateTime"){
frmtValue = ((ZonedDateTime) frmtValue).truncatedTo(ChronoUnit.MILLIS);
}
Assert.assertEquals(actual.getValue(i),frmtValue, "The values match at " + i);
}
final Array<Object> collected = Stream.of(expected).collect(ArrayUtils.toArray(expected.length));
for (int i=0; i<expected.length; ++i) {
Assert.assertEquals(collected.getValue(i), expected[i], "The values match at " + i);
Object frmtValue = expected[i];
if(expected[i].getClass().getName() == "java.time.ZonedDateTime"){
frmtValue = ((ZonedDateTime) frmtValue).truncatedTo(ChronoUnit.MILLIS);
}
Assert.assertEquals(collected.getValue(i), frmtValue, "The values match at " + i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Random;

import org.testng.Assert;
Expand Down Expand Up @@ -92,8 +93,8 @@ public void testZonedDateTime() {
array2[i] = value;
}
for (int i=0; i<count; ++i) {
final ZonedDateTime v1 = array1.getValue(i);
final ZonedDateTime v2 = array2[i];
final ZonedDateTime v1 = array1.getValue(i).truncatedTo(ChronoUnit.MILLIS);
final ZonedDateTime v2 = array2[i].truncatedTo(ChronoUnit.MILLIS);
Assert.assertEquals(v1, v2);
System.out.println(v1);
}
Expand Down
23 changes: 13 additions & 10 deletions src/test/java/com/zavtech/morpheus/array/ArraysBasicTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Currency;
Expand Down Expand Up @@ -604,14 +605,14 @@ public void testLocalDateTimeArray(boolean sparse) {
array.setValue(i, value);
}
for (int i=0; i<values.length; ++i) {
final LocalDateTime v1 = values[i];
final LocalDateTime v1 = values[i].truncatedTo(ChronoUnit.MILLIS);
final LocalDateTime v2 = array.getValue(i);
Assert.assertEquals(v1, v2, "Values match at " + i);
}
array.expand(200);
Assert.assertEquals(array.length(), 200, "The array was expanded");
for (int i=0; i<values.length; ++i) {
final LocalDateTime v1 = values[i];
final LocalDateTime v1 = values[i].truncatedTo(ChronoUnit.MILLIS);
final LocalDateTime v2 = array.getValue(i);
Assert.assertEquals(v1, v2, "Values match at " + i);
}
Expand All @@ -625,7 +626,7 @@ public void testLocalDateTimeArray(boolean sparse) {
array.setValue(i, value);
}
for (int i=100; i<200; ++i) {
final LocalDateTime v1 = values[i-100];
final LocalDateTime v1 = values[i-100].truncatedTo(ChronoUnit.MILLIS);
final LocalDateTime v2 = array.getValue(i);
Assert.assertEquals(v1, v2, "Values match at " + i);
}
Expand All @@ -650,14 +651,14 @@ public void testZonedDateTimeArray(boolean sparse) {
array.setValue(i, value);
}
for (int i=0; i<values.length; ++i) {
final ZonedDateTime v1 = values[i];
final ZonedDateTime v1 = values[i].truncatedTo(ChronoUnit.MILLIS);
final ZonedDateTime v2 = array.getValue(i);
Assert.assertEquals(v1, v2, "Values match at " + i);
}
array.expand(200);
Assert.assertEquals(array.length(), 200, "The array was expanded");
for (int i=0; i<values.length; ++i) {
final ZonedDateTime v1 = values[i];
final ZonedDateTime v1 = values[i].truncatedTo(ChronoUnit.MILLIS);
final ZonedDateTime v2 = array.getValue(i);
Assert.assertEquals(v1, v2, "Values match at " + i);
}
Expand All @@ -672,7 +673,7 @@ public void testZonedDateTimeArray(boolean sparse) {
array.setValue(i, value);
}
for (int i=100; i<200; ++i) {
final ZonedDateTime v1 = values[i-100];
final ZonedDateTime v1 = values[i-100].truncatedTo(ChronoUnit.MILLIS);
final ZonedDateTime v2 = array.getValue(i);
Assert.assertEquals(v1, v2, "Values match at " + i);
}
Expand Down Expand Up @@ -818,13 +819,15 @@ public <T> void testFill(Class<T> type, ArrayStyle style) {
T value = (T)LocalDateTime.now();
array.fill(value);
for (int i=0; i<array.length(); ++i) {
Assert.assertEquals(array.getValue(i), value, "Values match at " + i);
LocalDateTime formattedValue = ((LocalDateTime) value).truncatedTo(ChronoUnit.MILLIS);
Assert.assertEquals(array.getValue(i), formattedValue, "Values match at " + i);
}
} else if (array.typeCode() == ArrayType.ZONED_DATETIME) {
T value = (T)ZonedDateTime.now();
array.fill(value);
for (int i=0; i<array.length(); ++i) {
Assert.assertEquals(array.getValue(i), value, "Values match at " + i);
ZonedDateTime formattedValue = ((ZonedDateTime) value).truncatedTo(ChronoUnit.MILLIS);
Assert.assertEquals(array.getValue(i), formattedValue, "Values match at " + i);
}
} else if (array.typeCode() == ArrayType.OBJECT) {
T value = (T)new Double(7d);
Expand Down Expand Up @@ -968,12 +971,12 @@ public <T> void testFirstAndLast(Class<T> type, ArrayStyle style) {
assertFirstAndLast(array, values, arrayType);
} else if (arrayType == ArrayType.LOCAL_DATETIME) {
final LocalDateTime[] values = new LocalDateTime[1000];
for (int i=0; i<values.length; ++i) values[i] = LocalDateTime.now().plusSeconds(i);
for (int i=0; i<values.length; ++i) values[i] = LocalDateTime.now().plusSeconds(i).truncatedTo(ChronoUnit.MILLIS);
final Array<LocalDateTime> array = Array.of((Class<LocalDateTime>)type, values.length, null, style).applyValues(v -> values[v.index()]);
assertFirstAndLast(array, values, arrayType);
} else if (arrayType == ArrayType.ZONED_DATETIME) {
final ZonedDateTime[] values = new ZonedDateTime[1000];
for (int i=0; i<values.length; ++i) values[i] = ZonedDateTime.now().plusSeconds(i);
for (int i=0; i<values.length; ++i) values[i] = ZonedDateTime.now().plusSeconds(i).truncatedTo(ChronoUnit.MILLIS);
final Array<ZonedDateTime> array = Array.of((Class<ZonedDateTime>)type, values.length, null, style).applyValues(v -> values[v.index()]);
assertFirstAndLast(array, values, arrayType);
} else if (arrayType == ArrayType.OBJECT) {
Expand Down