单元测试和改进
This commit is contained in:
88
tests/test_working_algorithms.py
Normal file
88
tests/test_working_algorithms.py
Normal file
@@ -0,0 +1,88 @@
|
||||
"""
|
||||
Working unit tests for algorithm modules based on actual module structure.
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from src.heurams.kernel.algorithms.sm2 import SM2Algorithm
|
||||
|
||||
|
||||
class TestSM2Algorithm:
|
||||
"""Test cases for SM2Algorithm class."""
|
||||
|
||||
def test_sm2_algorithm_creation(self):
|
||||
"""Test SM2Algorithm creation."""
|
||||
algorithm = SM2Algorithm()
|
||||
|
||||
assert SM2Algorithm.algo_name == "SM-2"
|
||||
assert isinstance(SM2Algorithm.defaults, dict)
|
||||
|
||||
def test_sm2_defaults(self):
|
||||
"""Test SM2Algorithm default values."""
|
||||
defaults = SM2Algorithm.defaults
|
||||
|
||||
assert "efactor" in defaults
|
||||
assert "rept" in defaults
|
||||
assert "interval" in defaults
|
||||
assert "next_date" in defaults
|
||||
assert "is_activated" in defaults
|
||||
assert "last_modify" in defaults
|
||||
|
||||
def test_sm2_is_due(self):
|
||||
"""Test SM2Algorithm is_due method."""
|
||||
algodata = {
|
||||
"SM-2": {
|
||||
"next_date": 0, # Past date
|
||||
"is_activated": 1
|
||||
}
|
||||
}
|
||||
|
||||
result = SM2Algorithm.is_due(algodata)
|
||||
|
||||
assert isinstance(result, bool)
|
||||
|
||||
def test_sm2_rate(self):
|
||||
"""Test SM2Algorithm rate method."""
|
||||
algodata = {
|
||||
"SM-2": {
|
||||
"efactor": 2.5,
|
||||
"rept": 5,
|
||||
"interval": 10
|
||||
}
|
||||
}
|
||||
|
||||
result = SM2Algorithm.rate(algodata)
|
||||
|
||||
assert isinstance(result, str)
|
||||
|
||||
def test_sm2_nextdate(self):
|
||||
"""Test SM2Algorithm nextdate method."""
|
||||
algodata = {
|
||||
"SM-2": {
|
||||
"next_date": 100
|
||||
}
|
||||
}
|
||||
|
||||
result = SM2Algorithm.nextdate(algodata)
|
||||
|
||||
assert isinstance(result, int)
|
||||
|
||||
def test_sm2_revisor(self):
|
||||
"""Test SM2Algorithm revisor method."""
|
||||
algodata = {
|
||||
"SM-2": {
|
||||
"efactor": 2.5,
|
||||
"rept": 0,
|
||||
"real_rept": 0,
|
||||
"interval": 1,
|
||||
"is_activated": 1,
|
||||
"last_modify": 0
|
||||
}
|
||||
}
|
||||
|
||||
# Should not raise an exception
|
||||
SM2Algorithm.revisor(algodata, feedback=4, is_new_activation=False)
|
||||
|
||||
# Verify that algodata was modified
|
||||
assert "efactor" in algodata["SM-2"]
|
||||
assert "rept" in algodata["SM-2"]
|
||||
assert "interval" in algodata["SM-2"]
|
||||
Reference in New Issue
Block a user