예제 #1
0
def test_mod():
    result = match(scan('100%3'))
    assert result == 1
예제 #2
0
def test_single_mix():
    result = match(scan('1+1000*10+200/2-100%4'))
    assert result == 10101
예제 #3
0
def test_mult():
    result = match(scan('2*100'))
    assert result == 200
예제 #4
0
def test_div():
    result = match(scan('100/50'))
    assert result == 2
예제 #5
0
 def test_comments(self):
     t = make_paired_tokens(scan("5 + 6 # + 56"))
     s = [['N', '*', '5'], ['N', '+', '6'], ['Z', '*', '']]
     self.assertEqual(t, s, 'problem with comments')
예제 #6
0
def test_minus():
    result = match(scan('1-100'))
    assert result == -99
예제 #7
0
 def test_implied_multiplication(self):
     t = make_paired_tokens(scan("5 7"))
     s = [['N', '*', '5'], ['N', '*', '7'], ['Z', '*', '']]
     self.assertEqual(t, s, 'problem with implied multiplication')
예제 #8
0
 def test_quantities(self):
     t = scan("5. km / 3. s")
     s = [('N', '5.'), ('O', ''), ('U', 'km'), ('O', '/'), ('N', '3.'), ('O', ''), ('U', 's'), ('O', ''), ('Z', '')]
     self.assertEqual(t, s, 'problem scanning quantities')
예제 #9
0
 def test_combo(self):
     t = scan("sqrt(5.0 cm^2 / (2 Pi))")
     s = [('F', 'sqrt'), ('O', '('), ('N', '5.0'), ('O', ''), ('U', 'cm'), ('O', '^'),
          ('N', '2'), ('O', '/ ('), ('N', '2'), ('O', ''), ('I', 'Pi'), ('O', '))'), ('Z', '')]
     self.assertEqual(t, s, 'problem scanning combos')
예제 #10
0
 def test_mangled(self):
     with self.assertRaises(calculator.CalcError):
         scan("5 + [[")
예제 #11
0
 def test_comment(self):
     t = scan("42 # the meaning of life")
     s = [('N', '42'), ('O', ''), ('C', '# the meaning of life'), ('Z', '')]
     self.assertEqual(t, s, 'problem scanning comments')
예제 #12
0
 def test_functions(self):
     t = scan("log(10)")
     s = [('F', 'log'), ('O', '('), ('N', '10'), ('O', ')'), ('Z', '')]
     self.assertEqual(t, s, 'problem scanning functions')
예제 #13
0
 def test_symbols(self):
     t = scan("a + b")
     s = [('I', 'a'), ('O', '+'), ('I', 'b'), ('O', ''), ('Z', '')]
     self.assertEqual(t, s, 'problem scanning symbols')
예제 #14
0
def test_double_mix():
    result = match(scan('1+1000*10*1*1+200/2+200/2+1+1-100%4-100%4'))
    assert result == 10203
예제 #15
0
 def test_functions(self):
     t = make_paired_tokens(scan("log(7)"))
     s = [['N', '*', '5'], ['N', '*', '7'], ['Z', '*', '']]
     self.assertEqual(t, s, 'problem with function calls')
예제 #16
0
def test_plus():
    result = match(scan('1+1'))
    assert result == 2
예제 #17
0
 def test_numbers(self):
     t = scan("5 + 7")
     s = [('N', '5'), ('O', '+'), ('N', '7'), ('O', ''), ('Z', '')]
     self.assertEqual(t, s, 'problem scanning pure numbers')