示例#1
0
def test_right_incentives():
    """
    Test for the incentives of a known example.
    """
    g = Game({0}, {Game({0}, {-2})})
    ri = {Game({Game({2}, {0}), 2}, {0})}
    assert right_incentives(g) == ri
示例#2
0
def test_left_incentives():
    """
    Test for the incentives of a known example.
    """
    g = Game({0}, {Game({0}, {-2})})
    li = {Game({Game({2}, {0})}, {0})}
    assert left_incentives(g) == li
示例#3
0
def test_add_nimber_game():
    """
    Test that Nimbers add with Games correctly.
    """
    a = Nimber(3)
    b = Game(Nimber(2))
    c = Game(Nimber(1))
    assert a + b == c
示例#4
0
def test_mul_nimber_game():
    """
    Test that Nimbers multiply with Games correctly.
    """
    a = Nimber(2)
    b = Game(Nimber(2))
    c = Game(Nimber(3))
    assert a * b == c
示例#5
0
def test_value_dyadic_rational(m, j):
    """
    Test the construction of dyadic rationals.
    """
    f = m / 2**j
    n, d = f.as_integer_ratio()
    g = Game(f)
    assert g.value == (f"{n}/{d}" if d > 1 else f"{n}")
示例#6
0
def test_value_dyadic_rational(m, j):
    """
    Test the construction of dyadic rationals.
    """
    frac = m / 2**j
    num, denom = frac.as_integer_ratio()
    string = unicode_fraction(num, denom)
    game = Game(frac)
    assert game.value == string
示例#7
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)
示例#8
0
def test_game_fail():
    """
    Test that Game punts of constructing "deep" games.
    """
    with pytest.raises(ValueError):
        Game(1 / 3)
示例#9
0
def test_equiv_2():
    """
    Test the ordering of several Games.
    """
    g = Game(right={star})
    assert g == zero
示例#10
0
    up,
    up + star,
    pm_one,
])
def test_not_impartial(g):
    """
    Test that these games are not impartial.
    """
    assert not g.is_impartial


@pytest.mark.parametrize('g', [
    star,
    up,
    -up,
    Game({0}, {Game({0}, {-1})}),
])
def test_infinitesimal(g):
    """
    Test that these games are infinitesimal.
    """
    assert g.is_infinitesimal


@pytest.mark.parametrize('g', [
    half,
    one,
    zero,
    pm_one,
])
def test_not_infinitesimal(g):
示例#11
0
    assert gen1a == gen1b


def test_all_games_gen_2():
    """
    Test that the correct number of games are crated by day 2.
    """
    gen2 = all_games(2)
    assert len(gen2) == 22


@pytest.mark.parametrize(('g1', 'g2'), [
    (zero, star),
    (one, one),
    (up, -upstar),
    (Game({-1}, {-3}), Game({-1}, {-3})),
])
def test_companion(g1, g2):
    """
    Test companionship.
    """
    assert companion(g1) == g2


@pytest.mark.parametrize('g', [
    one,
    Game({-1}, {-3}),
])
def test_is_lonely(g):
    """
    Test that certain Games are lonely.
示例#12
0
"""
Tests for ludology.thermography.
"""

import pytest

from ludology import Game, Surreal
from ludology.closet import zero, quarter, half, one, pm_one, up, star
from ludology.thermography import (mean, temperature, cool, heat, overheat,
                                   is_cold, is_tepid, is_hot)


G_L1 = Game(5/2)
G_L2 = Game({Game(4)}, {Game(2)})
G_R1 = Game({Game(-1)}, {Game(-2)})
G_R2 = Game({Game()}, {Game(-4)})
g1 = Game({G_L1, G_L2}, {G_R1, G_R2})


@pytest.mark.parametrize(['g', 'm'], [
    (pm_one, 0.0),
    (one + pm_one, 1.0),
    (3 * one, 3.0),
    (g1, 0.5),
])
def test_mean(g, m):
    """
    Test that several mean values are correct.
    """
    assert mean(g) == m
示例#13
0
def test_mul_game(a, b):
    """
    Test the multiplication of two Surreals.
    """
    assert Surreal(a) * Game(b) == Surreal(a * b)
示例#14
0
@pytest.mark.parametrize(('g', 't'), [
    (pm_one, 1.0),
    (3 * one, -1.0),
    (g1, 2.5),
    (half, -1 / 2),
    (half + quarter, -1 / 4),
])
def test_temperature(g, t):
    """
    Test that several temperatures are correct.
    """
    assert temperature(g) == t


@pytest.mark.parametrize(('g', 't', 'v'), [
    (Game({2}, {-2}), 1.0, Game({1}, {-1})),
    (g1, 2.0, Game({1}, {Game({0}, {0})})),
])
def test_cooling(g, t, v):
    """
    Test that several cooled Games are correct.
    """
    assert cool(g, t) == v


@pytest.mark.parametrize(('g', 't', 'v'), [
    (pm_one, one, Game({2}, {-2})),
    (pm_one, 1, Game({2}, {-2})),
    (2 * one, 1.0, 2 * one),
])
def test_heating(g, t, v):
示例#15
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)
示例#16
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)
示例#17
0
"""
Tests for ludology.sums.
"""

import pytest

from ludology import Game
from ludology.canonical_form import canonical_form
from ludology.closet import one, pm_one, star, up, zero
from ludology.sums import (conjunctive, continued_conjunctive,
                           diminished_disjunctive, disjunctive, ordinal,
                           selective, sequential, shortened_selective, side)


G = Game({0}, {pm_one})


@pytest.mark.parametrize(('G', 'H', 'J'), [
    (G, up, Game({1}, {Game({1}, {1})})),
    (G, zero, G),
    (zero, G, G),
])
def test_disjunctive(G, H, J):
    """
    Test that the disjunctive sum matches known results.
    """
    assert canonical_form(disjunctive(G, H)) == J


@pytest.mark.parametrize(('G', 'H', 'J'), [
    (G, up, Game({1}, {Game({1}, {1})})),
示例#18
0
"""
Tests for ludolory.hypothesis.
"""

import pytest

from ludology import Game
from ludology.hypothesis import gamify


@pytest.mark.parametrize(['s', 'g'], [
    (([([], [([], [])]), ([], [])], [([], [])]), Game({0}, {0})),
    (Game({0}, {0}), Game({0}, {0})),
])
def test_gamify(s, g):
    """
    Test a contrived example.
    """
    assert gamify(s) == g
示例#19
0
    up,
    up + star,
    pm_one,
])
def test_not_impartial(g):
    """
    Test that these games are not impartial.
    """
    assert not g.is_impartial


@pytest.mark.parametrize('g', [
    star,
    up,
    -up,
    Game({0}, {Game({0}, {-1})}),
])
def test_infinitesimal(g):
    """
    Test that these games are infinitesimal.
    """
    assert g.is_infinitesimal


@pytest.mark.parametrize('g', [
    half,
    one,
    zero,
    pm_one,
])
def test_not_infinitesimal(g):