def GetAntsController(configprovider, maze, baseTestFolder): metadataconsumer = AntsMetaDataConsumerWrapper(configprovider) server_comm = ServerComm(configprovider) ant_step_processer = AntStepProcesser(configprovider) # metadataconsumer.AddConsumer(RobotMetadataConsumer(configprovider, server_comm, ant_step_processer)) metadataconsumer.AddConsumer(LoggingAntsMetaDataConsumer(configprovider)) metadataconsumer.AddConsumer( MetrySenderMetaDataConsumer(configprovider, AlgoAntMetaDataToNodeStateInterperter())) metadataconsumer.AddConsumer( AlgoAntDrawingMetaDataConsumer(configprovider)) metadataconsumer.AddConsumer( DillAntsMetaDataConsumer( configprovider, CreateFolder(configprovider, baseTestFolder, "Data"))) performancecounterwritter = PerofromanceWriterWrapper(configprovider) performancecounterwritter.AddWritter( LoggerPerofromanceWriter(configprovider)) performancecounterwritter.AddWritter( DillPerofromanceWriter( configprovider, CreateFolder(configprovider, baseTestFolder, "Performance"))) evaluationWrapper = EvaluationResponseWrapper(configprovider) evaluationWrapper.AddEvaluator(SimpleAntEvaluator(configprovider)) commandreciver = CommandsReciver(configprovider) commandreciver.Start() return SimpleAntsContrller( configprovider, maze, metadataconsumer, performancecounterwritter, UnifiedWorldImageProvider(configprovider, maze, commandreciver), RobotAlgoAntProducer(configprovider, ant_step_processer.initial_position(), server_comm=server_comm), evaluationWrapper)
def test__ant_not_on_field(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 0) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) is_on_field = processor.is_ant_on_field(99) self.assertTrue(not is_on_field)
def test__empty_ant(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 0) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) position_data = processor.get_ant_position_and_direction(99) self.assertTrue(position_data[0] == -1 and position_data[1] == -1 and position_data[2] == -1)
def test__from_north_step_back(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 0) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) processor.process_ant_step(99, StepEnum.Back) position_data = processor.get_ant_position_and_direction(99) self.assertTrue(position_data[1] == 2)
def test__initial_step_turn(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 0) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) processor.process_ant_step(99, StepEnum.TurnRight) position_data = processor.get_ant_position_and_direction(99) self.assertTrue(position_data[2] == DirectionsEnum.East)
def test__y_negetive_south_facing_axis_movment(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 1) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) processor.process_ant_step(99, StepEnum.NoStep) translate = TranslateStep(config, processor) step = AntStep(99, Position(1, 0)) movment = translate.TranlateStep(step) self.assertTrue(movment[0] == StepEnum.Back)
def test__x_positive_east_facing_axis_movment(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 2) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) processor.process_ant_step(99, StepEnum.NoStep) translate = TranslateStep(config, processor) step = AntStep(99, Position(2, 1)) movment = translate.TranlateStep(step) self.assertTrue(len(movment) == 1) self.assertTrue(movment[0] == StepEnum.Forward)
def GetAntsController(configprovider, maze, baseTestFolder): metadataconsumer = AntsMetaDataConsumerWrapper(configprovider) server_comm = ServerComm(config) ant_step_processer = AntStepProcesser(config) metadataconsumer.AddConsumer( RobotMetadataConsumer(config, server_comm, ant_step_processer)) metadataconsumer.AddConsumer(LoggingAntsMetaDataConsumer(config)) #metadataconsumer.AddConsumer(DrawingMetaDataConsumer(config,CreateFolder(configprovider,baseTestFolder,"Drawing_Maze"),maze.GetEnterence())) metadataconsumer.AddConsumer( MetrySenderMetaDataConsumer(config, DummyMetaDataToNodeStateInterperter())) metadataconsumer.AddConsumer( DillAntsMetaDataConsumer( config, CreateFolder(configprovider, baseTestFolder, "Data"))) performancecounterwritter = PerofromanceWriterWrapper(configprovider) performancecounterwritter.AddWritter( LoggerPerofromanceWriter(configprovider)) performancecounterwritter.AddWritter( DillPerofromanceWriter( configprovider, CreateFolder(configprovider, baseTestFolder, "Performance"))) evaluationWrapper = EvaluationResponseWrapper(configprovider) evaluationWrapper.AddEvaluator(SimpleAntEvaluator(configprovider)) step_enabler = TimedStepEnabler( int( configprovider.GetConfigValueForSectionAndKey( "RunDefinations", "SecondsPerStep", 5))) commandreciver = CommandsReciver(configprovider) commandreciver.Start() return SimpleAntsContrller( config, maze, metadataconsumer, performancecounterwritter, SimpleWorldImageProvider(config, maze, commandreciver), RobotAntProducer(configprovider, maze.GetEnterence(), server_comm=server_comm), evaluationWrapper)
def test__complex_set_1(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 0) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) processor.process_ant_step(99, StepEnum.Back) processor.process_ant_step(99, StepEnum.Back) processor.process_ant_step(99, StepEnum.TurnRight) processor.process_ant_step(99, StepEnum.Forward) position_data = processor.get_ant_position_and_direction(99) self.assertTrue(position_data[0] == 2) self.assertTrue(position_data[1] == 3) self.assertTrue(position_data[2] == DirectionsEnum.East)
def test__from_east_step_forward(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 0) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) processor.process_ant_step(99, StepEnum.TurnRight) processor.process_ant_step(99, StepEnum.Forward) position_data = processor.get_ant_position_and_direction(99) self.assertTrue(position_data[0] == 2)
def test__initial_ant_and_no_ant(self): config = DictionaryConfigProvider() config.SetValue('InitialPosition', 'InitialDirection', 0) config.SetValue('InitialPosition', 'InitialPosition_x', 1) config.SetValue('InitialPosition', 'InitialPosition_y', 1) processor = AntStepProcesser(config) processor.process_ant_step(99, StepEnum.NoStep) position_data = processor.get_ant_position_and_direction(99) self.assertTrue(position_data[0] == 1 and position_data[1] == 1 and position_data[2] == DirectionsEnum.North) position_data = processor.get_ant_position_and_direction(100) self.assertTrue(position_data[0] == -1 and position_data[1] == -1 and position_data[2] == -1)