def test_init_WatchListDict(self): correct = {'5': {}, '10': {}, '20': {}, '50': {}, '100': {}} wl = WatchListDict() self.assertEqual(correct, wl.root) wl = WatchListDict('bill_file_0.txt') self.assertEqual(correct, wl.root) correct = {'5': {'a': {'b': {'c': {None: None, 'd': {None: None, 'e': {None: None}}, 'e': {None: None}}, 'e': {'f': {None: None}}}}}, '10': {}, '20': {}, '50': {}, '100': {}} wl = WatchListDict('bill_file_5.txt') self.assertEqual(correct, wl.root) self.assertTrue(wl.validator.match('CF35365625U')) self.assertEqual(['__weakref__', 'insert', 'root', 'search', 'validator'], dir(wl)[-5:]) correct = {'5': {}, '10': {}, '20': {}, '50': {}, '100': {'C': {'F': {'3': {'5': {'3': {'6': {'5': {'6': {'2': {'5': {'U': {None: None}}}}}}}}}}}}} wl = WatchListDict('bill_file_1.txt') self.assertEqual(correct, wl.root) correct = pickle.load(open('bill_file_77_wld.pkl', 'rb')) wl = WatchListDict('bill_file_77.txt') self.assertEqual(correct.root, wl.root)
def test_insert_WatchListDict(self): wl = WatchListDict() wl.insert('abc', '5') wl.insert('abcd', '5') wl.insert('abef', '5') wl.insert('abcde', '5') wl.insert('abce', '5') correct = {'5': {'a': {'b': {'c': {None: None, 'd': {None: None, 'e': {None: None}}, 'e': {None: None}}, 'e': {'f': {None: None}}}}}, '10': {}, '20': {}, '50': {}, '100': {}} self.assertEqual(correct, wl.root)
def test_check_bills(self): wl = WatchListLinked('bill_file_77.txt') correct = ['JB67705552I 5', 'GJ03569965R 50', 'AL18844331R 20', 'HE44178509U 10', 'LB21339931W 20', 'AG35934714H 100', 'AAG35924714H 100'] self.assertEqual(correct, check_bills(wl, 'recovered_bills.txt')) wl = WatchListDict('bill_file_77.txt') self.assertEqual(correct, check_bills(wl, 'recovered_bills.txt'))
def test_search_WatchListDict(self): wl = WatchListDict('bill_file_77.txt') self.assertTrue(wl.search('JB67705552I', '5')) self.assertTrue(wl.search('GJ03569965R', '50')) self.assertTrue(wl.search('AL18844331R', '20')) self.assertTrue(wl.search('HE44178509U', '10')) self.assertTrue(wl.search('LB21339931W', '20')) self.assertTrue(wl.search('AG35934714H', '100')) self.assertFalse(wl.search('JB67705552I', '50')) self.assertFalse(wl.search('JB67705552', '5')) self.assertFalse(wl.search('JB6770555', '5')) self.assertFalse(wl.search('AG35934714H', '10')) self.assertFalse(wl.search('AL18944331R', '20')) self.assertFalse(wl.search('JB67805552I', '5')) self.assertFalse(wl.search('AG35924714H', '100')) wl = WatchListDict() self.assertFalse(wl.search('JB67705552I', '5')) wl = WatchListDict('bill_file_1.txt') self.assertFalse(wl.search('JB67705552I', '5')) self.assertFalse(wl.search('JB67705552I', '100')) self.assertTrue(wl.search('CF35365625U', '100')) wl = WatchListDict('bill_file_5.txt') self.assertFalse(wl.search('a', '5')) self.assertFalse(wl.search('ab', '5')) self.assertFalse(wl.search('abe', '5')) self.assertFalse(wl.search('abf', '5')) self.assertTrue(wl.search('abc', '5')) self.assertTrue(wl.search('abcd', '5')) self.assertTrue(wl.search('abef', '5')) self.assertTrue(wl.search('abcde', '5')) self.assertTrue(wl.search('abce', '5'))