summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/search/dispatch/LeanHitTest.java
blob: 3478038e42795e4a8b7f7155a1b9824f3744f0c3 (plain) (blame)
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
package com.yahoo.search.dispatch;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class LeanHitTest {
    byte [] gidA = {'a'};
    byte [] gidB = {'b'};
    byte [] gidC = {'c'};
    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));
    }
}