コード例 #1
0
    def test_AllPassiveMonsters_WithRando(self):
        wimpy = WimpyHypothesis()
        rando = RandoHypothesis()
        self.setUpDecisioner(wimpy, rando)

        # First we will start with the basic training case
        # which is the first 100 in the range
        for i in range(101):
            monster = Monster(0, [randint(1, 100)], 'passive')

            # Get the guess from the decisioner for the first 100,
            # we expect every guess to be 1
            self.assertTrue(self.decisioner.get_guess(monster.color))

            # Then we will update from this guess
            self.decisioner.update(monster.color, 1, monster.action(True))

        for i in range(5000):
            monster = Monster(0, [randint(1, 100)], 'aggressive')

            self.decisioner.get_guess(monster.color)

            # Then we will update from this guess
            self.decisioner.update(monster.color, 1, 1)

            # Flipping a coin is better than doing nothing
            self.assertGreater(rando.fitness(), wimpy.fitness())

        # Randomness should be near-even in distribution
        self.assertGreater(rando.fitness(), 0.4)
        self.assertGreater(0.6, rando.fitness())
コード例 #2
0
class KNearestNeighborsTest(unittest.TestCase):
    def setUp(self):
        self._hypothesis = RandoHypothesis()

    def tearDown(self):
        self._hypothesis = None

    def test_initGuess(self):
        """Test the Rando algorithm returns a value"""
        isTautological = self._hypothesis.get_guess([1])
        self.assertTrue(isTautological or not isTautological)

    def test_fitnessInAggroEnviron(self):
        """RandoHypothesis: Test fitness after a thousand flips in Aggro Environment"""
        self.assertTrue(self._hypothesis.fitness() == 0)
        for i in range(1000):
            self._hypothesis.update([100], 1, 1)
        self.assertTrue(self._hypothesis.fitness() > 0.4)
        self.assertTrue(self._hypothesis.fitness() < 0.6)
        print('RandoHypothesis Fitness: ' + str(self._hypothesis.fitness()) +
              ' ... ')
コード例 #3
0
class KNearestNeighborsTest(unittest.TestCase):

    def setUp(self):
        self._hypothesis = RandoHypothesis()

    def tearDown(self):
        self._hypothesis = None

    def test_initGuess(self):
        """Test the Rando algorithm returns a value"""
        isTautological = self._hypothesis.get_guess([1]) 
        self.assertTrue(isTautological or not isTautological)

    def test_fitnessInAggroEnviron(self):
        """RandoHypothesis: Test fitness after a thousand flips in Aggro Environment"""
        self.assertTrue(self._hypothesis.fitness()==0)
        for i in range(1000):
            self._hypothesis.update([100], 1, 1)
        self.assertTrue(self._hypothesis.fitness()>0.4)
        self.assertTrue(self._hypothesis.fitness()<0.6)
        print ('RandoHypothesis Fitness: ' + str(self._hypothesis.fitness()) + ' ... ')