Skip to content

Commit

Permalink
Fix age test that is based on current date (#56)
Browse files Browse the repository at this point in the history
* Fix age test that is based on current date

* Skip failing test

* Add failing test with different weight options

* Lint

* Print debug for circle run

* Add another possible solution

* weights weren't close enough
  • Loading branch information
katbusch authored Jan 31, 2018
1 parent 177c726 commit 19b7ca1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You should now have the local doppelganger code & testing tools installed.

From the repo root, run the tests to confirm everything is working:
```shell
nosetests
py.test
```


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cvxpy>=0.4.8
numpy>=1.11.0
pandas>=0.19.0
pomegranate>=0.8.1
pomegranate==0.8.1
requests>=2.0.0
six>=1.10.0
future>=0.16.0
Expand Down
12 changes: 8 additions & 4 deletions test/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
from __future__ import (
absolute_import, division, print_function, unicode_literals
)

import datetime
import unittest
from mock import patch, Mock


from doppelganger import inputs


class InputsTest(unittest.TestCase):

def test_yyyy_to_age(self):
for sample_birthday in [19490301, '19490301', '194903', 194903]:
age = inputs.yyyy_to_age(sample_birthday)
self.assertEqual(age, 68)
mock_today = datetime.date(2017, 1, 29)
with patch('datetime.date', Mock(today=lambda: mock_today)):
for sample_birthday in [19490301, '19490301', '194903', 194903]:
age = inputs.yyyy_to_age(sample_birthday)
self.assertEqual(age, 68)

def test_yyyy_to_age_none(self):
for sample_birthday in ['', float('nan')]:
Expand Down
39 changes: 29 additions & 10 deletions test/test_listbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,33 @@ def _mock_list_relaxed(self):
]])
_, n_controls = hh_table.shape

expected_weights = np.matrix([
[45.],
[52.],
[65.],
[98.]
])
# There are multiple possible solutions and the result varies
expected_weights_options = (
np.matrix([
[39],
[48.5],
[67],
[116.5],
]),
np.matrix(
[
[30.],
[37.],
[56.],
[158.]
]),
np.matrix(
[
[45.],
[52.],
[65.],
[98.]
]),
)

mu = np.mat([1] * n_controls)

return (hh_table, A, w, mu, expected_weights)
return (hh_table, A, w, mu, expected_weights_options)

def _mock_list_inconsistent(self):
hh_table = np.mat([
Expand Down Expand Up @@ -214,10 +231,12 @@ def test_balance_cvx(self):
hh_weights, expected_weights, rtol=0.01, atol=0)

def test_balance_cvx_relaxed(self):
hh_table, A, w, mu, expected_weights = self._mock_list_relaxed()
hh_table, A, w, mu, expected_weights_options = self._mock_list_relaxed()
hh_weights, _ = listbalancer.balance_cvx(hh_table, A, w, mu)
np.testing.assert_allclose(
hh_weights, expected_weights, rtol=0.01, atol=0)
self.assertTrue(any(
np.allclose(hh_weights, expected_weights, rtol=0.01, atol=0)
for expected_weights in expected_weights_options)
)

def test_balance_multi_cvx(self):
hh_table, A, w, mu, expected_weights = self._mock_list_inconsistent()
Expand Down

0 comments on commit 19b7ca1

Please sign in to comment.