test with different units and bars
This commit is contained in:
parent
647531f96c
commit
f9ff40312b
@ -25,7 +25,12 @@ class LiftingOptions(models.Model):
|
|||||||
|
|
||||||
def plates_for_weight(self, weight):
|
def plates_for_weight(self, weight):
|
||||||
side = []
|
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)
|
available = sorted(self.plate_pairs, reverse=True)
|
||||||
while w and available:
|
while w and available:
|
||||||
plate = available.pop(0)
|
plate = available.pop(0)
|
||||||
|
@ -16,16 +16,41 @@ class TestLiftingOptions(TestCase):
|
|||||||
opts = self.user.lifting_options
|
opts = self.user.lifting_options
|
||||||
opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
|
opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
|
||||||
opts.default_bar_id = 1
|
opts.default_bar_id = 1
|
||||||
|
opts.lifting_units = 'i'
|
||||||
|
|
||||||
assert opts.plates_for_weight(45) == []
|
assert opts.plates_for_weight(45) == []
|
||||||
assert opts.plates_for_weight(50) == [D('2.5')]
|
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(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')]
|
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):
|
def test_plates_for_weight_error(self):
|
||||||
opts = self.user.lifting_options
|
opts = self.user.lifting_options
|
||||||
opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
|
opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
|
||||||
opts.default_bar_id = 1
|
opts.default_bar_id = 1
|
||||||
|
opts.lifting_units = 'i'
|
||||||
|
|
||||||
# TODO: check amounts
|
# TODO: check amounts
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
opts.plates_for_weight('47.5')
|
opts.plates_for_weight('47.5')
|
||||||
|
Loading…
Reference in New Issue
Block a user