forked from OuyangWenyu/hydromodel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
38 lines (30 loc) · 1.41 KB
/
test.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
"""使用python自带的单元测试库unittest进行测试"""
import datetime
from calibrate import calibrate
from data_process import init_parameters
from xaj import xaj
import unittest
class TestXaj(unittest.TestCase):
"""每个单元测试类都必须继承unittest.TestCase"""
def test_xaj(self):
"""每个测试用例都必须以test开头"""
# 构造输入数据
property, config, initial_conditions, days_rain_evapor, floods_data, xaj_params = init_parameters()
# 调用模型计算,得到输出
simulated_flow = xaj(property, config, initial_conditions, days_rain_evapor, floods_data, xaj_params)
print(simulated_flow)
def test_xaj_calibrate(self):
starttime = datetime.datetime.now()
run_counts = 100
optimal_params = calibrate(run_counts)
print("本次优化的计算结果,即优选参数集为:")
print(optimal_params)
endtime = datetime.datetime.now()
print("率定完毕,耗费时间为 " + str((endtime - starttime).seconds) + " s")
if __name__ == '__main__':
# 测试流程:写好TestCase(类TestXaj),加载TestCase到TestSuite,由TextTestRunner运行TestSuite,运行结果保存在TextTestResult中
suite = unittest.TestSuite()
tests = [TestXaj('test_xaj_calibrate')]
suite.addTests(tests)
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)