def test_pop_front(self): q = LinkedDeque() with self.assertRaises(ValueError): q.pop_front() q.push_front("A") assert q.length() == 1 assert q.pop_front() == "A" assert q.is_empty() is True q.push_front("one") q.push_back("two") assert q.pop_front() == "one" assert q.pop_front() == "two" with self.assertRaises(ValueError): q.pop_front() assert q.is_empty() is True
def test_pop_back(self): dq = LinkedDeque(['A', 'B', 'C']) assert dq.length() == 3 assert dq.front() == 'A' dq.pop_back() assert dq.length() == 2 assert dq.front() == 'A' dq.pop_back() assert dq.length() == 1 assert dq.front() == 'A' assert dq.is_empty() == False dq.pop_back() assert dq.length() == 0 assert dq.front() == None assert dq.is_empty() == True
def test_push_back(self): dq = LinkedDeque() dq.push_back('A') assert dq.length() == 1 assert dq.front() == 'A' dq.push_back('B') assert dq.length() == 2 assert dq.front() == 'A' dq.push_back('C') assert dq.length() == 3 assert dq.front() == 'A' assert dq.is_empty() == False
class TestLinkedDeque(unittest.TestCase): def setUp(self): self.deque = LinkedDeque() def test_push(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.assertEqual(self.deque.size, 3) def test_push_left(self): self.deque.push_left(1) self.deque.push_left(2) self.deque.push_left(3) self.assertEqual(self.deque.size, 3) def test_pop(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.assertEqual(self.deque.pop(), 3) self.assertEqual(self.deque.size, 2) def test_pop_left(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.assertEqual(self.deque.pop_left(), 1) self.assertEqual(self.deque.size, 2) def test_remove(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.deque.remove(1) self.assertEqual(self.deque.size, 2) def test_clear(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.assertEqual(self.deque.size, 3) self.deque.clear() self.assertEqual(self.deque.size, 0) def test_is_empty(self): self.assertEqual(self.deque.is_empty(), True)
class TestLinkedDeque(unittest.TestCase): def setUp(self): self.deque = LinkedDeque() def test_push(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.assertEqual(self.deque.size, 3) def test_push_left(self): self.deque.push_left(1) self.deque.push_left(2) self.deque.push_left(3) self.assertEqual(self.deque.size, 3) def test_pop(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.assertEqual(self.deque.pop(), 3) self.assertEqual(self.deque.size, 2) def test_pop_left(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.assertEqual(self.deque.pop_left(), 1) self.assertEqual(self.deque.size, 2) def test_remove(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.deque.remove(1) self.assertEqual(self.deque.size, 2) def test_clear(self): self.deque.push(1) self.deque.push(2) self.deque.push(3) self.assertEqual(self.deque.size, 3) self.deque.clear() self.assertEqual(self.deque.size, 0) def test_is_empty(self): self.assertEqual(self.deque.is_empty(), True)
def test_init(self): dq = LinkedDeque() assert dq.front() is None assert dq.length() == 0 assert dq.is_empty() is True
def test_init_with_list(self): dq = LinkedDeque(['A', 'B', 'C']) assert dq.front() == 'A' assert dq.length() == 3 assert dq.is_empty() is False