Esempio n. 1
0
 def test_add_bsl_expr(self):
     assert exp_parser(['+']) == FuncApplication(Variable('+'), [])
     assert exp_parser(['+', 1]) == FuncApplication(Variable('+'),[Num(1)])
     assert exp_parser(['+', 1, 1]) == \
            FuncApplication(Variable('+'), [Num(1), Num(1)])
     assert exp_parser(['+', 1, '+', 1]) == \
            FuncApplication(Variable('+'), [Num(1), Variable('+'), Num(1)])
Esempio n. 2
0
 def test_add_bsl_expr(self):
     assert exp_parser(['+']) == FuncApplication(Variable('+'), [])
     assert exp_parser(['+', 1]) == FuncApplication(Variable('+'),[Num(1)])
     assert exp_parser(['+', 1, 1]) == \
            FuncApplication(Variable('+'), [Num(1), Num(1)])
     assert exp_parser(['+', 1, '+', 1]) == \
            FuncApplication(Variable('+'), [Num(1), Variable('+'), Num(1)])
Esempio n. 3
0
    def test_if(self):
        assert exp_parser(['if', 1 , 'true', 'false']) == \
               If([Num(1), Boolean(True), Boolean(False)])

        assert exp_parser(['if', 'false', ['/', 1, 0], 9]) == \
               If([Boolean(False),
                   FuncApplication(Variable('/'), [Num(1), Num(0)]),
                   Num(9)])
Esempio n. 4
0
    def test_if(self):
        assert exp_parser(['if', 1 , 'true', 'false']) == \
               If([Num(1), Boolean(True), Boolean(False)])

        assert exp_parser(['if', 'false', ['/', 1, 0], 9]) == \
               If([Boolean(False),
                   FuncApplication(Variable('/'), [Num(1), Num(0)]),
                   Num(9)])
Esempio n. 5
0
 def test_divide_bsl_expr(self):
     assert exp_parser(['/', 1, 1]) == \
            (FuncApplication(Variable('/'), [Num(1), Num(1)]))
     assert exp_parser(['/', 1,['-', 1]]) ==\
            (FuncApplication
             (Variable('/'),
              [Num(1), FuncApplication(Variable('-'), [Num(1)])]))
     assert exp_parser(['/', 1]) == \
            (FuncApplication(Variable('/'), [Num(1)]))
Esempio n. 6
0
 def test_divide_bsl_expr(self):
     assert exp_parser(['/', 1, 1]) == \
            (FuncApplication(Variable('/'), [Num(1), Num(1)]))
     assert exp_parser(['/', 1,['-', 1]]) ==\
            (FuncApplication
             (Variable('/'),
              [Num(1), FuncApplication(Variable('-'), [Num(1)])]))
     assert exp_parser(['/', 1]) == \
            (FuncApplication(Variable('/'), [Num(1)]))
Esempio n. 7
0
    def test_function_application(self):

        assert exp_parser(['f', 1]) == \
               (FuncApplication(Variable('f'), [Num(1)]))

        assert exp_parser(['f', 1, 2]).__eq__\
            (FuncApplication(Variable('f'), [Num(1), Num(2)]))
        assert exp_parser(['x',1]).__eq__\
            (FuncApplication(Variable('x'),[Num(1)]))

        assert not exp_parser(['define',['x',1],1])
Esempio n. 8
0
    def test_function_application(self):

        assert exp_parser(['f', 1]) == \
               (FuncApplication(Variable('f'), [Num(1)]))

        assert exp_parser(['f', 1, 2]).__eq__\
            (FuncApplication(Variable('f'), [Num(1), Num(2)]))
        assert exp_parser(['x',1]).__eq__\
            (FuncApplication(Variable('x'),[Num(1)]))

        assert not exp_parser(['define',['x',1],1])
Esempio n. 9
0
    def test_composite_bsl_expr(self):
        assert exp_parser(['*', 1,['+', 1]]) == \
               (FuncApplication
                (Variable('*'),
                 [Num(1),
                  FuncApplication(Variable('+'), [Num(1)])]))

        assert exp_parser(['*', 1, ['-', 2, 2], ['/', 1]]) == \
               (FuncApplication
                (Variable('*'),
                 [Num(1),
                  FuncApplication(Variable('-'), [Num(2),Num(2)]),
                  FuncApplication(Variable('/'), [Num(1)])]))
Esempio n. 10
0
    def test_composite_bsl_expr(self):
        assert exp_parser(['*', 1,['+', 1]]) == \
               (FuncApplication
                (Variable('*'),
                 [Num(1),
                  FuncApplication(Variable('+'), [Num(1)])]))

        assert exp_parser(['*', 1, ['-', 2, 2], ['/', 1]]) == \
               (FuncApplication
                (Variable('*'),
                 [Num(1),
                  FuncApplication(Variable('-'), [Num(2),Num(2)]),
                  FuncApplication(Variable('/'), [Num(1)])]))
