Skip to content

Commit

Permalink
change some tests to use Fraction
Browse files Browse the repository at this point in the history
  • Loading branch information
HighDiceRoller committed Oct 15, 2023
1 parent 04297cd commit 6bfa9ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
16 changes: 8 additions & 8 deletions tests/comparator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def test_lt():


def test_lt_fixed():
assert (icepool.d6 < 1).mean() == 0.0
assert (icepool.d6 < 7).mean() == 1.0
assert (icepool.d6 < 1).mean() == 0
assert (icepool.d6 < 7).mean() == 1


def test_lt_len():
Expand All @@ -27,8 +27,8 @@ def test_gt():


def test_gt_fixed():
assert (icepool.d6 > 0).mean() == 1.0
assert (icepool.d6 > 6).mean() == 0.0
assert (icepool.d6 > 0).mean() == 1
assert (icepool.d6 > 6).mean() == 0


def test_gt_len():
Expand All @@ -43,8 +43,8 @@ def test_leq():


def test_leq_fixed():
assert (icepool.d6 <= 0).mean() == 0.0
assert (icepool.d6 <= 6).mean() == 1.0
assert (icepool.d6 <= 0).mean() == 0
assert (icepool.d6 <= 6).mean() == 1


def test_leq_len():
Expand All @@ -59,8 +59,8 @@ def test_geq():


def test_geq_fixed():
assert (icepool.d6 >= 1).mean() == 1.0
assert (icepool.d6 >= 7).mean() == 0.0
assert (icepool.d6 >= 1).mean() == 1
assert (icepool.d6 >= 7).mean() == 0


def test_geq_len():
Expand Down
11 changes: 5 additions & 6 deletions tests/logical_test.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import icepool
import pytest

from fractions import Fraction


def test_invert():
assert (~icepool.coin(1, 4)).mean() < 0


def test_and():
assert (icepool.coin(1, 4) & icepool.coin(1, 4)).mean() == pytest.approx(1 /
16)
assert (icepool.coin(1, 4) & icepool.coin(1, 4)).mean() == Fraction(1, 16)


def test_or():
assert (icepool.coin(1, 4) | icepool.coin(1, 4)).mean() == pytest.approx(7 /
16)
assert (icepool.coin(1, 4) | icepool.coin(1, 4)).mean() == Fraction(7, 16)


def test_xor():
print(icepool.coin(1, 4) ^ icepool.coin(1, 4))
print((icepool.coin(1, 4) ^ icepool.coin(1, 4)).probability(1))
assert (icepool.coin(1, 4) ^ icepool.coin(1, 4)).mean() == pytest.approx(6 /
16)
assert (icepool.coin(1, 4) ^ icepool.coin(1, 4)).mean() == Fraction(6, 16)


def test_ifelse():
Expand Down
8 changes: 5 additions & 3 deletions tests/statistics_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import icepool
import pytest

from fractions import Fraction


def test_d6_mean():
assert icepool.d6.mean() == 3.5
Expand All @@ -11,12 +13,12 @@ def test_d8_variance():


def test_kolmogorov_smirnov_standard_dice():
assert icepool.d10.kolmogorov_smirnov(icepool.d20) == pytest.approx(0.5)
assert icepool.d10.kolmogorov_smirnov(icepool.d20) == Fraction(1, 2)


def test_kolmogorov_smirnov_flat_number():
assert icepool.Die([10]).kolmogorov_smirnov(icepool.Die([10])) == 0.0
assert icepool.Die([10]).kolmogorov_smirnov(icepool.Die([9])) == 1.0
assert icepool.Die([10]).kolmogorov_smirnov(icepool.Die([10])) == 0
assert icepool.Die([10]).kolmogorov_smirnov(icepool.Die([9])) == 1


def test_d6_median():
Expand Down

0 comments on commit 6bfa9ed

Please sign in to comment.