def testReduceLetterMult(self): x = prefixReduce("a * b") self.assertEqual(x, ("*", "a", "b")) x = prefixReduce("a * 1") self.assertEqual(x, ("*", "a", 1)) x = prefixReduce("1 * a") self.assertEqual(x, ("*", 1, "a"))
def testReduceLetterDivide(self): x = prefixReduce("a / b") self.assertEqual(x, ("/", "a", "b")) x = prefixReduce("a / 1") self.assertEqual(x, ("/", "a", 1)) x = prefixReduce("1 / a") self.assertEqual(x, ("/", 1, "a"))
def testReduceLetterAdd(self): x = prefixReduce("a + b") self.assertEqual(x, ("+", "a", "b")) x = prefixReduce("a + 1") self.assertEqual(x, ("+", "a", 1)) x = prefixReduce("1 + a") self.assertEqual(x, ("+", 1, "a"))
def testReduceLetterSubtract(self): x = prefixReduce("a - b") self.assertEqual(x, ("-", "a", "b")) x = prefixReduce("a - 1") self.assertEqual(x, ("-", "a", 1)) x = prefixReduce("1 - a") self.assertEqual(x, ("-", 1, "a"))
def testReduceNumber(self): x = prefixReduce("1") self.assertEqual(x, 1) x = prefixReduce("10") self.assertEqual(x, 10) x = prefixReduce("999") self.assertEqual(x, 999)
def testReduceMixed(self): x = prefixReduce("a + ( 1 + 2 )") self.assertEqual(x, ("+", "a", 3)) x = prefixReduce("( 1 + 2 ) + a") self.assertEqual(x, ("+", 3, "a")) x = prefixReduce("a + ( 2 * 3 )") self.assertEqual(x, ("+", "a", 6)) x = prefixReduce("( 2 * 3 ) + a") self.assertEqual(x, ("+", 6, "a"))
def testReduceParen(self): x = prefixReduce("(3 * 2)") self.assertEqual(x, 6) x = prefixReduce("(3 + 2)") self.assertEqual(x, 5) x = prefixReduce("5 * (3 + 2)") self.assertEqual(x, 25) x = prefixReduce("(3 + 2) * 5") self.assertEqual(x, 25)
def testReduceLetter(self): x = prefixReduce("a") self.assertEqual(x, "a") x = prefixReduce("z") self.assertEqual(x, "z")
def testReduceMult(self): x = prefixReduce("3 * 2") self.assertEqual(x, 6) x = prefixReduce("3 * 2 * 4") self.assertEqual(x, 24)
def testReduceAdd(self): x = prefixReduce("1 + 2") self.assertEqual(x, 3) x = prefixReduce("1 + 2 + 3") self.assertEqual(x, 6)