예제 #1
0
 def test_3(self):
     purity = 10
     values = [120, 100, 90, 80, 70, 60, 50]
     random.shuffle(values)  # the order should not matter
     max_weight = 11
     bank = SameGoldBank()
     bank.setup(purity=purity, values=values)
     values_solution = [60, 50]
     weights_solution = [6, 5]
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight, knapsack_alg=method)
     self.assertCountEqual(zip(values_robbed, weights_robbed),
                           zip(values_solution, weights_solution))
예제 #2
0
 def test_3(self):
     purity = 10
     values = [120, 100, 90, 80, 70, 60, 50]
     random.shuffle(values)  # the order should not matter
     max_weight = 11
     bank = SameGoldBank()
     bank.setup(purity=purity, values=values)
     values_solution = [60, 50]
     weights_solution = [6, 5]
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight,
                                              knapsack_alg=method)
     self.assertCountEqual(zip(values_robbed, weights_robbed),
                           zip(values_solution, weights_solution))
예제 #3
0
 def test_7(self):
     purity = 10
     values = [120, 100, 90, 80, 70, 60, 50]
     random.shuffle(values)  # the order should not matter
     max_weight = 19
     bank = SameGoldBank()
     bank.setup(purity=purity, values=values)
     values_solution = [100, 40, 50]
     weights_solution = [10, 4, 5]
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight, knapsack_alg=method)
     try:
         self.assertCountEqual(zip(values_robbed, weights_robbed),
                               zip(values_solution, weights_solution))
     except AssertionError:
         # this assertion is because the optimal solution may not be unique, let's check at least optimality
         self.assertEqual(sum(weights_solution), sum(weights_robbed))
예제 #4
0
 def test_7(self):
     purity = 10
     values = [120, 100, 90, 80, 70, 60, 50]
     random.shuffle(values)  # the order should not matter
     max_weight = 19
     bank = SameGoldBank()
     bank.setup(purity=purity, values=values)
     values_solution = [100, 40, 50]
     weights_solution = [10, 4, 5]
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight,
                                              knapsack_alg=method)
     try:
         self.assertCountEqual(zip(values_robbed, weights_robbed),
                               zip(values_solution, weights_solution))
     except AssertionError:
         # this assertion is because the optimal solution may not be unique, let's check at least optimality
         self.assertEqual(sum(weights_solution), sum(weights_robbed))