Beispiel #1
0
    def test_multiply_weight_float(self):
        """
        Tests multiplying node weight.
        """
        fraction = 0.5
        bd = Board(30, 30)
        coords = [[15, 15], [2, 7], [9, 25]]
        weights = [20, 2, 100]

        for coord, weight in zip(coords, weights):
            bd.setWeight(coord, weight)
            bd.multiplyWeight(coord, fraction)
            self.assertEqual(bd.getWeight(coord), weight * fraction)
Beispiel #2
0
    def test_multiply_weight_int(self):
        """
        Tests multiplying node weight.
        """
        multiplier = 5
        bd = Board(30, 30)
        coords = [[15, 15], [2, 7], [9, 25]]
        weights = [6, 14, 90]

        for coord, weight in zip(coords, weights):
            bd.setWeight(coord, weight)
            bd.multiplyWeight(coord, multiplier)

        for coord, weight in zip(coords, weights):
            desiredWeight = weight * multiplier
            if desiredWeight < -100:
                desiredWeight = -100
            elif desiredWeight > 100:
                desiredWeight = 100
            self.assertEqual(bd.getWeight(coord), desiredWeight)