Beispiel #1
0
    def test_weightloss(self, mocker):
        """Tests that the weight is updated according to the weightloss method.

        The mocker is used to give spesific values from random functions used
        in the module.
        """
        mocker.patch("numpy.random.normal", return_value=1)
        h = Herb()
        h.weightloss()
        assert h.weight == 1 - h.eta * 1
        h.weight = 100000
        c = Carn()
        c.weight = 100000
        weight_list_herb = []
        weight_list_carn = []
        for _ in range(100):
            weight_list_herb.append(h.weight)
            weight_list_carn.append(c.weight)
            h.weightloss()
            c.weightloss()
        assert all([
            weight1 > weight2 for weight1, weight2 in zip(
                weight_list_herb[:-1], weight_list_herb[1:])
        ]), "The weight does not decrease in the list when weightloss is used"
        assert all([
            weight1 > weight2 for weight1, weight2 in zip(
                weight_list_carn[:-1], weight_list_carn[1:])
        ]), "The weight does not decrease in the list when weightloss is used"
Beispiel #2
0
 def test_weightloss(self, mocker):
     mocker.patch('numpy.random.normal', return_value=1)
     h = Herb()
     h.weightloss()
     assert h.weight == 1 - h.eta * 1
     h.weight = 100000
     c = Carn()
     c.weight = 100000
     weight_list_herb = []
     weight_list_carn = []
     for _ in range(100):
         weight_list_herb.append(h.weight)
         weight_list_carn.append(c.weight)
         h.weightloss()
         c.weightloss()
     assert all([
         weight1 > weight2 for weight1, weight2 in zip(
             weight_list_herb[:-1], weight_list_herb[1:])
     ])
     assert all([
         weight1 > weight2 for weight1, weight2 in zip(
             weight_list_carn[:-1], weight_list_carn[1:])
     ])