def test_tail(self): self.assertEqual(self.uut.head, None) x = LinkedNode(4) y = LinkedNode(4) z = LinkedNode(6) self.uut.unshift_node(x) self.assertEqual(x, y) self.assertEqual(self.uut.tail, x) self.assertEqual(self.uut.tail, y) self.uut.push_node(z) self.assertEqual(self.uut.tail, 6)
def test_pop_node(self): expected = list(range(10)) for x in expected: self.uut.push_node(LinkedNode(x)) self.assertTrue(bool(self.uut)) while self.uut: self.assertEqual(expected[-1], self.uut.pop_node().value) expected = expected[:-1] self.assertFalse(bool(self.uut)) for x in range(-10, 11): self.uut.unshift_node(LinkedNode(x)) self.assertEqual(x, self.uut.pop_node().value) self.uut.push_node(LinkedNode(x)) self.assertEqual(x, self.uut.pop_node().value)
def test_shift_node(self): expected = list(range(10)) for x in expected: # Place on the back... self.uut.push_node(LinkedNode(x)) self.assertTrue(bool(self.uut)) while self.uut: # Read from the front... self.assertEqual(expected[0], self.uut.shift_node().value) expected = expected[1:] self.assertFalse(bool(self.uut)) # We aren't testing Cache.clear() here... self.uut = Cache() for x in range(-10, 11): self.uut.unshift_node(LinkedNode(x)) self.assertEqual(x, self.uut.shift_node().value) self.uut.push_node(LinkedNode(x)) self.assertEqual(x, self.uut.shift_node().value)
def test_empty(self): self.assertFalse(bool(self.uut)) self.uut.push_node(LinkedNode(1)) self.assertTrue(bool(self.uut))
def test_unshift(self): for x in range(10): self.uut.unshift_node(LinkedNode(x))
def test_push(self): for x in range(10): self.uut.push_node(LinkedNode(x))