def test_invert(n): """ Test the inversion of a Surreal. """ assert Surreal.from_value(n)._invert() == Surreal.from_value(1 / n)
def test_surreal_fail(): """ Test that Surreal doesn't try to construct things like 1/3. """ with pytest.raises(ValueError): Surreal.from_value(1 / 3)
def test_div(a, b): """ Test the division of two Surreals. """ assert Surreal.from_value(a) / Surreal.from_value(b) == Surreal.from_value(a / b)
def test_div_game(a, b): """ Test the division of a Surreal by a Game. """ assert Surreal.from_value(a) / Game(b) == Game(a / b)
def test_mul_game_2(a, b): """ Test the multiplication of two Surreals. """ assert Surreal.from_value(a) * Surreal.from_value(b) == Game(a * b)
def test_add_game_2(a, b): """ Test the addition of two Surreals. """ assert Surreal.from_value(a) + Surreal.from_value(b) == Game(a + b)
def test_order(a, b): """ Test the addition of two Surreals. """ assert (Surreal.from_value(a) >= Surreal.from_value(b)) == (a >= b)
""" Tests for ludology.surreal. """ import pytest from ludology import Game, Surreal from ludology.closet import one, star, zero @pytest.mark.parametrize('n', [ Surreal.from_value(0), Surreal.from_value(1 / 2), Surreal.from_value(0.125), Surreal.from_value(-1), Surreal.from_value(2), ]) def test_is_number(n): """ Test that all Surreals are numbers. """ assert n.is_number @pytest.mark.parametrize(('n', 'v'), [ (Surreal.from_value(0), True), (Surreal.from_value(1 / 2), False), (Surreal.from_value(0.125), False), (Surreal.from_value(-1), False), (Surreal.from_value(2), False), ])
@pytest.mark.parametrize(('g', 't', 'v'), [ (pm_one, 1.0, Game({3}, {-3})), (star, 1.0, pm_one), (up, 1.0, Game({1}, {Game({0}, {-2})})), ]) def test_overheating(g, t, v): """ Test that several overheated Games are correct. """ assert overheat(g, t) == v @pytest.mark.parametrize('g', [ 3 * one, Surreal.from_value(1 / 4), zero, -4 * one, ]) def test_is_cold(g): """ Assert that Numbers are cold. """ assert is_cold(g) @pytest.mark.parametrize('g', [ star, 2 + star, 5 * one + up, ])