From c9142a1d6b4ee3f477ba5a9c8414e870af57dc07 Mon Sep 17 00:00:00 2001 From: Veronika Maurerova Date: Thu, 21 Nov 2024 09:26:21 +0100 Subject: [PATCH] Fix TopNTreeMap test --- h2o-algos/src/main/java/hex/knn/KNNKey.java | 6 ------ h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/h2o-algos/src/main/java/hex/knn/KNNKey.java b/h2o-algos/src/main/java/hex/knn/KNNKey.java index a2692ea97366..4b15dd0ebb96 100644 --- a/h2o-algos/src/main/java/hex/knn/KNNKey.java +++ b/h2o-algos/src/main/java/hex/knn/KNNKey.java @@ -32,12 +32,6 @@ public int hashCode() { } @Override - /** - * The compare method does not ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all cases: - * in case the this.value and o.value are the same but the keys are not same -> order of asking matters. - * In this special case x.compareTo(y) == y.compareTo(x). - * We need this functionality for ordering in TopNTreeMap, where order of asking is important to decide top N neighbours. - */ public int compareTo(KNNKey o) { if (o == null) return 1; int sameValue = this.value.compareTo(o.value); diff --git a/h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java b/h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java index 4096058252a7..74770c115b92 100644 --- a/h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java +++ b/h2o-algos/src/test/java/hex/knn/TopNTreeMapTest.java @@ -64,8 +64,8 @@ public void testKNNKeyCompareTo(){ // same key same value -> both object are the same Assert.assertEquals(k2.compareTo(k3), 0); - // different key same value -> the first is less - Assert.assertEquals(k2.compareTo(k1), -1); + // different key same value -> depends on key comparator + Assert.assertEquals(k2.compareTo(k1), 1); // same key different value -> the item with less value is less Assert.assertEquals(k3.compareTo(k4), -1);