コード例 #1
0
ファイル: test_surreal.py プロジェクト: Autoplectic/ludology
def test_invert(n):
    """
    Test the inversion of a Surreal.
    """
    assert Surreal.from_value(n)._invert() == Surreal.from_value(1 / n)
コード例 #2
0
ファイル: test_surreal.py プロジェクト: Autoplectic/ludology
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
ファイル: test_surreal.py プロジェクト: Autoplectic/ludology
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
ファイル: test_surreal.py プロジェクト: Autoplectic/ludology
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
ファイル: test_surreal.py プロジェクト: Autoplectic/ludology
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)
コード例 #6
0
ファイル: test_surreal.py プロジェクト: Autoplectic/ludology
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)
コード例 #7
0
ファイル: test_surreal.py プロジェクト: Autoplectic/ludology
"""
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),
])
コード例 #8
0
ファイル: test_surreal.py プロジェクト: Autoplectic/ludology
def test_order(a, b):
    """
    Test the addition of two Surreals.
    """
    assert (Surreal.from_value(a) >= Surreal.from_value(b)) == (a >= b)
コード例 #9
0
def test_invert(n):
    """
    Test the inversion of a Surreal.
    """
    assert Surreal(n)._invert() == Surreal(1/n)
コード例 #10
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(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,
])
コード例 #11
0
def test_div(a, b):
    """
    Test the division of two Surreals.
    """
    assert Surreal(a) / Surreal(b) == Surreal(a / b)
コード例 #12
0
def test_mul_game(a, b):
    """
    Test the multiplication of two Surreals.
    """
    assert Surreal(a) * Game(b) == Surreal(a * b)
コード例 #13
0
def test_add(a, b):
    """
    Test the addition of two Surreals.
    """
    assert Surreal(a) + Surreal(b) == Surreal(a + b)
コード例 #14
0
"""
Tests for ludology.surreal.
"""

import pytest

from ludology import Game, Surreal
from ludology.closet import zero, one, star


@pytest.mark.parametrize('n', [
    Surreal(0),
    Surreal(1/2),
    Surreal(0.125),
    Surreal(-1),
    Surreal(2),
])
def test_is_number(n):
    """
    Test that all Surreals are numbers.
    """
    assert n.is_number


@pytest.mark.parametrize(['n', 'v'], [
    (Surreal(0), True),
    (Surreal(1/2), False),
    (Surreal(0.125), False),
    (Surreal(-1), False),
    (Surreal(2), False),
])
コード例 #15
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,
])