"test/vscode:/vscode.git/clone" did not exist on "fba8eccd7ebe41bbdbf70ab3b6a2df1835f8b532"
eval_test.cpp 1014 Bytes
Newer Older
Paul's avatar
Paul committed
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

#include <rtg/program.hpp>
#include <rtg/argument.hpp>
#include <rtg/shape.hpp>
#include "test.hpp"

int main() {

    rtg::program p;
    p.add_operator("sum", 
        [](std::vector<rtg::argument> args) {
            rtg::argument result;
            if(args.size() != 2) throw "Wrong args";
            if(args[0].s != args[1].s) throw "Wrong args";
            if(args[0].s.lens().size() != 1) throw "Wrong args";
            if(args[0].s.lens().front() != 1) throw "Wrong args";

            args[0].visit([&](auto x) {
                args[1].visit([&](auto y) {
                    result = rtg::literal{x + y}.get_argument();
                });
            });
            return result;
        },
        [](std::vector<rtg::shape> inputs) {
            if(inputs.size() != 2) throw "Wrong inputs";
            return inputs.front();
        }
    );

    auto one = p.add_literal(1);
    auto two = p.add_literal(2);
    p.add_instruction("sum", one, two);
    EXPECT(p.eval() == rtg::literal{3});
}