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));
    }
}

@@ -98,16 +98,60 @@
 Equals;%0A
+import static org.junit.Assert.assertFalse;%0A
 import s
@@ -213,24 +213,45 @@
 tTest %7B%0A    
+private static final 
 byte %5B%5D gidA
@@ -256,32 +256,53 @@
 dA = %7B'a'%7D;%0A    
+private static final 
 byte %5B%5D gidB = %7B
@@ -315,28 +315,100 @@
     
-byte %5B%5D gidC = %7B'c'%7D
+private static final byte %5B%5D gidC = %7B'c'%7D;%0A    private final double DELTA = 0.00000000000000
 ;%0A  
@@ -1641,10 +1641,319 @@
 ;%0A    %7D%0A
+    @Test%0A    public void testNaN2negativeInfinity() %7B%0A        LeanHit nan = new LeanHit(gidA, 0, 0, Double.NaN);%0A        assertFalse(Double.isNaN(nan.getRelevance()));%0A        assertTrue(Double.isInfinite(nan.getRelevance()));%0A        assertEquals(Double.NEGATIVE_INFINITY, nan.getRelevance(), DELTA);%0A    %7D%0A
 %7D%0A

Test that Nan -> negative infinity conversion takes place in LeanHit.