def test_select_rear_west(self): """Выбираются тыловые аэродромы для синих""" tvd_builder = processing.TvdBuilder(MOSCOW, IOC) IOC.grid_controller.get_file = _get_xgml_file_mock tvd = tvd_builder.get_tvd('11.11.1941') north = IOC.config.mgen.cfg[MOSCOW]['right_top']['x'] east = IOC.config.mgen.cfg[MOSCOW]['right_top']['z'] boundary_builder = processing.BoundaryBuilder(north=north, east=east, south=0, west=0) grid = IOC.grid_controller.get_grid(MOSCOW) exclude = boundary_builder.confrontation_west(grid=grid) include = boundary_builder.influence_west(border=grid.border) airfield1, airfield2, airfield3 = ( x for x in self.storage.airfields.load_by_tvd(MOSCOW) if x.name in ('rjev', 'sychevka', 'karpovo')) self.controller.add_aircraft(tvd.name, 201, airfield1.name, TEST_AIRCRAFT_NAME2, 10) self.controller.add_aircraft(tvd.name, 201, airfield2.name, TEST_AIRCRAFT_NAME2, 15) self.controller.add_aircraft(tvd.name, 201, airfield3.name, TEST_AIRCRAFT_NAME2, 20) selector = processing.AirfieldsSelector(IOC.config.main) # Act result = selector.select_rear( influence=include, front_area=exclude, airfields=self.storage.airfields.load_by_tvd(MOSCOW)) # Assert self.assertIn(result, [airfield1, airfield2, airfield3])
def test_build_west_complex(self): """Создаётся корректный многоугольник для 'сложной' линии фронта""" builder = processing.BoundaryBuilder(self.north, self.east, self.south, self.west) points = [ geometry.Point(x=1, z=1), geometry.Point(x=1, z=9), geometry.Point(x=9, z=9), geometry.Point(x=7, z=4), geometry.Point(x=5, z=4), geometry.Point(x=4, z=1), geometry.Point(x=8, z=3), geometry.Point(x=8, z=1), ] nodes = tests.utils.get_nodes(points) points.reverse() expected = [ geometry.Point(x=self.south, z=1), geometry.Point(x=self.south, z=self.west), geometry.Point(x=self.north, z=self.west), geometry.Point(x=self.north, z=1) ] + points # Act result = builder.influence_west(nodes) # Assert self.assertSequenceEqual(result, expected)
def test_select_front_west(self): """Выбираются фронтовые аэродромы для синих""" tvd_builder = processing.TvdBuilder(MOSCOW, IOC) IOC.grid_controller.get_file = _get_xgml_file_mock tvd = tvd_builder.get_tvd('11.11.1941') north = IOC.config.mgen.cfg[MOSCOW]['right_top']['x'] east = IOC.config.mgen.cfg[MOSCOW]['right_top']['z'] boundary_builder = processing.BoundaryBuilder(north=north, east=east, south=0, west=0) include = boundary_builder.confrontation_west( grid=IOC.grid_controller.get_grid(MOSCOW)) airfield1, airfield2 = ( x for x in self.storage.airfields.load_by_tvd(MOSCOW) if x.name in ('lotoshino', 'migalovo')) self.controller.add_aircraft(tvd.name, 201, airfield1.name, TEST_AIRCRAFT_NAME2, 10) self.controller.add_aircraft(tvd.name, 201, airfield2.name, TEST_AIRCRAFT_NAME2, -10) selector = processing.AirfieldsSelector(IOC.config.main) # Act result = selector.select_front( front_area=include, airfields=self.storage.airfields.load_by_tvd(MOSCOW)) # Assert self.assertEqual(3, len(result)) self.assertIn(airfield1, result) self.assertIn(airfield2, result)
def test_confrontation_area_east(self): """Создаётся многоугольник восточной прифронтовой полосы""" expected_keys = (7, 34, 35, 36, 46, 45, 40, 11, 1, 25, 41, 43, 44, 31, 32, 18, 6) builder = processing.BoundaryBuilder(self.north, self.east, self.south, self.west) grid = tests.mocks.get_test_grid(MGEN) # Act result = builder.confrontation_east(grid) # Assert self.assertSequenceEqual(tuple(int(x.key) for x in result), expected_keys)
def test_confrontation_area_west(self): """Создаётся многоугольник западной прифронтовой полосы""" expected_keys = (2, 26, 42, 29, 16, 5, 6, 18, 32, 31, 44, 43, 41, 25, 1) builder = processing.BoundaryBuilder(self.north, self.east, self.south, self.west) grid = tests.mocks.get_test_grid(MGEN) # Act result = builder.confrontation_west(grid) # Assert self.assertSequenceEqual(tuple(int(x.key) for x in result), expected_keys)
def boundary_builder(self) -> processing.BoundaryBuilder: """Сборщик многоугольников для Influence Area""" if not self._boundary_builder: offset = 10000 north = self.config.mgen.cfg[self.name]['right_top']['x'] + offset east = self.config.mgen.cfg[self.name]['right_top']['z'] + offset south = 0 - offset west = 0 - offset self._boundary_builder = processing.BoundaryBuilder(north=north, east=east, south=south, west=west) return self._boundary_builder
def test_get_confrontation_nodes(self): """Определяются вершины, входящие в прифронтовую полосу""" expected_keys = { 101: ('24', '11', '40', '45', '47', '46', '36', '35', '33', '34', '19', '7'), 201: ('2', '12', '26', '42', '29', '16', '30', '17', '5') } countries = (101, 201) builder = processing.BoundaryBuilder(self.north, self.east, self.south, self.west) grid = tests.mocks.get_test_grid(MGEN) for country in countries: # Act result = tests.utils.get_nodes_keys( list(builder.get_confrontation_nodes(grid, country))) # Assert self.assertCountEqual(expected_keys[country], result, msg=country)
def test_confrontation_area_stalingrad_east(self): """Создаётся многоугольник восточной прифронтовой полосы""" xgml = processing.Xgml(STALIN, MGEN) xgml.parse(str(MGEN.xgml[STALIN])) expected_keys = (192, 57, 196, 197, 185, 188, 187, 48, 110, 25, 102, 19, 95, 3, 191, 209, 94, 93, 96, 101, 100, 99, 137, 139, 138, 157, 186, 163, 164, 165, 184, 183, 182, 194, 193, 177) builder = processing.BoundaryBuilder(self.north, self.east, self.south, self.west) grid = model.Grid(STALIN, xgml.nodes, xgml.edges, 1) path = pathlib.Path(r'./tmp/{}_{}.xgml'.format(STALIN, 0)) xgml.save_file(str(path), grid.nodes, grid.edges) # Act result = builder.confrontation_east(grid) # Assert self.assertSequenceEqual(tuple(int(x.key) for x in result), expected_keys)
def test_build_east(self): """Создаётся корректный многоугольник восточной InfluenceArea""" builder = processing.BoundaryBuilder(self.north, self.east, self.south, self.west) points = [ geometry.Point(x=1, z=6), geometry.Point(x=4, z=3), geometry.Point(x=5, z=6), geometry.Point(x=7, z=4), geometry.Point(x=9, z=6) ] nodes = tests.utils.get_nodes(points) expected = points + [ geometry.Point(x=self.north, z=6), geometry.Point(x=self.north, z=self.east), geometry.Point(x=self.south, z=self.east), geometry.Point(x=self.south, z=6) ] # Act result = builder.influence_east(nodes) # Assert self.assertSequenceEqual(result, expected)