コード例 #1
0
ファイル: UnitTest.py プロジェクト: qianji/LEDOnline
 def test_tokens(self):
     L = ['1.2', '1.', '1..3', '1.2..2','.3(145..)','0.(3..)','3.96(721..)','.(4..)',\
             '"hi mom"','"Go tell the Spartans\\rThou who passest by"','"John said \\"hello\\""']
     expected = [ ['1.2'] , ['1.'], ['1','..', '3'], ['1.2', '..', '2'],['.3(145..)'],['0.(3..)'],['3.96(721..)'],['.(4..)'],\
             ['"hi mom"'],['"Go tell the Spartans\\rThou who passest by"'],['"John said \\"hello\\""']]
     for i in range(len(L)):
         actural = tokens(L[i])[0]
         self.assertEqual(expected[i],actural)   
コード例 #2
0
ファイル: UnitTest.py プロジェクト: qianji/LEDOnline
    def test_solutionSet(self):
        S = 'x in {1,2} U {3,4}'
        expected = [[('x', 1)], [('x', 2)], [('x', 3)], [('x', 4)]]
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected,actural) 
        
        S = 'x = 5 & y=10 & z = 20'
        expected = [[('x', 5), ('y', 10), ('z', 20)]]
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected,actural) 

        S = 'x in {2,3} & y in {10,20} & x*y < 40'
        expected = [[('x', 2), ('y', 10)], [('x', 3), ('y', 10)]]
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected,actural) 

        S = 'x in {1..10} & x < 1'
        expected = []
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected,actural) 
        
        S = '(x,y,z) = (10,20,30) & x=z'
        expected = []
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected,actural) 
        
        S = 'x=2 & x in {3,4}'
        expected = []
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected,actural) 
        
        S = 'x in {1,2} & x in {2,3}'
        expected = [[('x', 2)]]
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected,actural) 
        
        S = 'x=2 & x=3'
        expected = []
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected,actural) 
コード例 #3
0
    def test_solutionSet(self):
        S = 'x in {1,2} U {3,4}'
        expected = [[('x', 1)], [('x', 2)], [('x', 3)], [('x', 4)]]
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected, actural)

        S = 'x = 5 & y=10 & z = 20'
        expected = [[('x', 5), ('y', 10), ('z', 20)]]
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected, actural)

        S = 'x in {2,3} & y in {10,20} & x*y < 40'
        expected = [[('x', 2), ('y', 10)], [('x', 3), ('y', 10)]]
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected, actural)

        S = 'x in {1..10} & x < 1'
        expected = []
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected, actural)

        S = '(x,y,z) = (10,20,30) & x=z'
        expected = []
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected, actural)

        S = 'x=2 & x in {3,4}'
        expected = []
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected, actural)

        S = 'x in {1,2} & x in {2,3}'
        expected = [[('x', 2)]]
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected, actural)

        S = 'x=2 & x=3'
        expected = []
        t = tokens(S)[0]
        ast = parseExpression(t)[0]
        actural = solutionSet(ast.expression())
        self.assertEqual(expected, actural)
コード例 #4
0
 def test_tokens(self):
     L = ['1.2', '1.', '1..3', '1.2..2','.3(145..)','0.(3..)','3.96(721..)','.(4..)',\
             '"hi mom"','"Go tell the Spartans\\rThou who passest by"','"John said \\"hello\\""']
     expected = [ ['1.2'] , ['1.'], ['1','..', '3'], ['1.2', '..', '2'],['.3(145..)'],['0.(3..)'],['3.96(721..)'],['.(4..)'],\
             ['"hi mom"'],['"Go tell the Spartans\\rThou who passest by"'],['"John said \\"hello\\""']]
     for i in range(len(L)):
         actural = tokens(L[i])[0]
         self.assertEqual(expected[i], actural)
コード例 #5
0
ファイル: UnitTest.py プロジェクト: qianji/LEDOnline
 def expressionPrettyValues(self,L):
     #compile('test.led')
     values = []
     for e in L:
         e=tokens(e)[0]
         #v = val(parseExpression(e)[0])
         tree = parseExpression(e)[0]
         v = val(tree.expression())
         if isinstance(v,Fraction):
             v = numeralValue(v)
         #v=tree.val()
         values.append(prettyString(v))
     return values
コード例 #6
0
 def expressionPrettyValues(self, L):
     #compile('test.led')
     values = []
     for e in L:
         e = tokens(e)[0]
         #v = val(parseExpression(e)[0])
         tree = parseExpression(e)[0]
         v = val(tree.expression())
         if isinstance(v, Fraction):
             v = numeralValue(v)
         #v=tree.val()
         values.append(prettyString(v))
     return values
コード例 #7
0
ファイル: UnitTest.py プロジェクト: qianji/LEDOnline
 def functionValues(self,F,FunN,ParamsL):        
     #compile(F+'.led')
     values = []
     for Params in ParamsL:        
         # construct the params for the expression
         paramsStr = ''
         for i in range(len(Params)):
             if not i == len(Params)-1:
                 paramsStr += str(Params[i])+','
             else:
                 paramsStr += str(Params[i])
         # check for constant definition g = 12
         if paramsStr=='':
             e = FunN
         else:
             e = FunN + '(' + paramsStr + ')'
         expression,eFlag = tokens(e)
         if eFlag:
             tree, tFlag = parseExpression(expression)
             if tFlag:
                 values.append(prettyString(val(tree.expression())))
     return values      
コード例 #8
0
 def functionValues(self, F, FunN, ParamsL):
     #compile(F+'.led')
     values = []
     for Params in ParamsL:
         # construct the params for the expression
         paramsStr = ''
         for i in range(len(Params)):
             if not i == len(Params) - 1:
                 paramsStr += str(Params[i]) + ','
             else:
                 paramsStr += str(Params[i])
         # check for constant definition g = 12
         if paramsStr == '':
             e = FunN
         else:
             e = FunN + '(' + paramsStr + ')'
         expression, eFlag = tokens(e)
         if eFlag:
             tree, tFlag = parseExpression(expression)
             if tFlag:
                 values.append(prettyString(val(tree.expression())))
     return values