Beispiel #1
0
    def test_subtract_many_nodes(self):
        """
        Tests subtracting from many nodes weights.
        """
        subtrahend = 23
        bd = Board(30, 30)
        coords = [[15, 15], [2, 7], [9, 25]]
        weights = [20, -99, 99]

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

        bd.modifyWeights('-', coords, subtrahend)

        for coord, weight in zip(coords, weights):
            desiredWeight = weight - subtrahend
            if desiredWeight > 100:
                desiredWeight = 100
            elif desiredWeight < 0:
                desiredWeight = 0
            self.assertEqual(bd.getWeight(coord), desiredWeight)
Beispiel #2
0
    def test_divide_many_weights(self):
        """
        Tests dividing many nodes weights using an odd divisor.
        """
        divisor = 3
        bd = Board(30, 30)
        coords = [[15, 15], [2, 7], [9, 25]]
        weights = [21, -99, 99]

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

        bd.modifyWeights('/', coords, divisor)

        for coord, weight in zip(coords, weights):
            desiredWeight = weight // divisor
            if desiredWeight > 100:
                desiredWeight = 100
            elif desiredWeight < 0:
                desiredWeight = 0
            self.assertAlmostEqual(bd.getWeight(coord), desiredWeight, places=4)
Beispiel #3
0
    def test_add_many_nodes(self):
        """
        Tests adding to many nodes weights.
        """
        addend = 35
        bd = Board(30, 30)
        coords = [[15, 15], [2, 7], [9, 25]]
        weights = [20, -99, 99]

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

        bd.modifyWeights('+', coords, addend)

        for coord, weight in zip(coords, weights):
            desiredWeight = weight + addend
            if desiredWeight > 100:
                desiredWeight = 100
            elif desiredWeight < 0:
                desiredWeight = addend
            self.assertEqual(bd.getWeight(coord), desiredWeight)
Beispiel #4
0
    def test_multiply_many_nodes(self):
        """
        Tests multiplying many nodes weights.
        """
        multiplier = 2
        bd = Board(30, 30)
        coords = [[15, 15], [2, 7], [9, 25]]
        weights = [20, -99, 99]

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

        bd.modifyWeights('*', coords, multiplier)

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