-
Notifications
You must be signed in to change notification settings - Fork 26
/
test_sampling_sweep.py
51 lines (33 loc) · 1.42 KB
/
test_sampling_sweep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from easyvvuq.sampling.sweep import BasicSweep, wrap_iterable
import pytest
@pytest.fixture
def basic_sweep_sampler():
return BasicSweep({'a': [1, 2, 3], 'b': [4, 5, 6]})
def test_wrap_iterable():
res = []
for var_name, val in wrap_iterable('a', [1, 2, 3]):
res.append((var_name, val))
assert(res == [('a', 1), ('a', 2), ('a', 3)])
def test_sweep(basic_sweep_sampler):
res = []
for run_dict in basic_sweep_sampler:
res.append(run_dict)
assert(res == [{'a': 1, 'b': 4}, {'a': 1, 'b': 5}, {'a': 1, 'b': 6},
{'a': 2, 'b': 4}, {'a': 2, 'b': 5}, {'a': 2, 'b': 6},
{'a': 3, 'b': 4}, {'a': 3, 'b': 5}, {'a': 3, 'b': 6}])
def test_init():
sweep = BasicSweep({'a': [1, 2, 3], 'b': [4, 5, 6]}, 10)
with pytest.raises(StopIteration):
sweep.__next__()
def test_element_version(basic_sweep_sampler):
assert(isinstance(basic_sweep_sampler.element_version(), str))
def test_is_finite(basic_sweep_sampler):
assert(basic_sweep_sampler.is_finite())
def test_is_restartable(basic_sweep_sampler):
assert(basic_sweep_sampler.is_restartable())
def test_get_restart_dict(basic_sweep_sampler):
restart_dict = basic_sweep_sampler.get_restart_dict()
assert(restart_dict['sweep'] == {'a': [1, 2, 3], 'b': [4, 5, 6]})
assert(restart_dict['count'] == 0)
def test_basic_sweep_single_list():
assert(len(list(BasicSweep({'a': [1, 2, 3]}))) == 3)