Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 64 lines (39 sloc) 1.753 kb
fcafeda @thatmattbone binary search and expression tree examples are pretty much set. tests to...
authored
1 """
2 Exercise some the examples to make sure they're doing what we expect.
3 """
90c11f7 @thatmattbone some expression examples and more slides
authored
4 import unittest
fcafeda @thatmattbone binary search and expression tree examples are pretty much set. tests to...
authored
5 from zope.interface.exceptions import BrokenImplementation, Invalid
6
7 from expression import *
8 from binary_search import *
9
10 class ExpressionTest(unittest.TestCase):
11
12 def test_integer_node(self):
13 life_universe = IntegerExpressionNode(42)
14 self.assertEqual(42, life_universe.evaluate())
15
16
17 def test_broken_integer_node(self):
18 """
19 Make sure the BrokenIntegerExpressionNode behaves
20 correctly even though it's not providing the interface that it
21 claims to provide.
22 """
23 life_universe = BrokenIntegerExpressionNode(42)
24 self.assertEqual(42, life_universe.evaluate())
25
26
27 def test_addition_node(self):
28 twenty_one = AdditionExpressionNode(IntegerExpressionNode(10), IntegerExpressionNode(11))
29 self.assertEqual(21, twenty_one.evaluate())
30
31
32 def test_validate_addition_node(self):
33 self.assertIsNone(validate_addition_node())
34
35
36 def test_validate_integer_node(self):
37 self.assertIsNone(validate_integer_node())
38
39
40 def test_validate_broken_integer_node(self):
41 self.assertRaises(BrokenImplementation, validate_broken_integer_node)
42
43
44 class AscendingListTest(unittest.TestCase):
45
46 def test_verify_ascending_list(self):
47 self.assertIsNone(verify_ascending_list())
48
49
50 def test_verify_nonascending_list(self):
51 self.assertIsNone(verify_nonascending_list())
52
53
54 def test_validate_ascending_list(self):
55 self.assertIsNone(validate_ascending_list())
56
57
58 def test_validate_nonascending_list(self):
59 self.assertRaises(Invalid, validate_nonascending_list)
60
90c11f7 @thatmattbone some expression examples and more slides
authored
61
62 if __name__ == "__main__":
63 unittest.main()
Something went wrong with that request. Please try again.