test with different units and bars

This commit is contained in:
James Turk 2015-04-12 23:59:21 -04:00
parent 647531f96c
commit f9ff40312b
2 changed files with 31 additions and 1 deletions

View File

@ -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)

View File

@ -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')