Exemple #1
0
def test_gamegen_noise_gaussian(game_file):
    """Test gamegen with gaussian noise"""
    with stderr() as err, stdout() as out:
        assert run(
            'gen', 'noise', '-d', 'gaussian', '-w', '1.5', '-s', '5', '-i',
            game_file), err.getvalue()
    gamereader.loads(out.getvalue())
Exemple #2
0
def test_gamegen_noise_uniform(game_str):
    """Test uniform noise gamegen"""
    with stdin(game_str), stderr() as err, stdout() as out:
        assert run(
            'gen', 'noise', '-d', 'uniform', '-w', '1.5', '-s',
            '5'), err.getvalue()
    gamereader.loads(out.getvalue())
Exemple #3
0
def test_gamegen_noise_bimodal(game_file):
    """Test bimodal noise gamegen"""
    with stderr() as err, stdout() as out:
        assert run(
            'gen', 'noise', '-d', 'bimodal', '-w', '1.5', '-s', '5', '-i',
            game_file), err.getvalue()
    gamereader.loads(out.getvalue())
Exemple #4
0
def test_conv_mat_gambit_inv(mgame, mgame_str):
    """Test convert mat to gambit and back"""
    with stdin(mgame_str), stdout() as out, stderr() as err:
        assert run('conv', 'gambit'), err.getvalue()
    with stdin(out.getvalue()), stdout() as out, stderr() as err:
        assert run('conv', 'matgame'), err.getvalue()
    copy = gamereader.loads(out.getvalue())
    assert copy == mgame
Exemple #5
0
def test_conv_game_gambit_inv(game, game_str):
    """Test game to gambit and back"""
    with stdin(game_str), stdout() as out, stderr() as err:
        assert run('conv', 'gambit'), err.getvalue()
    with stdin(out.getvalue()), stdout() as out, stderr() as err:
        assert run('conv', 'game'), err.getvalue()
    copy = gamereader.loads(out.getvalue())
    assert copy == paygame.game_copy(matgame.matgame_copy(game))
Exemple #6
0
def test_conv_game_norm(game_str):
    """Test game to normalized version"""
    with stdin(game_str), stdout() as out, stderr() as err:
        assert run('conv', 'norm'), err.getvalue()
    game = gamereader.loads(out.getvalue())
    assert np.allclose(game.min_role_payoffs(), 0)
    assert np.all(np.isclose(game.max_role_payoffs(), 1) |
                  np.isclose(game.max_role_payoffs(), 0))
Exemple #7
0
def test_automatic_deserialization(base):
    """Test that we can serialize and deserialize arbitrary games"""
    if base == 'gambit':
        base = mat()
        string = gambit.dumps(base)
        fil = io.StringIO(string)
    else:
        base = base()
        string = gamereader.dumps(base)
        fil = io.StringIO()
        gamereader.dump(base, fil)
        fil.seek(0)

    copy = gamereader.loads(string)
    assert base == copy

    copy = gamereader.load(fil)
    assert base == copy
def test_automatic_deserialization(base):
    """Test that we can serialize and deserialize arbitrary games"""
    if base == 'gambit':
        base = mat()
        string = gambit.dumps(base)
        fil = io.StringIO(string)
    else:
        base = base()
        string = gamereader.dumps(base)
        fil = io.StringIO()
        gamereader.dump(base, fil)
        fil.seek(0)

    copy = gamereader.loads(string)
    assert base == copy

    copy = gamereader.load(fil)
    assert base == copy
Exemple #9
0
def test_reduction_hierarchical(game, game_file):
    """Test hierarchical reduction"""
    with stdout() as out, stderr() as err:
        assert run('red', '-thr', '-s', '2,1', '-i', game_file), err.getvalue()
    ogame = gamereader.loads(out.getvalue())
    assert ogame == hr.reduce_game(game, [2, 1])
Exemple #10
0
def test_reduction_basic(hardgame, hardgame_str):
    """Test basic reduction"""
    with stdin(hardgame_str), stdout() as out, stderr() as err:
        assert run('red', 'background:2;hft:1'), err.getvalue()
    game = gamereader.loads(out.getvalue())
    assert game == dpr.reduce_game(hardgame, [2, 1])
Exemple #11
0
def test_reduction_6(mgame_file):
    """Test that reduction works for other games"""
    with stdout() as out, stderr() as err:
        assert run('red', '-tidr', '-i', mgame_file), err.getvalue()
    gamereader.loads(out.getvalue())
Exemple #12
0
def test_dominance_strictdom(game_file):
    """Test strict dominance"""
    with stdout() as out, stderr() as err:
        assert run('dom', '-cstrictdom', '-i', game_file), err.getvalue()
    gamereader.loads(out.getvalue())
Exemple #13
0
def test_dominance_game(game, game_file):
    """Test basic dominance"""
    with stdout() as out, stderr() as err:
        assert run('dom', '-i', game_file), err.getvalue()
    game_dom = gamereader.loads(out.getvalue())
    assert game_dom == game
Exemple #14
0
def fix_hardgame(hardgame_str):
    """Get a game with hard nash equilibria"""
    return gamereader.loads(hardgame_str)
def test_parse_fail():
    """Test invalid games"""
    with pytest.raises(ValueError):
        gamereader.loads('')
    with pytest.raises(ValueError):
        gamereader.loadj({'type': 'unknown.0'})
Exemple #16
0
def test_reduction_twins(game, game_file):
    """Test twins reduction"""
    with stdout() as out, stderr() as err:
        assert run('red', '-ttr', '-i', game_file), err.getvalue()
    ogame = gamereader.loads(out.getvalue())
    assert ogame == tr.reduce_game(game)
Exemple #17
0
def test_reduction_identity(game, game_file):
    """Test identity reduction"""
    with stdout() as out, stderr() as err:
        assert run('red', '-tidr', '-i', game_file), err.getvalue()
    ogame = gamereader.loads(out.getvalue())
    assert ogame == game
Exemple #18
0
def test_dominance_never_best_response(game_file):
    """Test never best response"""
    with stdout() as out, stderr() as err:
        assert run('dom', '-cneverbr', '-i', game_file), err.getvalue()
    gamereader.loads(out.getvalue())
Exemple #19
0
def test_gamegen_ursym():
    """Test uniform role symmetric gamegen"""
    with stdout() as out, stderr() as err:
        assert run('gen', 'ursym', '3:4,4:3'), err.getvalue()
    gamereader.loads(out.getvalue())
Exemple #20
0
def test_parse_fail():
    """Test invalid games"""
    with pytest.raises(ValueError):
        gamereader.loads('')
    with pytest.raises(ValueError):
        gamereader.loadj({'type': 'unknown.0'})