Skip to content

Commit e01acfa

Browse files
authored
Merge pull request #700 from makarandhinge/WAYANG-594-fix-nondeterministic-sort-in-tensorflow-iris-test
[WAYANG-594] Fix non deterministic test in TensorflowIrisScalaLikeApiIT
2 parents 54f2de7 + 247a5fa commit e01acfa

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

wayang-tests-integration/src/test/java/org/apache/wayang/tests/TensorflowIrisScalaLikeApiIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,13 @@ void test() {
160160
DataQuantaBuilder<?, String> textFileSource = plan.readTextFile(uri.toString());
161161

162162
if (random) {
163+
// Assign random keys for shuffling, then sort by those keys
164+
// This avoids comparator contract violations from r.nextInt()
163165
Random r = new Random();
164-
textFileSource = textFileSource.sort(e -> r.nextInt());
166+
textFileSource = textFileSource
167+
.map(line -> new Tuple<>(r.nextDouble(), line))
168+
.sort(tuple -> tuple.field0)
169+
.map(tuple -> tuple.field1);
165170
}
166171

167172
MapDataQuantaBuilder<String, Tuple<float[], Integer>> mapXY = textFileSource.map(line -> {

0 commit comments

Comments
 (0)