aboutsummaryrefslogtreecommitdiffstats
path: root/predicate-search-core/src/test/java/com/yahoo/document/predicate/PredicatesTest.java
blob: 22832eedeff962575dbb8c63715699dd32fad416 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.predicate;

import org.junit.Test;

import static com.yahoo.document.predicate.Predicates.and;
import static com.yahoo.document.predicate.Predicates.feature;
import static com.yahoo.document.predicate.Predicates.not;
import static com.yahoo.document.predicate.Predicates.or;
import static com.yahoo.document.predicate.Predicates.value;
import static org.junit.Assert.assertEquals;

/**
 * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
 */
public class PredicatesTest {

    @Test
    public void requireThatApiIsUsable() {
        assertEquals(
                new Disjunction(
                        new Conjunction(new FeatureSet("country", "de", "no"),
                                        new Negation(new FeatureSet("gender", "female")),
                                        new FeatureRange("age", 6L, 9L)),
                        new Conjunction(new Negation(new FeatureSet("country", "se")),
                                        new FeatureSet("gender", "female"),
                                        new FeatureRange("age", 69L, null))),
                or(and(feature("country").inSet("de", "no"),
                       feature("gender").notInSet("female"),
                       feature("age").inRange(6, 9)),
                   and(not(feature("country").inSet("se")),
                       feature("gender").inSet("female"),
                       feature("age").greaterThanOrEqualTo(69))));

        assertEquals(new BooleanPredicate(true), value(true));
        assertEquals(new BooleanPredicate(false), value(false));
    }
}