def read(filename: str) -> Problem: with open(filename, 'r') as f: (total_rows, total_columns, num_cars, num_rides, in_time_start_bonus, steps) = map(int, f.readline().split()) rides = [] for i in range(num_rides): ( start_row, start_column, end_row, end_column, earliest_start, latest_finish, ) = map(int, f.readline().split()) rides.append( Ride(start=Point(start_row, start_column), finish=Point(end_row, end_column), time_start=earliest_start, time_end=latest_finish, index=i)) return Problem( num_rides=num_rides, num_cars=num_cars, size=Size(rows=total_rows, columns=total_columns), rides=rides, in_time_start_bonus=in_time_start_bonus, num_steps=steps, )
def test_min_score(self): query_frame = Frame( frame_id=0, timestamp=0, ball_coordinates=Point(x=0, y=0), home_players_coordinates={}, away_players_coordinates={} ) dataset = TrackingDataset( dataset_id="test", frames=[ # this frame will score less than 90 replace( query_frame, frame_id=1, ball_coordinates=Point(x=0, y=68) ), replace( query_frame, frame_id=3 ) ] ) resultset = SearchEngine.search( dataset, matcher=MunkresMatcher(query_frame), min_score=90 ) assert resultset.results == [Result(frame_id=3, score=100)]
def test_ball_distance(self): frame1 = Frame(frame_id=0, timestamp=10, home_players_coordinates={}, away_players_coordinates={}, ball_coordinates=Point(x=0, y=0)) frame2 = Frame(frame_id=1, timestamp=10, home_players_coordinates={}, away_players_coordinates={}, ball_coordinates=Point(x=0, y=0)) munkres_matcher = MunkresMatcher(reference_frame=frame1) score = munkres_matcher.match(frame2) assert score == 100 frame3 = Frame(frame_id=0, timestamp=10, home_players_coordinates={}, away_players_coordinates={}, ball_coordinates=Point(x=0, y=1)) score = munkres_matcher.match(frame3) assert score == 99.5 frame4 = Frame(frame_id=0, timestamp=10, home_players_coordinates={}, away_players_coordinates={}, ball_coordinates=Point(x=0, y=10)) score = munkres_matcher.match(frame4) assert score == 94.35614381022528
def test_checkWin5(self): """ We verify if the check works well when we don't have a win """ self.repo.Empty() self.repo.makeMovePlayer(Point(0, 0, "O")) self.repo.makeMovePlayer(Point(0, 1, "O")) self.repo.makeMovePlayer(Point(0, 2, "O")) self.repo.makeMovePlayer(Point(0, 3, "O")) self.assertEqual(False, self.repo.checkWin())
def test_makeMoveAi(self): self.repo.makeMoveAi() self.repo.makeMovePlayer(Point(2, 1, "X")) self.repo.makeMovePlayer(Point(2, 2, "X")) self.repo.makeMovePlayer(Point(2, 3, "X")) self.repo.makeMoveAi() self.assertEqual(self.repo.checkWin(), False) self.repo.makeMovePlayer(Point(2, 4, "X")) self.repo.makeMoveAi() self.assertEqual(self.repo.checkWin(), True)
def test_checkWin1(self): """ We verify if the check works well when we have a diagonal """ self.repo.makeMovePlayer(Point(0, 0, "O")) self.repo.makeMovePlayer(Point(1, 1, "O")) self.repo.makeMovePlayer(Point(2, 2, "O")) self.repo.makeMovePlayer(Point(3, 3, "O")) self.repo.makeMovePlayer(Point(4, 4, "O")) self.assertEqual(True, self.repo.checkWin())
def test_checkWin4(self): """ We verify if the check works well when we have a 5 consecutive in a column """ self.repo.Empty() self.repo.makeMovePlayer(Point(0, 0, "O")) self.repo.makeMovePlayer(Point(1, 0, "O")) self.repo.makeMovePlayer(Point(2, 0, "O")) self.repo.makeMovePlayer(Point(3, 0, "O")) self.repo.makeMovePlayer(Point(4, 0, "O")) self.assertEqual(True, self.repo.checkWin())
def test_checkWin6(self): """ We verify if the check works well when we don't have a win """ self.repo.Empty() self.repo.makeMovePlayer(Point(2, 0, "X")) self.repo.makeMovePlayer(Point(2, 1, "X")) self.repo.makeMovePlayer(Point(2, 2, "X")) self.repo.makeMovePlayer(Point(2, 3, "X")) self.repo.makeMovePlayer(Point(2, 4, "X")) self.assertEqual(True, self.repo.checkWin())
def test_checkWin2(self): """ We verify if the check works well when we have 5 consecutive in a row """ self.repo.Empty() self.repo.makeMovePlayer(Point(0, 0, "O")) self.repo.makeMovePlayer(Point(0, 1, "O")) self.repo.makeMovePlayer(Point(0, 2, "O")) self.repo.makeMovePlayer(Point(0, 3, "O")) self.repo.makeMovePlayer(Point(0, 4, "O")) self.assertEqual(True, self.repo.checkWin())
def readTheDataset(self, filename): with open(filename, 'r') as file: reader = csv.reader(file) rows = [] for row in reader: rows.append(row) del rows[0] for row in rows: row[1], row[2] = float(row[1]), float(row[2]) point = Point(*row[1:3]) point.setTheDatasetLabel(row[0]) self.__points.append(point)
def test_single_match(self): query_frame = Frame( frame_id=0, timestamp=0, ball_coordinates=Point(x=0, y=0), home_players_coordinates={}, away_players_coordinates={} ) dataset = TrackingDataset( dataset_id="test", frames=[ replace( query_frame, frame_id=1 ) ] ) resultset = SearchEngine.search( dataset, matcher=MunkresMatcher(query_frame) ) assert resultset.results == [Result(frame_id=1, score=100)]
def test_valide_move(self): self.assertEqual(self.repo.valide_move(1, 3), True) self.assertEqual(self.repo.valide_move(0, -1), False) self.assertEqual(self.repo.valide_move(5, 5), True) self.assertEqual(self.repo.valide_move(1, 0), True) self.repo.makeMovePlayer(Point(0, 3, "O")) self.assertEqual(self.repo.valide_move(0, 3), False)
def test_single_frame(self): search_service = self._init_search_service() search_service.repository.save( TrackingDataset(dataset_id="test", frames=[ Frame(frame_id=1, timestamp=0, ball_coordinates=Point(x=0, y=0), home_players_coordinates={}, away_players_coordinates={}), Frame(frame_id=2, timestamp=0.1, ball_coordinates=Point(x=1, y=0), home_players_coordinates={}, away_players_coordinates={}) ])) resultset = search_service.search_by_frame("test", 1) assert resultset.results == [Result(frame_id=2, score=99.5)]
def test_same_frame(self): repository = MemoryRepository() repository.save( TrackingDataset(dataset_id="test", frames=[ Frame(frame_id=1, timestamp=0, ball_coordinates=Point(x=0, y=0), home_players_coordinates={}, away_players_coordinates={}) ])) search_service = self._init_search_service(repository=repository) resultset = search_service.search_by_frame("test", 1) assert len(resultset.results) == 0
def test_empty_resultset(self): query_frame = Frame( frame_id=0, timestamp=0, ball_coordinates=Point(x=0, y=0), home_players_coordinates={}, away_players_coordinates={} ) dataset = TrackingDataset( dataset_id="test", frames=[] ) resultset = SearchEngine.search( dataset, matcher=MunkresMatcher(query_frame) ) assert len(resultset.results) == 0
def _create_point(x: str, y: str) -> Point: return Point(x=float(x) * 105, y=float(y) * 68)
def test_makeMovePlayer(self): self.repo.makeMovePlayer(Point(0, 3, "O")) self.assertEqual(self.repo.valide_move(0, 3), False)