Files
multi_energy_complementarity/tests/test_float_comparison.py
2025-12-27 19:15:56 +08:00

63 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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()