def test_bound_weights_with_only_one_bound(self): weights = [(0, 0), (2, 2), (4, 2), (6, 0)] # With only minimum self.assertEqual(rand.bound_weights(weights, minimum=1), [(1, 1), (2, 2), (4, 2), (6, 0)]) # With only maximum self.assertEqual(rand.bound_weights(weights, maximum=5), [(0, 0), (2, 2), (4, 2), (5, 1)])
def test_bound_weights_clipping_between_existing_weights(self): weights = [(0, 0), (2, 2), (4, 2), (6, 0)] self.assertEqual(rand.bound_weights(weights, 1, 5), [(1, 1), (2, 2), (4, 2), (5, 1)])
def test_bound_weights_clipping_on_existing_weights(self): weights = [(0, 0), (2, 2), (4, 2), (6, 0)] self.assertEqual(rand.bound_weights(weights, 2, 4), [(2, 2), (4, 2)])
def test_bound_weights_with_weights_already_inside_bounds(self): # When all weights are already inside bounds, # rand.bound_weights() should have no effect weights = [(0, 0), (2, 2), (4, 2), (6, 0)] modified = rand.bound_weights(weights, -2, 8) self.assertEqual(weights, modified)
def test_bound_weights_doesnt_modify_input(self): weights = [(0, 0), (2, 2), (4, 2), (6, 0)] original_weights = weights[:] modified = rand.bound_weights(weights, 2, 4) self.assertEqual(weights, original_weights)
def test_bound_weights_without_bounds_raises_TypeError(self): weights = [(0, 0), (2, 2), (4, 2), (6, 0)] with self.assertRaises(TypeError): rand.bound_weights(weights)
def test_bound_weights_with_bad_bounds_raises_ValueError(self): weights = [(0, 0), (2, 2), (4, 2), (6, 0)] with self.assertRaises(ValueError): rand.bound_weights(weights, 10, 5)
def test_bound_weights_without_bounds_returns_unmodified(self): weights = [(0, 0), (2, 2), (4, 2), (6, 0)] self.assertEqual(weights, rand.bound_weights(weights))
def test_bound_weights_doesnt_modify_input(self): weights = [(0, 0), (2, 2), (4, 2), (6, 0)] original_weights = weights[:] rand.bound_weights(weights, 2, 4) self.assertEqual(weights, original_weights)