"vscode:/vscode.git/clone" did not exist on "a5147a5d5333e519ee0c04874c97a6c6e23877e1"
validate.cpp 1.36 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
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

void simple_test()
{
    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});
}

void out_of_order()
{
    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
32
33
34
35
36
37
38
39
40
41
void incomplete_args()
{
    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});
}

42
43
MIGRAPH_ROB(access_ins_arguments, std::vector<migraph::instruction_ref>, migraph::instruction, arguments)

Paul's avatar
Paul committed
44
45
46
47
48
49
50
void invalid_args()
{
    migraph::program p;

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

Paul's avatar
Paul committed
55
56
int main()
{
Paul's avatar
Paul committed
57
58
    simple_test();
    out_of_order();
Paul's avatar
Paul committed
59
60
    incomplete_args();
    invalid_args();
Paul's avatar
Paul committed
61
}