Ejemplo n.º 1
0
    def test_direction_direct(self):
        test_data = {
            NORTH: {
                _p(NORTH): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 2, 0)
                    }
                }
            },
            NORTH: {
                _p(NORTH): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 2, 0)
                    }
                },
                _p(NORTH_WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_NONE: (9, 500, 0)
                    }
                }  # An other molecule type
            }
        }

        for direction in test_data:
            self._test_direction_for_points(test_data[direction], direction)
Ejemplo n.º 2
0
    def test_direction_direct(self):
        test_data = {
            NORTH: {
                _p(NORTH): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2, 0)}}
            },
            NORTH: {
                _p(NORTH): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2, 0)}},
                _p(NORTH_WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_NONE: (9, 500, 0)}}  # An other molecule type
            }
        }

        for direction in test_data:
            self._test_direction_for_points(test_data[direction], direction)
Ejemplo n.º 3
0
    def test_appose(self):
        self._test_point_raise_no_molecule()
        self._test_points_raise_no_molecule()

        # Une molecule au centre
        DirectionMolecule.appose(self._context, _p(CENTER),
                                 self._get_molecule(PHEROMON_DIR_EXPLO, 2))
        # Ne permet pas de trouver une route
        self._test_point_raise_no_molecule(re_init=False)
        self._test_points_raise_no_molecule(re_init=False)

        # Une molecule au nord
        DirectionMolecule.appose(self._context, _p(NORTH),
                                 self._get_molecule(PHEROMON_DIR_EXPLO, 1))
        # le permet
        self._test_direction_for_points({}, NORTH, re_init=False)
        self._test_direction_for_point({}, NORTH, re_init=False)
Ejemplo n.º 4
0
    def test_appose(self):
        self._test_point_raise_no_molecule()
        self._test_points_raise_no_molecule()

        # Une molecule au centre
        DirectionMolecule.appose(self._context,
                                  _p(CENTER),
                                  self._get_molecule(PHEROMON_DIR_EXPLO, 2))
        # Ne permet pas de trouver une route
        self._test_point_raise_no_molecule(re_init=False)
        self._test_points_raise_no_molecule(re_init=False)

        # Une molecule au nord
        DirectionMolecule.appose(self._context,
                                  _p(NORTH),
                                  self._get_molecule(PHEROMON_DIR_EXPLO, 1))
        # le permet
        self._test_direction_for_points({}, NORTH, re_init=False)
        self._test_direction_for_point({}, NORTH, re_init=False)
Ejemplo n.º 5
0
    def test_no_molecules_around(self):
        # No molecule
        with self.assertRaises(NoMolecule):
            self._test_direction_for_points({}, -1)

        # Wrong molecule type
        with self.assertRaises(NoMolecule):
            self._test_direction_for_points({
                _p(SOUTH_EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_NONE: (9, 5, 0)}}
            }, -1)
Ejemplo n.º 6
0
 def _test_points_raise_no_molecule(self,
                                    molecules={},
                                    direction=-1,
                                    molecule_type=PHEROMON_DIR_EXPLO,
                                    reference_point=_p(CENTER),
                                    re_init=True):
     with self.assertRaises(NoMolecule):
         self._test_direction_for_points(molecules,
                                         direction,
                                         re_init=re_init)
Ejemplo n.º 7
0
    def _test_direction_for_point(self, molecules, direction, molecule_type=PHEROMON_DIR_EXPLO,
                                  reference_point=_p(CENTER), re_init=True):
        """

        :param molecules:
        :param direction:
        :param molecule_type:
        :param reference_point:
        :return:
        """
        self._set_up_molecules(molecules, re_init=re_init)
        direction_tested = DirectionMolecule.get_direction_for_point(self._context, reference_point, molecule_type)
        self.assertEqual(direction, direction_tested, "Direction must be %s" % direction)
Ejemplo n.º 8
0
    def test_no_molecules_around(self):
        # No molecule
        with self.assertRaises(NoMolecule):
            self._test_direction_for_points({}, -1)

        # Wrong molecule type
        with self.assertRaises(NoMolecule):
            self._test_direction_for_points(
                {
                    _p(SOUTH_EST): {
                        MOLECULES_DIRECTION: {
                            PHEROMON_DIR_NONE: (9, 5, 0)
                        }
                    }
                }, -1)
Ejemplo n.º 9
0
    def test_route_with_multiple_different_intensity(self):
        """
        Test find route in middle of multiple molecules
        :return:
        """
        test_data = {
            NORTH_WEST: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 2, 0)
                    }
                },
                _p(NORTH_WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 2, 0)
                    }
                },
                _p(SOUTH_EST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (8, 1, 0)
                    }
                }
            },
            NORTH_WEST: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 2, 0)
                    }
                },
                _p(NORTH_WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 2, 0)
                    }
                },
                _p(SOUTH_EST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (8, 1, 0)
                    }
                },
                _p(SOUTH_EST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_NONE: (5, 10, 0)
                    }
                }  # an other molecule type
            }
        }

        for direction_wanted in test_data:
            self._test_direction_for_point(test_data[direction_wanted],
                                           direction_wanted)
