def test_mod(): result = match(scan('100%3')) assert result == 1
def test_single_mix(): result = match(scan('1+1000*10+200/2-100%4')) assert result == 10101
def test_mult(): result = match(scan('2*100')) assert result == 200
def test_div(): result = match(scan('100/50')) assert result == 2
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')
def test_minus(): result = match(scan('1-100')) assert result == -99
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')
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')
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')
def test_mangled(self): with self.assertRaises(calculator.CalcError): scan("5 + [[")
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')
def test_functions(self): t = scan("log(10)") s = [('F', 'log'), ('O', '('), ('N', '10'), ('O', ')'), ('Z', '')] self.assertEqual(t, s, 'problem scanning functions')
def test_symbols(self): t = scan("a + b") s = [('I', 'a'), ('O', '+'), ('I', 'b'), ('O', ''), ('Z', '')] self.assertEqual(t, s, 'problem scanning symbols')
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
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')
def test_plus(): result = match(scan('1+1')) assert result == 2
def test_numbers(self): t = scan("5 + 7") s = [('N', '5'), ('O', '+'), ('N', '7'), ('O', ''), ('Z', '')] self.assertEqual(t, s, 'problem scanning pure numbers')