Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
#20: goal support in Volume class
Browse files Browse the repository at this point in the history
  • Loading branch information
podusowski committed May 24, 2017
1 parent 8ae957d commit 02ffe1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions training/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def test_duration_volume(self):
self.assertEqual("1sec", str(units.Volume(seconds=1)))
self.assertEqual("1min", str(units.Volume(seconds=60)))

self.assertEqual("1min left", units.Volume(seconds=60).left_to(2))

def test_pace_convertion_from_mps_to_mpkm(self):
self.assertEqual('3:59min/km', units.mpkm_from_mps(4.17))
self.assertEqual('5:03min/km', units.mpkm_from_mps(3.3))
Expand Down
11 changes: 7 additions & 4 deletions training/units.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from copy import copy


def mpkm_from_mps(m_per_s):
try:
c = 16.666666666667
Expand Down Expand Up @@ -44,11 +47,9 @@ def __init__(self, reps:int=None, meters:int=None, seconds:int=None) -> None:
self.value = meters
elif seconds is not None:
self.type = Volume.Type.DURATION
self.multiplier = 1
self.multiplier = 60
self.value = seconds

self.distance = meters is not None

def __str__(self):
if self.type == Volume.Type.DISTANCE:
return km_from_m(self.value)
Expand Down Expand Up @@ -78,4 +79,6 @@ def number(self):
return self.value / self.multiplier

def _make_new(self, value):
return Volume(meters=value) if self.distance else Volume(reps=value)
ret = copy(self)
ret.value = value
return ret

0 comments on commit 02ffe1b

Please sign in to comment.