Пример #1
0
 def test_diff_num_commands(self):
     self.assertFalse(
         ast_equal(
             ast.Program(
                 ast.Body([
                     ast.commands_ast.Loader(
                         ast.Var("source"),
                         ast.Source("www.coviddata.com/stream")),
                 ])), ast.Program(ast.Body([]))))
Пример #2
0
 def test_identical_commands(self):
     self.assertTrue(
         ast_equal(
             ast.Program(
                 ast.Body([
                     ast.commands_ast.Loader(
                         ast.Var("source"),
                         ast.Source("www.coviddata.com/stream")),
                 ])),
             ast.Program(
                 ast.Body([
                     ast.commands_ast.Loader(
                         ast.Var("source"),
                         ast.Source("www.coviddata.com/stream")),
                 ]))))
Пример #3
0
 def test_diff_math_funcs_(self):
     self.assertFalse(
         ast_equal(
             ast.Program(
                 ast.Body([
                     ast.Trigger(
                         ast.Var("source"),
                         ast.MathFuncs([ast.Increment(ast.Var("count"))]))
                 ])),
             ast.Program(
                 ast.Body([
                     ast.Trigger(
                         ast.Var("source"),
                         ast.MathFuncs([ast.Decrement(ast.Var("count"))]))
                 ]))))
Пример #4
0
 def test_different_load_var_names(self):
     self.assertFalse(
         ast_equal(
             ast.Program(
                 ast.Body([
                     ast.commands_ast.Loader(
                         ast.Var("source"),
                         ast.Source("www.coviddata.com/stream")),
                 ])),
             ast.Program(
                 ast.Body([
                     ast.commands_ast.Loader(
                         ast.Var("source1"),
                         ast.Source("www.coviddata.com/stream")),
                 ]))))
Пример #5
0
 def test_diff_commands(self):
     self.assertFalse(
         ast_equal(
             ast.Program(
                 ast.Body([
                     ast.commands_ast.Loader(
                         ast.Var("source"),
                         ast.Source("www.coviddata.com/stream")),
                 ])),
             ast.Program(
                 ast.Body([
                     ast.Mapper(
                         ast.Var("source"), "case_date",
                         ast.Declare(ast.Type(Types.NUMBER),
                                     ast.Var("date")))
                 ]))))
Пример #6
0
 def test_diff_map_declare_var(self):
     self.assertFalse(
         ast_equal(
             ast.Program(
                 ast.Body([
                     ast.Mapper(
                         ast.Var("source"), "case_date",
                         ast.Declare(ast.Type(Types.NUMBER),
                                     ast.Var("date")))
                 ])),
             ast.Program(
                 ast.Body([
                     ast.Mapper(
                         ast.Var("source"), "case_date",
                         ast.Declare(ast.Type(Types.NUMBER),
                                     ast.Var("count")))
                 ]))))
Пример #7
0
    def test_regular(self):
        p_expected: ast.Program = ast.Program(
            ast.Body([

                # source = live remote "https://covid-api.com/api/reports"
                ast.Loader(ast.Var("source"),
                           ast.Source("https://covid-api.com/api/reports")),

                # map source "confirmed" to number confirmed
                ast.Mapper(
                    ast.Var("source"), "confirmed",
                    ast.Declare(ast.Type(Types.NUMBER), ast.Var("confirmed"))),

                # number count = 0
                ast.Assigner(
                    ast.Declare(ast.Type(Types.NUMBER), ast.Var("count")),
                    ast.Value(values.IntegerValue(0))),

                # observe(source) do count++
                ast.Trigger(ast.Var("source"),
                            ast.MathFuncs([ast.Increment(ast.Var("count"))])),

                # plot line_xy(count,confirmed) called "confirmed_cases"
                ast.Plotter(ast.Graph(graphs.LineXYGraph()),
                            ast.VarAxis(ast.Var("count")),
                            ast.VarAxis(ast.Var("confirmed")),
                            "confirmed_cases"),
            ]))

        def parse(content) -> ast.Program:
            t = Tokenizer(content)
            t.tokenize()
            return Parser(t).parseProgram()

        p: ast.Program = read_program_file(
            "tests/res/programs/regular_program.mstx", parse)

        self.assertTrue(ast_equal(p_expected, p))
Пример #8
0
 def test_identical_construction(self):
     self.assertTrue(ast_equal(example_1(), example_1()))
Пример #9
0
 def test_trivial(self):
     self.assertTrue(
         ast_equal(ast.Program(ast.Body([])), ast.Program(ast.Body([]))))