-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_core.py
More file actions
63 lines (43 loc) · 1.84 KB
/
Copy pathtest_core.py
File metadata and controls
63 lines (43 loc) · 1.84 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
from pathlib import Path
import pytest
from simulador_quantico.core import (
_normalize_shor_base,
classical_trial_division,
create_timestamped_output_dir,
quantum_shor_simulation,
recover_factors_from_order,
)
def test_classical_trial_division_for_15():
result = classical_trial_division(15)
assert result.factors == (3, 5)
assert result.operations >= 1
assert result.elapsed_s >= 0
def test_timestamped_output_dir_creation(tmp_path: Path):
run_dir = create_timestamped_output_dir(tmp_path)
assert run_dir.exists()
assert run_dir.is_dir()
assert run_dir.parent == tmp_path
def test_normalize_shor_base_applies_modulo():
assert _normalize_shor_base(a=17, n=15) == 2
def test_normalize_shor_base_rejects_zero_or_one():
with pytest.raises(ValueError):
_normalize_shor_base(a=15, n=15)
with pytest.raises(ValueError):
_normalize_shor_base(a=16, n=15)
def test_recover_factors_from_order_for_15():
factors = recover_factors_from_order(n=15, a=2, r=4)
assert factors == (3, 5)
def test_recover_factors_from_order_returns_none_for_odd_order():
assert recover_factors_from_order(n=15, a=2, r=3) is None
def test_quantum_shor_simulation_rejects_even_n():
with pytest.raises(ValueError, match="N deve ser ímpar"):
quantum_shor_simulation(n=14, a=3, shots=512, n_counting=4)
def test_quantum_shor_simulation_rejects_non_coprime_base():
with pytest.raises(ValueError, match="coprima"):
quantum_shor_simulation(n=21, a=6, shots=512, n_counting=6)
def test_quantum_shor_simulation_general_case_succeeds_without_qiskit():
result = quantum_shor_simulation(n=21, a=2, shots=512, n_counting=6)
assert result.candidate_a == 2
assert result.measured_order is not None
assert result.factors == (3, 7)
assert sum(result.counts.values()) == result.shots