Ejemplo n.º 10
0
    def test_direction_with_multiple_intensity(self):
        test_data = {
            NORTH: {
                _p(NORTH): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 5, 0)}},
                _p(SOUTH_EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4, 0)}},
                _p(NORTH_WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4, 0)}}
            },
            NORTH: {
                _p(NORTH): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 5, 0)}},
                _p(WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_NONE: (9, 500, 0)}},  # An other molecule_type
                _p(SOUTH_EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4, 0)}},
                _p(NORTH_WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 4, 0)}}
            }
        }

        for direction in test_data:
            self._test_direction_for_points(test_data[direction], direction)
Ejemplo n.º 11
0
    def _test_direction_for_point(self,
                                  molecules,
                                  direction,
                                  molecule_type=PHEROMON_DIR_EXPLO,
                                  reference_point=_p(CENTER),
                                  re_init=True):
        """

        :param molecules:
        :param direction:
        :param molecule_type:
        :param reference_point:
        :return:
        """
        self._set_up_molecules(molecules, re_init=re_init)
        direction_tested = DirectionMolecule.get_direction_for_point(
            self._context, reference_point, molecule_type)
        self.assertEqual(direction, direction_tested,
                         "Direction must be %s" % direction)
Ejemplo n.º 12
0
    def test_direction_with_multiple_intensity(self):
        test_data = {
            NORTH: {
                _p(NORTH): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 5, 0)
                    }
                },
                _p(SOUTH_EST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 4, 0)
                    }
                },
                _p(NORTH_WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 4, 0)
                    }
                }
            },
            NORTH: {
                _p(NORTH): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 5, 0)
                    }
                },
                _p(WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_NONE: (9, 500, 0)
                    }
                },  # An other molecule_type
                _p(SOUTH_EST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 4, 0)
                    }
                },
                _p(NORTH_WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 4, 0)
                    }
                }
            }
        }

        for direction in test_data:
            self._test_direction_for_points(test_data[direction], direction)
Ejemplo n.º 13
0
    def test_route_with_multiple_different_intensity(self):
        """
        Test find route in middle of multiple molecules
        :return:
        """
        test_data = {
            NORTH_WEST: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 2, 0)}},
                _p(NORTH_WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2, 0)}},
                _p(SOUTH_EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (8, 1, 0)}}
            },
            NORTH_WEST: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 2, 0)}},
                _p(NORTH_WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 2, 0)}},
                _p(SOUTH_EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (8, 1, 0)}},
                _p(SOUTH_EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_NONE: (5, 10, 0)}}  # an other molecule type
            }
        }

        for direction_wanted in test_data:
            self._test_direction_for_point(test_data[direction_wanted], direction_wanted)
Ejemplo n.º 14
0
    def test_route_direct_route(self):
        """
        Test easy direction with 1 best molecules just near actual position
        :return:
        """
        test_data = {
            NORTH_WEST: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1, 0)}},
                _p(NORTH_WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1, 0)}}
            },
            NORTH: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1, 0)}},
                _p(NORTH): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1, 0)}}
            },
            NORTH_EST: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1, 0)}},
                _p(NORTH_EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1, 0)}}
            },
            WEST: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1, 0)}},
                _p(WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1, 0)}}
            },
            EST: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1, 0)}},
                _p(EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1, 0)}}
            },
            SOUTH_WEST: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1, 0)}},
                _p(SOUTH_WEST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1, 0)}}
            },
            SOUTH: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1, 0)}},
                _p(SOUTH): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1, 0)}}
            },
            SOUTH_EST: {
                _p(CENTER): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (10, 1, 0)}},
                _p(SOUTH_EST): {MOLECULES_DIRECTION: {PHEROMON_DIR_EXPLO: (9, 1, 0)}}
            }
        }

        for direction_wanted in test_data:
            self._test_direction_for_point(test_data[direction_wanted], direction_wanted)
Ejemplo n.º 15
0
 def _test_points_raise_no_molecule(self, molecules={}, direction=-1, molecule_type=PHEROMON_DIR_EXPLO,
                              reference_point=_p(CENTER), re_init=True):
     with self.assertRaises(NoMolecule):
         self._test_direction_for_points(molecules, direction, re_init=re_init)
Ejemplo n.º 16
0
    def test_route_direct_route(self):
        """
        Test easy direction with 1 best molecules just near actual position
        :return:
        """
        test_data = {
            NORTH_WEST: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 1, 0)
                    }
                },
                _p(NORTH_WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 1, 0)
                    }
                }
            },
            NORTH: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 1, 0)
                    }
                },
                _p(NORTH): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 1, 0)
                    }
                }
            },
            NORTH_EST: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 1, 0)
                    }
                },
                _p(NORTH_EST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 1, 0)
                    }
                }
            },
            WEST: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 1, 0)
                    }
                },
                _p(WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 1, 0)
                    }
                }
            },
            EST: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 1, 0)
                    }
                },
                _p(EST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 1, 0)
                    }
                }
            },
            SOUTH_WEST: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 1, 0)
                    }
                },
                _p(SOUTH_WEST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 1, 0)
                    }
                }
            },
            SOUTH: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 1, 0)
                    }
                },
                _p(SOUTH): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 1, 0)
                    }
                }
            },
            SOUTH_EST: {
                _p(CENTER): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (10, 1, 0)
                    }
                },
                _p(SOUTH_EST): {
                    MOLECULES_DIRECTION: {
                        PHEROMON_DIR_EXPLO: (9, 1, 0)
                    }
                }
            }
        }

        for direction_wanted in test_data:
            self._test_direction_for_point(test_data[direction_wanted],
                                           direction_wanted)