示例#1
0
    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"))
示例#2
0
    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"))
示例#3
0
    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"))
示例#4
0
    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"))
示例#5
0
    def testReduceNumber(self):
        x = prefixReduce("1")
        self.assertEqual(x, 1)

        x = prefixReduce("10")
        self.assertEqual(x, 10)

        x = prefixReduce("999")
        self.assertEqual(x, 999)
示例#6
0
    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"))
示例#7
0
    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)
示例#8
0
    def testReduceLetter(self):
        x = prefixReduce("a")
        self.assertEqual(x, "a")

        x = prefixReduce("z")
        self.assertEqual(x, "z")
示例#9
0
    def testReduceMult(self):
        x = prefixReduce("3 * 2")
        self.assertEqual(x, 6)

        x = prefixReduce("3 * 2 * 4")
        self.assertEqual(x, 24)
示例#10
0
    def testReduceAdd(self):
        x = prefixReduce("1 + 2")
        self.assertEqual(x, 3)

        x = prefixReduce("1 + 2 + 3")
        self.assertEqual(x, 6)