Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
purboday committed Sep 3, 2024
1 parent fcaa857 commit 692e7ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Julia package designed for simulating the operation of battery energy storage systems (BESS) in various energy markets. The package provides tools to model battery characteristics, simulate market operations, and calculate the optimal power dispatch.

## Installation
To get started with BatteryOptimization.jl, ensure you have Julia installed on your system (version 1.6 or later is recommended).
To get started, ensure you have Julia installed on your system (version 1.6 or later is recommended).

- Begin by cloning the repository to your local machine:
```
Expand Down
4 changes: 2 additions & 2 deletions src/Markets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export Market, get_price

function load_caiso_prices()
dfmt = dateformat"mm/dd/yyyy HH:MM:SS p"
price_per_mwh = DataFrame(CSV.File("src/data/20230101-20240101 CAISO Average Price.csv"; dateformat=dfmt))
price_per_mwh = DataFrame(CSV.File("$(@__DIR__)/data/20230101-20240101 CAISO Average Price.csv"; dateformat=dfmt))
price_per_kwh = transform(price_per_mwh, :price => (x -> x * 0.001) => :price)
return price_per_kwh
end

function load_ercot_prices()
dfmt = dateformat"mm/dd/yyyy HH:MM:SS p"
price_per_mwh = DataFrame(CSV.File("src/data/20230101-20240101 ERCOT Real-time Price.csv"; dateformat=dfmt))
price_per_mwh = DataFrame(CSV.File("$(@__DIR__)/data/20230101-20240101 ERCOT Real-time Price.csv"; dateformat=dfmt))
price_per_kwh = transform(price_per_mwh, :price => (x -> x * 0.001) => :price)
price_per_kwh = price_per_kwh[price_per_kwh.zone.=="LZ_HOUSTON", :]
price_per_kwh = price_per_kwh[:, [:date, :price]]
Expand Down
25 changes: 24 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
using BatteryOptimization
using BatteryOptimization.Dates
using BatteryOptimization.DataFrames
using Test

@testset "BatteryOptimization.jl" begin
# Write your tests here.
battery = Battery(capacity_kwh=100, max_power_kw=25)
market = Market("CAISO", DateTime("2023-06-01T00:00:00"), DateTime("2023-06-01T03:00:00"))
result = run_simulation(DateTime("2023-06-01T00:00:00"), DateTime("2023-06-01T03:00:00"), market, battery)
@test length(result.power_schedule.power_kw) == 4
@test result.objective_value isa Real
@test all(result.power_schedule.power_kw .<= battery.max_power_kw)
@test all(result.power_schedule.power_kw .>= -battery.max_power_kw)
@test sum(result.power_schedule.power_kw) >= battery.capacity_kwh * (battery.final_soc - battery.initial_soc)
@test all(get_soc(battery.initial_soc, battery.capacity_kwh, result.power_schedule).soc .<= battery.max_soc)
@test all(get_soc(battery.initial_soc, battery.capacity_kwh, result.power_schedule).soc .>= battery.min_soc)
end

@testset "Markets.jl" begin
@testset "Test Market $(iso)" for iso in ["CAISO", "ERCOT"]
market = Market(iso, DateTime("2023-06-01T00:00:00"), DateTime("2023-06-01T03:00:00"))
@test market.price_per_kwh isa DataFrame
@test !isempty(market.price_per_kwh)
@test all(market.price_per_kwh.date .>= DateTime("2023-05-31T23:00:00"))
@test all(market.price_per_kwh.date .<= DateTime("2023-06-1T03:00:00"))
@test get_price(market, timestamp=DateTime("2023-06-01T04:00:00")) == market.price_per_kwh[end, :price]
end
@test_throws ErrorException Market("XYZ", DateTime("2023-06-01T00:00:00"), DateTime("2023-06-1T03:00:00"))
end

0 comments on commit 692e7ec

Please sign in to comment.