1# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2#
3# This source code is licensed under the MIT license found in the
4# LICENSE file in the root directory of this source tree.
5
6import typing as tp
7import numpy as np
8from nevergrad.common import testing
9from . import game
10
11
12@testing.parametrized(**{name: (name,) for name in game._Game().get_list_of_games()})
13def test_games(name: str) -> None:
14    dimension = game._Game().play_game(name)
15    res: tp.List[tp.Any] = []
16    for k in range(200):
17        res.append(game._Game().play_game(name, np.random.uniform(0, 1, dimension), None))
18        score = float(sum(1 if r == 2 else 0 if r == 1 else 0.5 for r in res)) / len(res)
19        if k >= 20 and 0.2 <= score <= 0.8:
20            break
21    assert score >= 0.1
22    assert score <= 0.9
23    assert any(res), "All ties"
24    function = game.Game(name)
25    function(function.parametrization.random_state.normal(size=function.dimension))
26