From f9ff40312b377e24a2f8347090d56c73d189bdd3 Mon Sep 17 00:00:00 2001 From: James Turk Date: Sun, 12 Apr 2015 23:59:21 -0400 Subject: [PATCH] test with different units and bars --- lifting/models.py | 7 ++++++- lifting/tests.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lifting/models.py b/lifting/models.py index 207bbf7..21014ad 100644 --- a/lifting/models.py +++ b/lifting/models.py @@ -25,7 +25,12 @@ class LiftingOptions(models.Model): def plates_for_weight(self, weight): side = [] - w = initial_weight = Decimal(weight) - self.default_bar.weight_lb + w = Decimal(weight) + if self.lifting_units == 'i': + w -= self.default_bar.weight_lb + else: + w -= self.default_bar.weight_kg + initial_weight = w available = sorted(self.plate_pairs, reverse=True) while w and available: plate = available.pop(0) diff --git a/lifting/tests.py b/lifting/tests.py index 8844942..cacb5d3 100644 --- a/lifting/tests.py +++ b/lifting/tests.py @@ -16,16 +16,41 @@ class TestLiftingOptions(TestCase): opts = self.user.lifting_options opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')] opts.default_bar_id = 1 + opts.lifting_units = 'i' assert opts.plates_for_weight(45) == [] assert opts.plates_for_weight(50) == [D('2.5')] assert opts.plates_for_weight(90) == [D(10), D(5), D(5), D('2.5')] assert opts.plates_for_weight(320) == [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')] + def test_plates_for_weight_womens_bar(self): + opts = self.user.lifting_options + opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')] + opts.default_bar_id = 2 + opts.lifting_units = 'i' + + assert opts.plates_for_weight(35) == [] + assert opts.plates_for_weight(40) == [D('2.5')] + assert opts.plates_for_weight(80) == [D(10), D(5), D(5), D('2.5')] + assert opts.plates_for_weight(310) == [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')] + + def test_plates_for_weight_kg(self): + opts = self.user.lifting_options + opts.plate_pairs = [D(20), D(20), D(10), D(5), D('2.5')] + opts.default_bar_id = 1 + opts.lifting_units = 'm' + + assert opts.plates_for_weight(20) == [] + assert opts.plates_for_weight(25) == [D('2.5')] + assert opts.plates_for_weight(55) == [D(10), D(5), D('2.5')] + assert opts.plates_for_weight(135) == [D(20), D(20), D(10), D(5), D('2.5')] + def test_plates_for_weight_error(self): opts = self.user.lifting_options opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')] opts.default_bar_id = 1 + opts.lifting_units = 'i' + # TODO: check amounts with self.assertRaises(ValueError): opts.plates_for_weight('47.5')