Skip to content

Commit

Permalink
fixup! test: Adding testing for new function
Browse files Browse the repository at this point in the history
  • Loading branch information
pesap committed Aug 27, 2024
1 parent 18ff011 commit 6988ef6
Showing 1 changed file with 51 additions and 17 deletions.
68 changes: 51 additions & 17 deletions test/test_power_system_table_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ end
end

@testset "Test create_poly_cost function" begin

cost_colnames = ["heat_rate_a0", "heat_rate_a1", "heat_rate_a2"]

# Coefficients for a CC using natura gas
Expand All @@ -193,39 +192,74 @@ end

# First test that return quadratic if all coefficients are provided.
# We convert the coefficients to string to mimic parsing from csv
example_generator = (name="test-gen", heat_rate_a0=string(a0), heat_rate_a1=string(a1), heat_rate_a2=string(a2))
example_generator = (
name = "test-gen",
heat_rate_a0 = string(a0),
heat_rate_a1 = string(a1),
heat_rate_a2 = string(a2),
)
cost_curve, fixed_cost = create_poly_cost(example_generator, cost_colnames)
@assert cost_curve isa QuadraticCurve
@assert isapprox(get_quadratic_term(cost_curve), a2, atol=0.01)
@assert isapprox(get_proportional_term(cost_curve), a1, atol=0.01)
@assert isapprox(get_constant_term(cost_curve), a0, atol=0.01)
@assert isapprox(get_quadratic_term(cost_curve), a2, atol = 0.01)
@assert isapprox(get_proportional_term(cost_curve), a1, atol = 0.01)
@assert isapprox(get_constant_term(cost_curve), a0, atol = 0.01)

# Test return linear with both proportional and constant term
example_generator = (name="test-gen", heat_rate_a0=string(a0), heat_rate_a1=string(a1), heat_rate_a2=nothing)
example_generator = (
name = "test-gen",
heat_rate_a0 = string(a0),
heat_rate_a1 = string(a1),
heat_rate_a2 = nothing,
)
cost_curve, fixed_cost = create_poly_cost(example_generator, cost_colnames)
@assert cost_curve isa LinearCurve
@assert isapprox(get_proportional_term(cost_curve), a1, atol=0.01)
@assert isapprox(get_constant_term(cost_curve), a0, atol=0.01)
@assert isapprox(get_proportional_term(cost_curve), a1, atol = 0.01)
@assert isapprox(get_constant_term(cost_curve), a0, atol = 0.01)

# Test return linear with just proportional term
example_generator = (name="test-gen", heat_rate_a0=nothing, heat_rate_a1=string(a1), heat_rate_a2=nothing)
example_generator = (
name = "test-gen",
heat_rate_a0 = nothing,
heat_rate_a1 = string(a1),
heat_rate_a2 = nothing,
)
cost_curve, fixed_cost = create_poly_cost(example_generator, cost_colnames)
@assert cost_curve isa LinearCurve
@assert isapprox(get_proportional_term(cost_curve), a1, atol=0.01)
@assert isapprox(get_proportional_term(cost_curve), a1, atol = 0.01)

# Test raises error if a2 is passed but other coefficients are nothing
example_generator = (name="test-gen", heat_rate_a0=nothing, heat_rate_a1=nothing, heat_rate_a2=string(a2))
example_generator = (
name = "test-gen",
heat_rate_a0 = nothing,
heat_rate_a1 = nothing,
heat_rate_a2 = string(a2),
)
@test_throws IS.DataFormatError create_poly_cost(example_generator, cost_colnames)
example_generator = (name="test-gen", heat_rate_a0=nothing, heat_rate_a1=string(a1), heat_rate_a2=string(a2))
example_generator = (
name = "test-gen",
heat_rate_a0 = nothing,
heat_rate_a1 = string(a1),
heat_rate_a2 = string(a2),
)
@test_throws IS.DataFormatError create_poly_cost(example_generator, cost_colnames)
example_generator = (name="test-gen", heat_rate_a0=string(a0), heat_rate_a1=nothing, heat_rate_a2=string(a2))
example_generator = (
name = "test-gen",
heat_rate_a0 = string(a0),
heat_rate_a1 = nothing,
heat_rate_a2 = string(a2),
)
@test_throws IS.DataFormatError create_poly_cost(example_generator, cost_colnames)

# Test that it works with zero proportional and constant term
example_generator = (name="test-gen", heat_rate_a0=string(0.0), heat_rate_a1=string(0.0), heat_rate_a2=string(a2))
example_generator = (
name = "test-gen",
heat_rate_a0 = string(0.0),
heat_rate_a1 = string(0.0),
heat_rate_a2 = string(a2),
)
cost_curve, fixed_cost = create_poly_cost(example_generator, cost_colnames)
@assert cost_curve isa QuadraticCurve
@assert isapprox(get_quadratic_term(cost_curve), a2, atol=0.01)
@assert isapprox(get_proportional_term(cost_curve), 0.0, atol=0.01)
@assert isapprox(get_constant_term(cost_curve), 0.0, atol=0.01)
@assert isapprox(get_quadratic_term(cost_curve), a2, atol = 0.01)
@assert isapprox(get_proportional_term(cost_curve), 0.0, atol = 0.01)
@assert isapprox(get_constant_term(cost_curve), 0.0, atol = 0.01)
end

0 comments on commit 6988ef6

Please sign in to comment.