aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/tests/eval/cell_type_space/cell_type_space_test.cpp
blob: 8d99ea38c5dd3b63dbe17b424bb3c39ef14b0442 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/eval/eval/test/cell_type_space.h>
#include <vespa/vespalib/gtest/gtest.h>

using namespace vespalib::eval;
using namespace vespalib::eval::test;

//-----------------------------------------------------------------------------

auto all_types = CellTypeUtils::list_types();

//-----------------------------------------------------------------------------

TEST(CellTypeSpaceTest, n_1) {
    auto space = CellTypeSpace(all_types, 1);
    for (auto t0: all_types) {
        ASSERT_TRUE(space.valid());
        auto ts = space.get();
        ASSERT_EQ(ts.size(), 1);
        EXPECT_EQ(t0, ts[0]);
        space.next();
    }
    EXPECT_FALSE(space.valid());
}

TEST(CellTypeSpaceTest, n_2) {
    auto space = CellTypeSpace(all_types, 2);
    for (auto t0: all_types) {
        for (auto t1: all_types) {
            ASSERT_TRUE(space.valid());
            auto ts = space.get();
            ASSERT_EQ(ts.size(), 2);
            EXPECT_EQ(t0, ts[0]);
            EXPECT_EQ(t1, ts[1]);
            space.next();
        }
    }
    EXPECT_FALSE(space.valid());
}

TEST(CellTypeSpaceTest, n_2_same) {
    auto space = CellTypeSpace(all_types, 2).same();
    for (auto t0: all_types) {
        for (auto t1: all_types) {
            if (t0 != t1) continue;
            ASSERT_TRUE(space.valid());
            auto ts = space.get();
            ASSERT_EQ(ts.size(), 2);
            EXPECT_EQ(t0, ts[0]);
            EXPECT_EQ(t1, ts[1]);
            space.next();
        }
    }
    EXPECT_FALSE(space.valid());
}

TEST(CellTypeSpaceTest, n_2_different) {
    auto space = CellTypeSpace(all_types, 2).different();
    for (auto t0: all_types) {
        for (auto t1: all_types) {
            if (t0 == t1) continue;
            ASSERT_TRUE(space.valid());
            auto ts = space.get();
            ASSERT_EQ(ts.size(), 2);
            EXPECT_EQ(t0, ts[0]);
            EXPECT_EQ(t1, ts[1]);
            space.next();
        }
    }
    EXPECT_FALSE(space.valid());
}

//-----------------------------------------------------------------------------

GTEST_MAIN_RUN_ALL_TESTS()