コード例 #1
0
ファイル: test_queue.py プロジェクト: hermajan/algorithms
	def test_enqueue(self):
		q = Queue()
		q.enqueue(1)

		# Inserting to empty queue.
		self.assertIsNotNone(q.first)
		self.assertIsNotNone(q.last)

		self.assertEqual(q.first.value, 1)
		self.assertIsNone(q.first.left)
		self.assertEqual(q.last.value, 1)
		self.assertIsNone(q.last.left)

		# Inserting to nonempty queue.
		q = Queue()
		i = Item()
		i.left = None
		i.value = 1
		q.first = i
		q.last = i

		q.enqueue(2)
		self.assertIsNotNone(q.first)
		self.assertIsNotNone(q.last)

		self.assertEqual(q.last.value, 2)
		self.assertEqual(q.first, i)
		self.assertEqual(q.first.left.value, 2)
コード例 #2
0
    def test_enqueue(self):
        q = Queue()
        q.enqueue(1)

        # Inserting to empty queue.
        self.assertIsNotNone(q.first)
        self.assertIsNotNone(q.last)

        self.assertEqual(q.first.value, 1)
        self.assertIsNone(q.first.left)
        self.assertEqual(q.last.value, 1)
        self.assertIsNone(q.last.left)

        # Inserting to nonempty queue.
        q = Queue()
        i = Item()
        i.left = None
        i.value = 1
        q.first = i
        q.last = i

        q.enqueue(2)
        self.assertIsNotNone(q.first)
        self.assertIsNotNone(q.last)

        self.assertEqual(q.last.value, 2)
        self.assertEqual(q.first, i)
        self.assertEqual(q.first.left.value, 2)
コード例 #3
0
ファイル: test_queue.py プロジェクト: hermajan/algorithms
	def test_isEmpty(self):
		q = Queue()
		self.assertTrue(q.isEmpty())

		i = Item()
		i.left = None
		i.value = 1
		q.first = i
		q.last = i
		self.assertFalse(q.isEmpty())
コード例 #4
0
    def test_isEmpty(self):
        q = Queue()
        self.assertTrue(q.isEmpty())

        i = Item()
        i.left = None
        i.value = 1
        q.first = i
        q.last = i
        self.assertFalse(q.isEmpty())
コード例 #5
0
ファイル: test_queue.py プロジェクト: hermajan/algorithms
	def test_dequeue(self):
		q = Queue()
		v = q.dequeue()

		# Deleting in empty queue.
		self.assertIsNone(v)
		self.assertIsNone(q.first)
		self.assertIsNone(q.last)

		# Deleting in nonempty queue.
		q = Queue()
		i = Item()
		i.value = 1
		i.left = None
		q.first = i
		q.last = i
		v = q.dequeue()

		self.assertEqual(v, 1)
		self.assertIsNone(q.first)
		self.assertIsNone(q.last)
コード例 #6
0
    def test_dequeue(self):
        q = Queue()
        v = q.dequeue()

        # Deleting in empty queue.
        self.assertIsNone(v)
        self.assertIsNone(q.first)
        self.assertIsNone(q.last)

        # Deleting in nonempty queue.
        q = Queue()
        i = Item()
        i.value = 1
        i.left = None
        q.first = i
        q.last = i
        v = q.dequeue()

        self.assertEqual(v, 1)
        self.assertIsNone(q.first)
        self.assertIsNone(q.last)