예제 #1
0
def test_invert(n):
    """
    Test the inversion of a Surreal.
    """
    assert Surreal.from_value(n)._invert() == Surreal.from_value(1 / n)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
def test_order(a, b):
    """
    Test the addition of two Surreals.
    """
    assert (Surreal.from_value(a) >= Surreal.from_value(b)) == (a >= b)
예제 #8
0
"""
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),
])
예제 #9
0
@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,
])