aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/test/java/com/yahoo/searchlib/gbdt/ResponseNodeTestCase.java
blob: 7529777c0206fe563adf5277f87c6f31e1aa6675 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.gbdt;

import org.junit.Test;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;

import static org.junit.Assert.assertEquals;

/**
 * @author Simon Thoresen Hult
 */
public class ResponseNodeTestCase {

    @Test
    public void requireThatAccessorsWork() {
        ResponseNode node = new ResponseNode(6.9, null);
        assertEquals(6.9, node.value(), 1E-6);
    }

    @Test
    public void requireThatRankingExpressionCanBeGenerated() {
        assertExpression("0.0", new ResponseNode(0, null));
        assertExpression("1.0", new ResponseNode(1, null));
    }

    @Test
    public void requireThatNodeCanBeGeneratedFromDomNode() throws ParserConfigurationException, IOException, SAXException {
        String xml = "<Response value='1' />\n";
        ResponseNode node = ResponseNode.fromDom(XmlHelper.parseXml(xml));
        assertEquals(1, node.value(), 1E-6);
    }

    private static void assertExpression(String expected, TreeNode node) {
        assertEquals(expected, node.toRankingExpression());
    }

}