Exemple #1
0
 def test(self):
     for (capacity, weights, prices, answer) in [(50, [20, 50,
                                                       30], [60, 100,
                                                             120], 180.0),
                                                 (10, [30], [500], 500 / 3),
                                                 (3, [1, 2, 3], [1, 2,
                                                                 3], 3)]:
         self.assertAlmostEqual(maximum_loot_value(capacity, weights,
                                                   prices),
                                answer,
                                delta=1e-03)
     self.assertAlmostEqual(maximum_loot_value(2 * (10**6),
                                               [1 for i in range(10**3)],
                                               [1 for j in range(10**3)]),
                            1000,
                            delta=1e-03)
 def test(self):
     for (capacity, weights, prices,
          answer) in [(50, [20, 50, 30], [60, 100, 120], 180.0),
                      (10, [30], [500], 500 / 3)]:
         self.assertAlmostEqual(maximum_loot_value(capacity, weights,
                                                   prices),
                                answer,
                                delta=1e-03)
Exemple #3
0
 def test(self):
     for (capacity, weights, prices,
          answer) in [(50, [20, 50, 30], [60, 100, 120], 180.0),
                      (10, [30], [500], 500 / 3),
                      (30, [10, 30, 20], [10, 15, 40], 50),
                      (100, [20, 40, 10], [50, 5, 10], 65),
                      (5, [1, 2, 2, 3], [6, 4, 4, 3], 14),
                      (0, [30], [500], 0)]:
         self.assertAlmostEqual(maximum_loot_value(capacity, weights,
                                                   prices),
                                answer,
                                delta=1e-03)
Exemple #4
0
    def test_2(self):
        count = 1
        while True:
            n = randint(1,10)
            capacity = randint(0, 2* 10**6)
            weights = []
            prices = []
            for i in range(n):
                weights.append(randint(1, 2* 10**6))
                prices.append(randint(1, 2* 10**6))


            if len(weights) == len(prices):
                print(capacity, weights, prices)
                opt1 = maximum_loot_value(capacity, weights, prices)
                opt2 = maximum_loot_value_1(capacity, weights, prices)
                if maximum_loot_value(capacity, weights, prices) != maximum_loot_value_1(capacity, weights, prices):
                    print(opt1, opt2 )
                    print('Failed')
                    break
            count+=1
Exemple #5
0
 def test(self):
         for (capacity, weights, prices, answer) in [
             (50, [20, 50, 30], [60, 100, 120], 180.0),
             (10, [30], [500], 500 / 3),
             (10, [5, 5, 4, 7], [10, 20, 20, 21], 43),
             (100, [21, 5, 17, 4, 13, 19, 2], [1241, 3554, 3523, 8964, 87456, 135, 120], 104993)
         ]:
             self.assertAlmostEqual(
                 maximum_loot_value(capacity, weights, prices),
                 answer,
                 delta=1e-03
             )
    capacity = 12619
    prices = [
        1347, 3494, 4257, 2741, 5711, 1562, 4116, 7471, 5833, 5989, 416, 5515,
        2016, 2442, 3905, 3404, 9100, 6207, 1644, 2240, 5231, 1335, 673, 393,
        6964, 5535, 6252, 89, 8073, 7775, 2053, 2226, 3563, 693, 9315, 5007,
        1829, 9173, 8908, 2625, 5008, 7867, 7532, 7824, 435, 4403, 6028, 5586,
        5289, 5541, 2234, 4306, 2299, 8374, 4343, 7359, 8939, 6261, 7100, 8205,
        982, 6358, 3990, 570, 2200, 4519, 5251, 5209, 1239, 6045, 8871, 3897,
        3756, 143, 7592, 7106, 4762, 1218, 2520, 5230, 1403, 8540, 3841, 6265,
        908, 5881, 3717, 8574, 8037, 3239, 4442, 6518, 6564, 4138, 4041, 7052,
        2738, 1924, 3326, 6057
    ]
    weights = [
        8254, 9484, 2934, 7521, 5054, 4629, 3648, 2124, 3039, 8661, 9916, 3740,
        8876, 3138, 7136, 9804, 2398, 7744, 9785, 5399, 5351, 7907, 8511, 5524,
        9136, 5894, 118, 5494, 87, 6297, 4437, 7777, 3549, 2956, 5477, 5542,
        7290, 3291, 3019, 7229, 7430, 4829, 7996, 5708, 6681, 7195, 4428, 4293,
        7030, 857, 5725, 6936, 7497, 3161, 7268, 9172, 2888, 6389, 7087, 4136,
        147, 5791, 1100, 9317, 3256, 3074, 9226, 1652, 4033, 1004, 9477, 2245,
        1859, 8303, 3872, 9526, 1678, 5881, 5272, 7923, 6299, 9238, 2039, 7903,
        4283, 7011, 6773, 5543, 8704, 1786, 5498, 9117, 7320, 2403, 4692, 4411,
        8, 272, 5588, 8540
    ]

    if math.fabs(maximum_loot_value(12619, weights, prices) -
                 66152.572) > 1e-03:
        failed("Wrong answer for capacity={}, weights={}, prices={}".format(
            capacity, weights, prices))
    else:
        passed()