|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import pytest |
| 3 | +import random |
4 | 4 |
|
5 | 5 | from deepeval.optimizer.algorithms import COPRO |
6 | 6 |
|
7 | 7 |
|
8 | | -def test_copro_defaults(): |
| 8 | +def test_copro_defaults() -> None: |
9 | 9 | algo = COPRO() |
| 10 | + assert algo.depth == 4 |
| 11 | + assert algo.breadth == 7 |
| 12 | + assert algo.minibatch_size == 25 |
| 13 | + assert isinstance(algo.random_state, random.Random) |
| 14 | + assert isinstance(algo.seed, int) |
10 | 15 |
|
11 | | - # Base defaults |
12 | | - assert algo.iterations == 5 |
13 | | - assert algo.minibatch_size == 8 |
14 | | - assert algo.exploration_probability == 0.2 |
15 | | - assert algo.full_eval_every == 5 |
16 | | - assert isinstance(algo.random_seed, int) |
17 | 16 |
|
18 | | - # COPRO-specific defaults |
19 | | - assert algo.population_size == 4 |
20 | | - assert algo.proposals_per_step == 4 |
| 17 | +def test_copro_accepts_explicit_random_state() -> None: |
| 18 | + r = random.Random(123) |
| 19 | + algo = COPRO(random_state=r) |
| 20 | + assert algo.random_state is r |
| 21 | + assert isinstance(algo.seed, int) |
21 | 22 |
|
22 | 23 |
|
23 | | -@pytest.mark.parametrize("value", [0, -1]) |
24 | | -def test_copro_rejects_non_positive_population_size(value: int): |
25 | | - with pytest.raises(ValueError): |
26 | | - COPRO(population_size=value) |
| 24 | +def test_copro_int_random_state_sets_seed() -> None: |
| 25 | + algo = COPRO(random_state=99) |
| 26 | + assert algo.seed == 99 |
| 27 | + assert isinstance(algo.random_state, random.Random) |
27 | 28 |
|
28 | 29 |
|
29 | | -@pytest.mark.parametrize("value", [0, -3]) |
30 | | -def test_copro_rejects_non_positive_proposals_per_step(value: int): |
31 | | - with pytest.raises(ValueError): |
32 | | - COPRO(proposals_per_step=value) |
| 30 | +def test_copro_allows_minimal_hyperparameters() -> None: |
| 31 | + algo = COPRO(depth=1, breadth=1, minibatch_size=1, random_state=0) |
| 32 | + assert algo.depth == 1 |
| 33 | + assert algo.breadth == 1 |
| 34 | + assert algo.minibatch_size == 1 |
0 commit comments