def test(self): while True: capacity = randint(0, OptimalWeightSimplfiedStressTestCase.CAPACITY) weights = [] for i in range(0, OptimalWeightSimplfiedStressTestCase.N): weights.append(randint(0, OptimalWeightSimplfiedStressTestCase.WEIGHT)) value = optimal_weight_simplified(capacity, weights) print('capacity: %s' % capacity) print('weights: %s' % weights) print('value: %s' % value) print() self.assertTrue(capacity >= value)
def test_with_capacity_as_10_and_bars_as_1_4_8(self): capacity = 10 weights = [1, 4, 8] value = optimal_weight_simplified(capacity, weights) self.assertEqual(9, value) self.assertTrue(capacity >= value)
def test_with_capacity_as_14_and_several_weights(self): capacity = 14 weights = [2, 4, 3, 6] value = optimal_weight_simplified(capacity, weights) self.assertEqual(13, value) self.assertTrue(capacity >= value)
def test_with_capacity_as_10_and_several_weights_with_duplicates(self): capacity = 10 weights = [2, 4, 3, 6, 2, 4, 3, 6] value = optimal_weight_simplified(capacity, weights) self.assertEqual(10, value) self.assertTrue(capacity >= value)
def test_with_capacity_as_2_and_weights_as_1_and_2(self): capacity = 2 weights = [1, 2] value = optimal_weight_simplified(capacity, weights) self.assertEqual(2, value) self.assertTrue(capacity >= value)
def test_with_capacity_as_1_and_weights_as_2_and_3(self): capacity = 1 weights = [2, 3] value = optimal_weight_simplified(capacity, weights) self.assertEqual(0, value) self.assertTrue(capacity >= value)
def test_with_capacity_as_1_and_duplicate_weights(self): capacity = 1 weights = [1, 1] value = optimal_weight_simplified(capacity, weights) self.assertEqual(1, value) self.assertTrue(capacity >= value)
def test_with_non_zero_capacity_and_empty_weights(self): capacity = 123 weights = [] value = optimal_weight_simplified(capacity, weights) self.assertEqual(0, value) self.assertTrue(capacity >= value)
def test_with_zero_capacity(self): capacity = 0 weights = [] value = optimal_weight_simplified(capacity, weights) self.assertEqual(0, value) self.assertTrue(capacity >= value)
def test_with_preceeding_lower_bound_of_weights(self): with self.assertRaisesRegex(AssertionError, ''): capacity = 1 weights = [1, -1, 2] optimal_weight_simplified(capacity, weights)