Skip to content

Commit

Permalink
chore(test): use unittest assertions in test_metrics.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto authored and Liam James committed Dec 14, 2023
1 parent a7f2235 commit ed273ea
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions test/core/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ def setUp(self) -> None:
self.fair_dataset = uniform_binary_dataset(rows=DATASET_SIZE)
self.unfair_dataset = skewed_binary_dataset(rows=DATASET_SIZE, p=0.9)

def assertInRange(self, value, lower, upper):
self.assertGreaterEqual(value, lower)
self.assertLessEqual(value, upper)

def test_parity_on_fair_binary_case(self):
x = self.fair_dataset[:, 0]
y = self.fair_dataset[:, 1]
parities = discrete_demographic_parities(x, y, 1)
assert parities.shape == (1,)
assert 0.0 < parities[0] <= 0.005
self.assertEqual(parities.shape, (1,))
self.assertInRange(parities[0], 0.0, 0.005)

def test_parity_on_unfair_binary_case(self):
x = self.unfair_dataset[:, 0]
y = self.unfair_dataset[:, 1]
parities = discrete_demographic_parities(x, y, 1)
assert 0.4 < parities[0] <= 0.5
self.assertEqual(parities.shape, (1,))
self.assertInRange(parities[0], 0.4, 0.5)


if __name__ == '__main__':
Expand Down

0 comments on commit ed273ea

Please sign in to comment.