Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix age test that is based on current date #56

Merged
merged 7 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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