Example #1
0
 def test_bang_for_buck(self):
     item = Item(weight1=10, value=2)
     backpack = Backpack()
     backpack.add_item(item)
     constraint = FastMaxItemValue(lambda x: x.weight1, 50, "Test Rule")
     results = constraint.test(backpack)
     expect(results.bang_for_buck) == 10
Example #2
0
 def test_fit_multiple(self):
     item = Item(weight1=10)
     backpack = Backpack()
     backpack.add_item(item)
     constraint = FastMaxItemValue(lambda x: x.weight1, 50, "Test Rule")
     results = constraint.test(backpack)
     expect(results.fit_multiple) == 5
Example #3
0
    def test_fails(self):
        item = Item(weight1=25.1)
        max_value_results = MaxValueResult(
            True, {item: {
                'pass': True,
                'total': 25.1
            }}, "Test Rule")
        results = AllTestResults()
        results.update_constraint(max_value_results)

        backpack = Backpack(test_results=results)
        backpack.add_item(item)

        constraint = FastMaxItemValue(lambda x: x.weight1, 50, "Test Rule")
        new_max_value_results = constraint.test(backpack)
        expect(new_max_value_results.passes) == False
Example #4
0
 def test_passes(self):
     backpack = Backpack()
     backpack.add_item(Item(weight1=10))
     constraint = FastMaxItemValue(lambda x: x.weight1, 10, "Test Rule")
     results = constraint.test(backpack)
     expect(results.passes) == True