示例#1
0
 def test_out_of_bounds(self):
     """Test if method raises ValueError when initialized with the wrong value"""
     bounds = ([1, 1, 1], [5, 5, 5])
     init_pos = np.array([[-2, 3, 3], [6, 8, 1]])
     with pytest.raises(ValueError):
         P.generate_swarm(
             n_particles=2, dimensions=3, bounds=bounds, init_pos=init_pos
         )
示例#2
0
 def test_return_values(self, bounds, center):
     """Test if method returns expected values"""
     pos = P.generate_swarm(
         n_particles=2, dimensions=3, bounds=bounds, center=center
     )
     if bounds is None:
         min_bounds, max_bounds = (0.1, 2.00)
     else:
         min_bounds, max_bounds = bounds
     lower_bound = center * np.array(min_bounds)
     upper_bound = center * np.array(max_bounds)
     assert (pos <= upper_bound).all() and (pos >= lower_bound).all()
示例#3
0
def test_generate_swarm_bounds_init_pos(bounds, init_pos):
    """Tests if generate_swarm() returns expected values given init_pos and bounds"""
    pos = P.generate_swarm(n_particles=2,
                           dimensions=3,
                           bounds=bounds,
                           init_pos=init_pos)
    if (bounds is None) and (init_pos is None):
        min_bounds, max_bounds = (0.0, 1.00)
    elif (bounds is None) and (init_pos is not None):
        min_bounds, max_bounds = (-np.inf, np.inf)
    else:
        min_bounds, max_bounds = bounds
    lower_bound = np.array(min_bounds)
    upper_bound = np.array(max_bounds)
    assert (pos <= upper_bound).all() and (pos >= lower_bound).all()
示例#4
0
 def test_bounds_wrong_size(self, bounds):
     """Test if method raises ValueError when bounds is of wrong shape"""
     with pytest.raises(ValueError):
         P.generate_swarm(n_particles=2, dimensions=3, bounds=bounds)
示例#5
0
 def test_bounds_wrong_type(self, bounds):
     """Test if method raises TypeError when bounds is not an array"""
     with pytest.raises(TypeError):
         P.generate_swarm(n_particles=2, dimensions=3, bounds=bounds)