def test_happy_days(self, items, bin_count, ideal_distance): '''When any other input, ...''' bins = multi_way_partitioning(items, bin_count) # Fill as many bins as possible assert bins.count(frozenbag()) == max(bin_count - len(items), 0) # Relative error to ideal solution should be acceptable actual_distance = self.get_distance(self.reapply_weights(items, bins)) assert actual_distance >= (ideal_distance - 1e8), 'bug in test' assert actual_distance <= 1.3 * ideal_distance
def test_one_bin(self): '''When one bin, return single bin containing all items''' assert multi_way_partitioning([(1,2), (2,3)], bin_count=1) == bag([frozenbag([1,2])])
def test_no_items(self): '''When no items, return empty bins''' assert multi_way_partitioning([], bin_count=2) == bag([frozenbag(), frozenbag()])
def test_one_item(self): '''When one item, return 1 singleton and x empty bins''' assert multi_way_partitioning([(1,2)], bin_count=2) == bag([frozenbag([1]), frozenbag()])
def test_invalid_bin_count(self): '''When bin_count < 1, ValueError''' with pytest.raises(ValueError): multi_way_partitioning({(1,2)}, bin_count=0)