1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.dispatch;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class LeanHitTest {
private static final byte [] gidA = {'a'};
private static final byte [] gidB = {'b'};
private static final byte [] gidC = {'c'};
private final double DELTA = 0.00000000000000;
private void verifyTransitiveOrdering(LeanHit a, LeanHit b, LeanHit c) {
assertTrue(a.compareTo(b) < 0);
assertTrue(b.compareTo(c) < 0);
assertTrue(a.compareTo(c) < 0);
assertTrue(b.compareTo(a) > 0);
assertTrue(c.compareTo(b) > 0);
assertTrue(c.compareTo(a) > 0);
}
@Test
public void testOrderingByRelevance() {
assertEquals(0, new LeanHit(gidA, 0, 0, 1).compareTo(new LeanHit(gidA, 0, 0, 1)));
verifyTransitiveOrdering(new LeanHit(gidA, 0, 0, 1),
new LeanHit(gidA, 0, 0, 0),
new LeanHit(gidA, 0, 0, -1));
}
@Test
public void testOrderingByGid() {
assertEquals(0, new LeanHit(gidA, 0, 0, 1).compareTo(new LeanHit(gidA, 0, 0, 1)));
verifyTransitiveOrdering(new LeanHit(gidA, 0, 0, 1),
new LeanHit(gidB, 0, 0, 1),
new LeanHit(gidC, 0, 0, 1));
}
@Test
public void testOrderingBySortData() {
assertEquals(0, new LeanHit(gidA, 0, 0, gidA).compareTo(new LeanHit(gidA, 0, 0, gidA)));
verifyTransitiveOrdering(new LeanHit(gidA, 0, 0, gidA),
new LeanHit(gidA, 0, 0, gidB),
new LeanHit(gidA, 0, 0, gidC));
}
@Test
public void testNaN2negativeInfinity() {
LeanHit nan = new LeanHit(gidA, 0, 0, Double.NaN);
assertFalse(Double.isNaN(nan.getRelevance()));
assertTrue(Double.isInfinite(nan.getRelevance()));
assertEquals(Double.NEGATIVE_INFINITY, nan.getRelevance(), DELTA);
}
}
|