aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java
blob: 1a39f3cc7aca0c9400b2e078100076aca633f385 (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 Vespa.ai. 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.jupiter.api.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
    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
    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
    void testAlphanumericComparison() {
        assertSemantics("a", "a");
        assertSemantics("AND z highletter", "z");
        assertSemantics("AND p highletter", "p");
    }

}