def test_index(self): mylist = UnorderedList() mylist.append(1) mylist.append(2) self.assertEqual(mylist.index(1), 1) self.assertEqual(mylist.index(2), 2)
def test_insert(self): mylist = UnorderedList() mylist.insert(1, 0) mylist.insert(3, 1) mylist.insert(2, 1) self.assertEqual(mylist.index(1), 1) self.assertEqual(mylist.index(2), 2) self.assertEqual(mylist.index(3), 3)
def setUp(self): self.mylist = UnorderedList() self.mylist.add(12) self.mylist.add(22) self.mylist.add(9) self.mylist.add(89) self.mylist.add(71) self.mylist.add(16)
def test_pop(self): mylist = UnorderedList() mylist.append(1) mylist.append(2) self.assertEqual(mylist.pop(), 2) self.assertEqual(mylist.pop(), 1) self.assertEqual(mylist.pop(), None)
def test_append(self): mylist = UnorderedList() mylist.append(1) self.assertEqual(mylist.head.getData(), 1) self.assertEqual(mylist.tail.getData(), 1) mylist.append(2) self.assertEqual(mylist.head.getData(), 1) self.assertEqual(mylist.tail.getData(), 2)
def test_append(self): l = UnorderedList() l.append(34) l.append('test') self.assertEqual(l.length(), 2) self.assertEqual(l.toList(), [34, 'test'])
def test_add(self): l = UnorderedList() l.add(34) l.add('test') self.assertEqual(l.length(), 2) self.assertEqual(l.toList(), ['test', 34])
def test_pop(self): l = UnorderedList() l.add('test') l.add(34) l.add(0) l.append(78) l.pop(2) self.assertEqual(l.toList(), [0, 34, 78]) l.pop(0) self.assertEqual(l.toList(), [34, 78]) l.pop(5) self.assertEqual(l.toList(), [34, 78]) l.pop() self.assertEqual(l.toList(), [78])
def test_insert(self): l = UnorderedList() l.add('test') l.add(34) l.add(0) l.append(78) l.insert(2, 'inserted') self.assertEqual(l.toList(), [0, 34, 'inserted', 'test', 78]) l.insert(4, 'out') self.assertEqual(l.toList(), [0, 34, 'inserted', 'test', 'out', 78]) l.insert(0, 12) self.assertEqual(l.toList(), [12, 0, 34, 'inserted', 'test', 'out', 78]) l.insert(10, 100) self.assertEqual(l.toList(), [12, 0, 34, 'inserted', 'test', 'out', 78])
def test_index(self): l = UnorderedList() l.add('test') l.add(34) l.add(0) l.append(78) self.assertEqual(l.index(78), 3) self.assertEqual(l.index(0), 0) self.assertEqual(l.index('test'), 2)
def test_remove(self): l = UnorderedList() l.add('test') l.add(34) l.add(0) l.append(78) self.assertEqual(l.length(), 4) self.assertEqual(l.toList(), [0, 34, 'test', 78]) l.remove(34) self.assertEqual(l.toList(), [0, 'test', 78]) l.remove(45) self.assertEqual(l.toList(), [0, 'test', 78])
def test_index(self): l = UnorderedList() l.add('test') l.add(34) l.add(0) l.append(78) self.assertEqual(l.length(), 4) self.assertEqual(l.toList(), [0, 34, 'test', 78]) pos = l.index(34) self.assertEqual(pos, 1)
class UnorderedListTestCase(unittest.TestCase): def setUp(self): self.mylist = UnorderedList() self.mylist.add(12) self.mylist.add(22) self.mylist.add(9) self.mylist.add(89) self.mylist.add(71) self.mylist.add(16) def test_length(self): self.assertEqual(self.mylist.length(), 6) def test_search(self): self.assertEqual(self.mylist.search(12), True) self.assertEqual(self.mylist.search(3), False) def test_remove(self): self.mylist.remove(12) self.mylist.remove(11) self.assertEqual(self.mylist.search(12), False) self.assertEqual(self.mylist.search(11), False) self.assertEqual(self.mylist.length(), 5) def test_toList(self): self.assertEqual(self.mylist.toList(), [16, 71, 89, 9, 22, 12])