Skip to content

Commit

Permalink
add std() test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jeewon-hwang committed Mar 23, 2016
1 parent a1f0932 commit 36818db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions TimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ def mean(self):
-------
float
the mean of self.values
Raises
------
ValueError
If self.values is empty
"""
if(len(self._values) == 0):
raise ValueError("cant calculate mean of length 0 list")
Expand All @@ -294,6 +299,24 @@ def median(self):
if(len(self._values) == 0):
raise ValueError("cant calculate median of length 0 list")
return np.median(self._values)

def std(self):
'''
Returns the standard-deviation of self.values
Returns
-------
float
the standard deviation of self.values
Raises
------
ValueError
If self.values is empty
'''
if(len(self._values) == 0):
raise ValueError("cant calculate median of length 0 list")
return np.std(self._values)

def interpolate(self, times):
'''
Expand Down
7 changes: 7 additions & 0 deletions test_TimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ def test_median_empty():
with raises(ValueError):
TS.TimeSeries([],[]).median()

def test_std_empty():
with raises(ValueError):
TS.TimeSeries([],[]).std()

def test_mean():
assert testSeries.mean() == 2.5

def test_median():
assert testSeries.median() == 2.5

def test_std():
assert testSeries.std() == 1.1180339887498949

def test_itertimes():
ti=testSeries.itertimes()
assert next(ti)==0
Expand Down

0 comments on commit 36818db

Please sign in to comment.