Ejemplo n.º 1
0
 def test_returns_correct_values(self):
     """Test it returns the correct values. """
     weights_in = np.array([6.0, 3.0, 1.0])
     result = WeightsUtilities.normalise_weights(weights_in)
     expected_result = np.array([0.6, 0.3, 0.1])
     self.assertArrayAlmostEqual(result, expected_result)
Ejemplo n.º 2
0
 def test_fails_sum_equals_zero(self):
     """Test it fails if sum of input weights is zero. """
     weights_in = np.array([0.0, 0.0, 0.0])
     msg = ('Sum of weights must be > 0.0')
     with self.assertRaisesRegexp(ValueError, msg):
         WeightsUtilities.normalise_weights(weights_in)
Ejemplo n.º 3
0
 def test_array_sum_equals_one(self):
     """Test that the resulting weights add up to one. """
     weights_in = np.array([1.0, 2.0, 3.0])
     result = WeightsUtilities.normalise_weights(weights_in)
     self.assertAlmostEquals(result.sum(), 1.0)
Ejemplo n.º 4
0
 def test_fails_weight_less_than_zero(self):
     """Test it fails if weight less than zero. """
     weights_in = np.array([-1.0, 0.1])
     msg = ('Weights must be positive')
     with self.assertRaisesRegexp(ValueError, msg):
         WeightsUtilities.normalise_weights(weights_in)
Ejemplo n.º 5
0
 def test_basic(self):
     """Test that the function returns an array of weights. """
     weights_in = np.array([1.0, 2.0, 3.0])
     result = WeightsUtilities.normalise_weights(weights_in)
     self.assertIsInstance(result, np.ndarray)