def test_min(self): s = SortedList() for i in {1, 3, 4, 7, 2, 4, 8}: s.add(i) self.assertEqual(min(s), 1) s.add(0) self.assertEqual(min(s), 0)
def test_len(self): s = SortedList() for i in range(20): s.add(i) self.assertEqual(len(s), 20) s.remove(4) self.assertEqual(len(s), 19)
def test_max(self): s = SortedList() for i in {3, 4, 2, 6, 8}: s.add(i) self.assertEqual(max(s), 8) s.add(100) self.assertEqual(max(s), 100)
def test_remove(self): s = SortedList() for i in range(10): s.add(i + (-1)**i) for i in range(10): s.remove(i) self.assertFalse(s)
def transpose(self): T = Matrix() for i in range(len(self)): L = SortedList() for j in range(len(self)): if i in self[j]: L.add(j) T.insert_col(L) return T
def test_add(self): s = SortedList() for i in range(10): s.add(i + (-1)**i) self.assertEqual(s, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) s = SortedList() self.assertFalse(s) for i in {2, 5, 8, 0, 1, 3}: s.add(i) self.assertEqual(s, [0, 1, 2, 3, 5, 8])
def search(self, current): print("----------") print("Current: {}".format(current.label)) current.visitaded = True if current == self.goal: self.find = True else: sorted_list = SortedList(len(current.adjacent)) for i in current.adjacent: if i.vertex.visitaded == False: i.vertex.visitaded == True sorted_list.add(i.vertex) sorted_list.show() if sorted_list.values[0] != None: self.search(sorted_list.values[0])
def test_contains(self): s = SortedList() for i in {2, 4, 6, 7, 8, 9}: s.add(i) for i in {2, 4, 6, 7, 8, 9}: self.assertIn(i, s)
def test_getitem(self): s = SortedList() for i in {1, 3, 5, 7, 9}: s.add(i) for i in range(5): self.assertEqual(s[i], 2 * i + 1)
def search(self, current): print("----------") print("Current: {}".format(current.label)) current.visitaded = True if current == self.goal: self.find = True else: sorted_list = SortedList(len(current.adjacent)) for i in current.adjacent: if i.vertex.visitaded == False: i.vertex.visitaded == True sorted_list.add(i.vertex) sorted_list.show() if sorted_list.values[0] != None: self.search(sorted_list.values[0]) graph = Graph() graph.arad.show_adjacent() list = SortedList(5) list.add(graph.arad) list.add(graph.craiova) list.add(graph.bucharest) list.add(graph.dobreta) list.show() greedy_search = GreedySearch(graph.bucharest) greedy_search.search(graph.arad)