Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_remove(self):
q = BoundedPriorityQueue(2)
a = DummyNode(1)
b = DummyNode(2)
q.append(a)
q.append(b)
q.remove(a)
self.assertEqual(len(q), 1)
self.assertIs(q[0], b)
def test_sorted_priority(self):
q = BoundedPriorityQueue()
q.append(DummyNode(3))
q.append(DummyNode(1))
q.append(DummyNode(2))
self.assertTrue(sorted_equals_pop(q))
def test_limit_works_on_append(self):
q = BoundedPriorityQueue(2)
q.append(DummyNode(1))
q.append(DummyNode(1))
q.append(DummyNode(1))
self.assertEqual(len(q), 2)
def test_limit_works_on_extend(self):
q = BoundedPriorityQueue(2)
q.extend([DummyNode(1), DummyNode(1), DummyNode(1)])
self.assertEqual(len(q), 2)
def test_pop_works_with_order(self):
q = BoundedPriorityQueue()
q.append(DummyNode(3))
q.append(DummyNode(1))
q.append(DummyNode(2))
self.assertEqual(q.pop().value, 1)
def test_solution_is_node(self):
node = genetic(self.problem, iterations_limit=1, mutation_chance=0, population_size=1)
self.assertIsInstance(node, SearchNode)
def test_equals(self):
n1 = SearchNode(problem=self.problem, state='i')
n2 = SearchNode(problem=self.problem, state='i')
n3 = SearchNode(problem=self.problem, state='i', action='a')
n4 = SearchNode(problem=self.problem, state='ia')
self.assertTrue(n1 == n2)
self.assertTrue(n1 == n3)
self.assertFalse(n1 == n4)
def test_path(self):
n1 = SearchNode(problem=self.problem, state='i')
n2 = SearchNode(action='a', state='ia', parent=n1)
n3 = SearchNode(action='b', state='iab', parent=n2)
path = [(None, 'i'), ('a', 'ia'), ('b', 'iab')]
self.assertEqual(n3.path(), path)
def test_path(self):
n1 = SearchNode(problem=self.problem, state='i')
n2 = SearchNode(action='a', state='ia', parent=n1)
n3 = SearchNode(action='b', state='iab', parent=n2)
path = [(None, 'i'), ('a', 'ia'), ('b', 'iab')]
self.assertEqual(n3.path(), path)
def test_equals(self):
n1 = SearchNode(problem=self.problem, state='i')
n2 = SearchNode(problem=self.problem, state='i')
n3 = SearchNode(problem=self.problem, state='i', action='a')
n4 = SearchNode(problem=self.problem, state='ia')
self.assertTrue(n1 == n2)
self.assertTrue(n1 == n3)
self.assertFalse(n1 == n4)