Skip to content

Commit 048471b

Browse files
committed
adding tests that parsed matpower data can be seralized to JSON
1 parent 339d488 commit 048471b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/matpower.jl

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using JSON
2+
13
@testset "test matpower parser" begin
24
@testset "30-bus case file" begin
35
result = run_opf("../test/data/case30.m", ACPPowerModel, ipopt_solver)
@@ -8,6 +10,8 @@
810

911
@testset "30-bus case matpower data" begin
1012
data = PowerModels.parse_file("../test/data/case30.m")
13+
@test isa(JSON.json(data), String)
14+
1115
result = run_opf(data, ACPPowerModel, ipopt_solver)
1216

1317
@test result["status"] == :LocalOptimal
@@ -17,6 +21,7 @@
1721
@testset "14-bus case file with names" begin
1822
data = PowerModels.parse_file("../test/data/case14.m")
1923
@test data["bus"][1]["bus_name"] == "Bus 1 HV"
24+
@test isa(JSON.json(data), String)
2025
end
2126

2227
@testset "2-bus case file with spaces" begin
@@ -56,6 +61,7 @@ end
5661
@test data["const_int"] == 123
5762
@test data["const_float"] == 4.56
5863
@test data["const_str"] == "a string"
64+
@test isa(JSON.json(data), String)
5965
end
6066

6167
@testset "3-bus extended matrix" begin
@@ -66,6 +72,7 @@ end
6672
@test data["areas"][1]["col_2"] == 1
6773
@test data["areas"][2]["col_1"] == 2
6874
@test data["areas"][2]["col_2"] == 3
75+
@test isa(JSON.json(data), String)
6976
end
7077

7178
@testset "3-bus extended named matrix" begin
@@ -76,6 +83,7 @@ end
7683
@test data["areas_named"][1]["refbus"] == 5
7784
@test data["areas_named"][2]["area"] == 5
7885
@test data["areas_named"][2]["refbus"] == 6
86+
@test isa(JSON.json(data), String)
7987
end
8088

8189
@testset "3-bus extended predefined matrix" begin
@@ -88,6 +96,7 @@ end
8896
@test data["branch"][2]["rate_p"] == 60.1
8997
@test data["branch"][3]["rate_i"] == 12
9098
@test data["branch"][3]["rate_p"] == 30
99+
@test isa(JSON.json(data), String)
91100
end
92101

93102

@@ -103,6 +112,7 @@ end
103112
@test data["areas_cells"][2]["col_2"] == 456
104113
@test data["areas_cells"][2]["col_4"] == "Slack Bus 3"
105114
@test data["areas_cells"][2]["col_5"] == 4.56
115+
@test isa(JSON.json(data), String)
106116
end
107117

108118
@testset "3-bus extended named matrix from cell" begin
@@ -119,6 +129,7 @@ end
119129
@test data["areas_named_cells"][2]["area2"] == 987
120130
@test data["areas_named_cells"][2]["refbus_name"] == "Slack Bus 3"
121131
@test data["areas_named_cells"][2]["refbus"] == 4.56
132+
@test isa(JSON.json(data), String)
122133
end
123134

124135
@testset "3-bus extended predefined matrix from cell" begin
@@ -131,6 +142,16 @@ end
131142
@test data["branch"][2]["number_id"] == 456
132143
@test data["branch"][3]["name"] == "Branch 3"
133144
@test data["branch"][3]["number_id"] == 789
145+
@test isa(JSON.json(data), String)
146+
end
147+
148+
@testset "3-bus tnep case" begin
149+
data = PowerModels.parse_file("../test/data/case3_tnep.m")
150+
151+
@test haskey(data, "ne_branch")
152+
@test data["ne_branch"][1]["f_bus"] == 1
153+
@test data["ne_branch"][1]["construction_cost"] == 1
154+
@test isa(JSON.json(data), String)
134155
end
135156
end
136157

0 commit comments

Comments
 (0)