validate.cpp 1.38 KB
Newer Older
Paul's avatar
Paul committed
1
#include <migraph/program.hpp>
Paul's avatar
Paul committed
2
#include <migraph/instruction.hpp>
Paul's avatar
Paul committed
3
4
#include <basic_ops.hpp>
#include <test.hpp>
5
#include <rob.hpp>
Paul's avatar
Paul committed
6

Paul's avatar
Paul committed
7
TEST_CASE(simple_test)
Paul's avatar
Paul committed
8
9
10
11
12
13
14
15
16
17
18
19
{
    migraph::program p;

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    p.add_instruction(sum_op{}, one, two);
    EXPECT(bool{p.validate() == p.end()});
    auto result = p.eval({});
    EXPECT(result == migraph::literal{3});
    EXPECT(result != migraph::literal{4});
}

Paul's avatar
Paul committed
20
TEST_CASE(out_of_order)
Paul's avatar
Paul committed
21
22
23
24
25
26
27
28
29
30
{
    migraph::program p;

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    auto ins = p.add_instruction(sum_op{}, one, two);
    p.move_instruction(two, p.end());
    EXPECT(bool{p.validate() == ins});
}

Paul's avatar
Paul committed
31
TEST_CASE(incomplete_args)
Paul's avatar
Paul committed
32
33
34
35
36
37
38
39
40
41
{
    migraph::program p;

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    auto ins = p.add_instruction(sum_op{}, one, two);
    ins->clear_arguments();
    EXPECT(bool{p.validate() == ins});
}

Paul's avatar
Paul committed
42
43
44
45
MIGRAPH_ROB(access_ins_arguments,
            std::vector<migraph::instruction_ref>,
            migraph::instruction,
            arguments)
46

Paul's avatar
Paul committed
47
TEST_CASE(invalid_args)
Paul's avatar
Paul committed
48
49
50
51
52
53
{
    migraph::program p;

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    auto ins = p.add_instruction(sum_op{}, one, two);
54
    access_ins_arguments(*ins).clear();
Paul's avatar
Paul committed
55
56
57
    EXPECT(bool{p.validate() == p.begin()});
}

Paul's avatar
Paul committed
58
int main(int argc, const char* argv[]) { test::run(argc, argv); }