Esempio n. 11
0
    def test_parse(self):
        assert parse(['+', 1, [1, '+']]) == \
               FuncApplication\
                   (Variable('+'),
                    [Num(1), FuncApplication(Num(1), [Variable('+')])])

        assert parse(['+', 1, 2]) == \
               FuncApplication(Variable('+'), [Num(1), Num(2)])
        assert parse(['define-struct', 'posn', ['x', 'y']]) ==\
               (StructDef('posn', ['x', 'y']))
        with pytest.raises(ParserError):
            parse(exp_parser([]))
Esempio n. 12
0
    def test_parse(self):
        assert parse(['+', 1, [1, '+']]) == \
               FuncApplication\
                   (Variable('+'),
                    [Num(1), FuncApplication(Num(1), [Variable('+')])])

        assert parse(['+', 1, 2]) == \
               FuncApplication(Variable('+'), [Num(1), Num(2)])
        assert parse(['define-struct', 'posn', ['x', 'y']]) ==\
               (StructDef('posn', ['x', 'y']))
        with pytest.raises(ParserError):
            parse(exp_parser([]))
Esempio n. 13
0
    def test_expr_parser(self):
        assert exp_parser(['+', 'a', 'b']) ==\
               FuncApplication(Variable('+'), [Variable('a'), Variable('b')])
        assert exp_parser([1]) == FuncApplication(Num(1), [])
        assert exp_parser([1, '+', 1]) == \
               FuncApplication(Num(1), [Variable('+'), Num(1)])

        with pytest.raises(ParserError):
            exp_parser('define')

        with pytest.raises(ParserError):
            exp_parser(['-'])
Esempio n. 14
0
    def test_expr_parser(self):
        assert exp_parser(['+', 'a', 'b']) ==\
               FuncApplication(Variable('+'), [Variable('a'), Variable('b')])
        assert exp_parser([1]) == FuncApplication(Num(1), [])
        assert exp_parser([1, '+', 1]) == \
               FuncApplication(Num(1), [Variable('+'), Num(1)])

        with pytest.raises(ParserError):
            exp_parser('define')

        with pytest.raises(ParserError):
            exp_parser(['-'])
Esempio n. 15
0
    def test_equals(self):
        assert exp_parser(['=', 3, 3]) ==\
               FuncApplication(Variable('='), [Num(3), Num(3)])

        with pytest.raises(ParserError):
            exp_parser(['=', 3])
Esempio n. 16
0
 def test_mult_bsl_expr(self):
     assert exp_parser(['*', 1, 1]) == \
            (FuncApplication(Variable('*'), [Num(1), Num(1)]))
     assert exp_parser(['*']) == (FuncApplication(Variable('*'), []))
Esempio n. 17
0
    def test_bigger_less_than(self):
        assert exp_parser(['>', 3, 3]) == \
               FuncApplication(Variable('>'), [Num(3), Num(3)])

        with pytest.raises(ParserError):
            exp_parser(['>', 3])
Esempio n. 18
0
 def test_exponent(self):
     assert exp_parser(['^', 2, 3]) ==\
            FuncApplication(Variable('^'),[Num(2), Num(3)])
Esempio n. 19
0
 def test_exponent(self):
     assert exp_parser(['^', 2, 3]) ==\
            FuncApplication(Variable('^'),[Num(2), Num(3)])
Esempio n. 20
0
    def test_bigger_less_than(self):
        assert exp_parser(['>', 3, 3]) == \
               FuncApplication(Variable('>'), [Num(3), Num(3)])

        with pytest.raises(ParserError):
            exp_parser(['>', 3])
Esempio n. 21
0
    def test_equals(self):
        assert exp_parser(['=', 3, 3]) ==\
               FuncApplication(Variable('='), [Num(3), Num(3)])

        with pytest.raises(ParserError):
            exp_parser(['=', 3])
Esempio n. 22
0
 def test_and(self):
     assert exp_parser(['and', 'true', 'true']) == \
            And([Boolean(True), Boolean(True)])
Esempio n. 23
0
 def test_and(self):
     assert exp_parser(['and', 'true', 'true']) == \
            And([Boolean(True), Boolean(True)])
Esempio n. 24
0
 def test_mult_bsl_expr(self):
     assert exp_parser(['*', 1, 1]) == \
            (FuncApplication(Variable('*'), [Num(1), Num(1)]))
     assert exp_parser(['*']) == (FuncApplication(Variable('*'), []))