aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java
blob: 988d69a55d3037860d24df0991fd310095b889d0 (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
43
44
45
46
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.semantics.test;

import org.junit.Test;

/**
 * @author bratseth
 */
public class ComparisonTestCase extends RuleBaseAbstractTestCase {

    public ComparisonTestCase() {
        super("comparison.sr");
    }

    /**
     * Tests that we can wriote rules which depends on the <i>same term</i> (java) being matched by two
     * different conditions (coffee, island)
     */
    @Test
    public void testNamedConditionReturnComparison() {
        // Not sufficient that both conditions are matched
        assertSemantics("AND borneo arabica island:borneo coffee:arabica","borneo arabica");

        // They must match the same word
        assertSemantics("AND java noise island:java coffee:java control:ambigous off","java noise");

        // Works also when there are other, not-equal matches
        assertSemantics("AND borneo arabica java island:borneo island:java coffee:arabica coffee:java control:ambigous off",
                        "borneo arabica java");
    }

    @Test
    public void testContainsAsSubstring() {
        assertSemantics("AND java island:java coffee:java control:ambigous off","java");
        assertSemantics("AND kanava island:kanava off","kanava");
        assertSemantics("AND borneo island:borneo","borneo");
    }

    @Test
    public void testAlphanumericComparison() {
        assertSemantics("a","a");
        assertSemantics("AND z highletter","z");
        assertSemantics("AND p highletter","p");
    }

}