Skip to content

Commit

Permalink
Added failing tests with expectations from rcrunch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Keane committed Jun 19, 2018
1 parent 2c2f811 commit 743629f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/cr/cube/measures/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def data(self):
'''Return table index by margin.'''
if self.cube.has_mr:
return self._mr_index()
# this margin should be calculated from the univariate cube of the row variable.
margin = (
self.cube.margin(axis=0, weighted=self.weighted, prune=self.prune) /
self.cube.margin(weighted=self.weighted, prune=self.prune)
Expand Down
22 changes: 11 additions & 11 deletions tests/integration/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ class TestIndex(TestCase):
def test_mr_x_cat_index(self):
cube = CrunchCube(SELECTED_CROSSTAB_4)
expected = np.array([
[0.95865152585539, 1.0385904443566],
[1.02305106635277, 0.9784320457270],
[0.97603114632311, 1.0224274029149],
[0.98102944430498, 1.0182906820384],
[1.14466510106092, 0.8606566846476],
[0.99292572005336, 1.0068293374540]
[0.958651525855387,1.03859044435659],
[1.02305106635277,0.978432045727022],
[0.976031146323114,1.0224274029149],
[0.981029444304978,1.01829068203842],
[1.14466510106092,0.860656684647625],
[0.992925720053358,1.00682933745397]
])
actual = cube.index()
np.testing.assert_almost_equal(actual, expected)

def test_cat_x_mr_index(self):
cube = CrunchCube(CAT_X_MR_SIMPLE)
expected = np.array([
[0.8571429, 1.1152941, 0.9610984],
[1.0769231, 0.9466231, 1.019037],
[0.909090909090909,1.06951871657754,0.956937799043062],
[1.04477611940298,0.9657594381036,1.02120974076984]
])
actual = cube.index()
np.testing.assert_almost_equal(actual, expected)

def test_mr_x_mr_index(self):
cube = CrunchCube(PETS_X_PETS)
expected = np.array([
[1.0000000000000000, 1.1724137931034484, 0.894736842105263],
[0.8529411764705883, 1.0000000000000000, 0.763157894736842],
[1.1176470588235294, 1.310344827586207, 1.0000000000000000]
[2,0.96551724137931,0.947368421052632],
[0.956747404844291,2.32352941176471,0.978328173374613],
[0.975232198142415,1.01633393829401,1.84210526315789]
])
actual = cube.index()
np.testing.assert_almost_equal(actual, expected)
Expand Down

0 comments on commit 743629f

Please sign in to comment.