def test_drs_upper_and_lower_constraints(constraint_gen, insert_fixed_point): """Test DRS with both upper and lower constraints. Checks no constraint is broken, and that the returned values sum to within drs.EPSILON of 1""" for n in NTASKS_LIST: x = 0 while x < REPEATS: upper_bounds = constraint_gen(n, UPPER_CONSTRAINT_TOTAL) lower_bounds = constraint_gen(n, LOWER_CONSTRAINT_TOTAL) if all(l < u for l, u in zip(lower_bounds, upper_bounds)): util = 1 i = 0 if insert_fixed_point: position = random.randint(0, n-1) fixed_point = random.random() assert isinstance(lower_bounds, list) assert isinstance(upper_bounds, list) lower_bounds.insert(position, fixed_point) upper_bounds.insert(position, fixed_point) util += fixed_point i = 1 assert sum(lower_bounds) <= util result = drs.drs(n+i, util, upper_bounds, lower_bounds) if insert_fixed_point: assert isinstance(result, list) fixed_point_returned = result.pop(position) assert fixed_point_returned == fixed_point upper_bounds.pop(position) lower_bounds.pop(position) assert len(upper_bounds) == len(result) assert all([x < y for x, y in list(zip(result, upper_bounds))]) assert all(x > y for x, y in zip(result, lower_bounds)) assert abs(1 - sum(result)) < drs.EPSILON x += 1
def test_drs_fixed_point(constraint_gen): """Test to see that DRS works with constraints where only a single point is valid""" for n in NTASKS_LIST: for _ in range(REPEATS): constraints = constraint_gen(n, 1) result = drs.drs(n, sum(constraints), constraints, constraints) assert result == constraints
def test_drs_no_constraints(): """Test DRS with no constraints. Checks to see that the returned values sum to within drs.EPSILON of 1""" for n in NTASKS_LIST: for _ in range(REPEATS): result = drs.drs(n, 1) assert abs(1 - sum(result)) < drs.EPSILON assert all(x > 0 for x in result) assert all(x < 1 for x in result)
def test_drs_upper_constraints(constraint_gen): """Test DRS with upper constraints. Checks no upper constraint is broken, and that the returned values sum to within drs.EPSILON of 1""" for n in NTASKS_LIST: for _ in range(REPEATS): upper_bounds = constraint_gen(n, UPPER_CONSTRAINT_TOTAL) result = drs.drs(n, 1, upper_bounds) assert all(x < y for x, y in zip(result, upper_bounds)) assert abs(1 - sum(result)) < drs.EPSILON assert all(x > 0 for x in result)
def test_drs_lower_bounds(constraint_gen): """Test DRS with lower bounds. Checks no lower bound is broken, and that the returned values sum to within drs.EPSILON of 1""" for n in NTASKS_LIST: for _ in range(REPEATS): lower_bounds = constraint_gen(n, LOWER_CONSTRAINT_TOTAL) util = 1.0 result = drs.drs(n, util, lower_bounds=lower_bounds) assert all(x > y for x, y in zip(result, lower_bounds)) assert abs(1 - sum(result)) < drs.EPSILON assert all(x < 1 for x in result)