def test_stations_coverage(self): sq = cities.SquareCity(6, 7 * 4, 2) cells = set(sq.city_map.keys()) stations, clusters = sq.place_stations_new("central", 16) self.assertEqual( cells, {c for c in cells for cells in clusters}, "There are cells that are not covered by any station.")
def test_total_d_stations(self): sq = cities.SquareCity(6, 7 * 4, 2) min_d_stations = 10 self.assertEqual( sq.set_max_chargers_stations(2, 10)[1], 16, "Number of small distributed stations is not the expected.") self.assertEqual( sq.set_max_chargers_stations(2, 16)[1], 16, "Number of small distributed stations is not the expected.") self.assertEqual( sq.set_max_chargers_stations(2, 17)[1], 36, "Number of small distributed stations is not the expected.")
def test_lattice_distance(self): sq = cities.SquareCity(6, 7 * 4, 2) # With this city the SIZE = 72 self.assertEqual(lattice_distance(0, 0, 0, 0), 0, "Lattice distance for zero distance not working") self.assertEqual(lattice_distance(0, 0, 10, 10), 20, "Lattice distance same cuadrant not working") self.assertEqual(lattice_distance(0, 0, 71, 71), 2), "Lattice distance different cuadrants not working" self.assertEqual( lattice_distance(10, 10, 50, 50), 64), "Lattice distance different cuadrants not working"
def test_rechability(self): sq = cities.SquareCity(6, 5 * 4, 2) city_map = sq.city_map all_cells = set(city_map.values()) start = random.choice(list(all_cells)) visited = set() open_set = [start] while open_set: current = open_set.pop() visited.add(current) for cell in current.successors: if cell not in visited: open_set.append(cell) self.assertEqual(all_cells, visited, "There are cells that are not reachable")
def test_stations_placement(self): sq = cities.SquareCity(6, 7 * 4, 2) stations, clusters = sq.place_stations_new("central", 16) self.assertTrue( len(stations) == len(clusters), "Number of stations cluster doesn't match the service areas.") stations, clusters = sq.place_stations_new("distributed", 16) self.assertTrue( len(stations) == len(clusters), "Number of stations cluster doesn't match the service areas.") stations, clusters = sq.place_stations_new("four", 16) self.assertTrue( len(stations) == len(clusters), "Number of stations cluster doesn't match the service areas.")
def test_size(self): sq = cities.SquareCity(6, 7 * 4, 2) matrix = sq.city_matrix base = 6 + 2 + 7 * 4 self.assertEqual(matrix.shape, (2 * base, 2 * base), "Square city shape is not squared")
def test_different_types(self): sq = cities.SquareCity(6, 7 * 4, 2) av, rb, st = sq.avenues, sq.roundabouts, sq.streets self.assertEqual(av.intersection(rb, st), set(), "There are collisions between the cell types")
def test_path_length(self): sq = cities.SquareCity(6, 7 * 4, 2)