完成基本多场景功能。
This commit is contained in:
63
tests/test_float_comparison.py
Normal file
63
tests/test_float_comparison.py
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试浮点数比较逻辑的脚本
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
||||
|
||||
from storage_optimization import calculate_energy_balance, SystemParameters
|
||||
|
||||
def test_float_comparison():
|
||||
"""测试浮点数比较逻辑"""
|
||||
|
||||
# 创建测试数据
|
||||
solar_output = [1.0] * 24
|
||||
wind_output = [1.0] * 24
|
||||
thermal_output = [1.0] * 24
|
||||
load_demand = [1.0] * 24
|
||||
|
||||
# 测试非常小的上网电量比例(接近0)
|
||||
params = SystemParameters(
|
||||
max_curtailment_wind=0.1,
|
||||
max_curtailment_solar=0.1,
|
||||
max_grid_ratio=1e-15, # 非常小的值,应该被视为0
|
||||
storage_efficiency=0.9,
|
||||
discharge_rate=1.0,
|
||||
charge_rate=1.0
|
||||
)
|
||||
|
||||
# 计算能量平衡
|
||||
storage_capacity = 5.0
|
||||
result = calculate_energy_balance(
|
||||
solar_output, wind_output, thermal_output, load_demand, params, storage_capacity
|
||||
)
|
||||
|
||||
# 检查结果
|
||||
total_grid_feed_in = sum(result['grid_feed_in'])
|
||||
print(f"测试非常小的上网电量比例 ({params.max_grid_ratio}):")
|
||||
print(f"实际上网电量: {total_grid_feed_in:.6f} MWh")
|
||||
|
||||
# 测试正常的上网电量比例
|
||||
params2 = SystemParameters(
|
||||
max_curtailment_wind=0.1,
|
||||
max_curtailment_solar=0.1,
|
||||
max_grid_ratio=0.1, # 正常值
|
||||
storage_efficiency=0.9,
|
||||
discharge_rate=1.0,
|
||||
charge_rate=1.0
|
||||
)
|
||||
|
||||
result2 = calculate_energy_balance(
|
||||
solar_output, wind_output, thermal_output, load_demand, params2, storage_capacity
|
||||
)
|
||||
|
||||
total_grid_feed_in2 = sum(result2['grid_feed_in'])
|
||||
print(f"\n测试正常的上网电量比例 ({params2.max_grid_ratio}):")
|
||||
print(f"实际上网电量: {total_grid_feed_in2:.6f} MWh")
|
||||
|
||||
print("\n浮点数比较逻辑测试完成")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_float_comparison()
|
||||
Reference in New Issue
Block a user