This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split tests & remove gitlab ci confic & add stuff to Makefile (#11)
* split the tests in multiple files * removed gitlab ci configuration * fixing code coverage in travis ci * fixing code coverage in travis ci * update code coverage ci * fixing ci * fixing ci * fixing ci * fixing ci * fixing ci * fixing ci * added more stuff to Makefile
- Loading branch information
1 parent
f4789c6
commit 2b6f32d
Showing
11 changed files
with
537 additions
and
576 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
.PHONY : docs | ||
.PHONY : docs test coverage clean | ||
|
||
docs: | ||
julia -e "using Pkg; Pkg.activate(\".\"); include(\"docs/make.jl\")" | ||
|
||
test: | ||
julia --check-bounds=yes --color=yes -e "using Pkg; Pkg.activate(\".\"); Pkg.test()" | ||
|
||
coverage: | ||
julia --check-bounds=yes --color=yes --inline=no -e "using Pkg; Pkg.activate(\".\"); Pkg.test(coverage=true)" | ||
|
||
clean: | ||
find src -name "*.jl.*.cov" -type f -delete | ||
find test -name "*.jl.*.cov" -type f -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
include("testing_base.jl") | ||
|
||
function cmp_complex_real(c_arr, r_arr) | ||
cmp_arr = Array{Bool}(undef, length(c_arr)) | ||
for i in 1:length(c_arr) | ||
cmp_arr[i] = (c_arr[i] == r_arr[2*i-1] + im*r_arr[2*i]) | ||
end | ||
all(cmp_arr) | ||
end | ||
num_real = 21 # should be an odd number | ||
@assert isodd(num_real) "test for odd numbers, too" | ||
num_complex = 3 | ||
@assert 2*num_complex <= num_real "need to get less complex number than half the real numbers" | ||
real_array = rand(num_real) | ||
complex_array = PowerDynBase.complexview(real_array, 1, 3) | ||
@test length(complex_array) == 3 | ||
@test cmp_complex_real(complex_array, real_array) | ||
complex_array[:] = rand(3) .+ im.*rand(3) | ||
@test cmp_complex_real(complex_array, real_array) | ||
real_array[:] = rand(num_real) | ||
@test cmp_complex_real(complex_array, real_array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
include("testing_base.jl") | ||
|
||
begin | ||
_removelinereferences(b) = b | ||
function _removelinereferences(b::Expr) | ||
if ~(b.head in (:block, :macrocall)) | ||
return b | ||
end | ||
b.args = [ el for el in b.args if ~(el isa LineNumberNode) ] | ||
b | ||
end | ||
removelinereferences(q::Expr) = MacroTools.postwalk( _removelinereferences , q) | ||
rlr = removelinereferences | ||
_removesingleblocks(b) = b | ||
function _removesingleblocks(b::Expr) | ||
if ~(b.head in (:block, )) || length(b.args) != 1 | ||
return b | ||
end | ||
b.args[1] | ||
end | ||
removesingleblocks(q::Expr) = MacroTools.postwalk( _removesingleblocks , q) | ||
rsb = removesingleblocks | ||
end | ||
|
||
struct_def = PowerDynBase.buildparameterstruct(:MyParams, [:p1, :p2]) | ||
struct_def_tests = :(struct MyParams <: AbstractNodeParameters | ||
p1 | ||
p2 | ||
MyParams(; p1, p2) = new(p1, p2) | ||
end) | ||
@test struct_def |> rlr == struct_def_tests |> rlr |> rsb | ||
internals = PowerDynBase.getinternalvars(Val{:OrdinaryNodeDynamics}, :([[a, da], [b, db]])) | ||
@test internals == (vars=[:a, :b], dvars=[:da, :db]) | ||
@test PowerDynBase.getinternalvars(Val{:OrdinaryNodeDynamicsWithMass}, :([[a, da], [b, db]])) == internals | ||
@test_throws NodeDynamicsError PowerDynBase.getinternalvars(Val{:unknown}, :([[a, da], [b, db]])) | ||
dynamicscall = :(OrdinaryNodeDynamicsWithMass(a=1, b=3)) | ||
funcbody = quote | ||
funcbodyline1 | ||
funcbodyline2 | ||
end | ||
prep = quote | ||
prepline1 | ||
prepline2 | ||
end | ||
cndfunction = quote | ||
function construct_node_dynamics(par::MyParams) | ||
p1 = par.p1 | ||
p2 = par.p2 | ||
prepline1 | ||
prepline2 | ||
end | ||
end |> rlr |> rsb | ||
PowerDynBase.cndfunction_builder!(Val{:OrdinaryNodeDynamicsWithMass}, | ||
internals, | ||
dynamicscall, | ||
funcbody, | ||
cndfunction) | ||
cnd_function_test = quote | ||
function construct_node_dynamics(par::MyParams) | ||
p1 = par.p1 | ||
p2 = par.p2 | ||
prepline1 | ||
prepline2 | ||
function rhs!(dint::AbstractVector, u, i, int::AbstractVector, t) | ||
a = int[1] | ||
b = int[2] | ||
funcbodyline1 | ||
funcbodyline2 | ||
try | ||
dint[1] = da | ||
dint[2] = db | ||
return du | ||
catch e | ||
if typeof(e) === UndefVarError | ||
throw(NodeDynamicsError("you need to provide $(e.var)")) | ||
else | ||
throw(e) | ||
end | ||
end | ||
end | ||
OrdinaryNodeDynamicsWithMass(a=1, b=3, rhs=rhs!, n_int=2, symbols=ODENodeSymbols([:a, :b], [:da, :db]), parameters=par) | ||
end | ||
end |> rlr |> rsb | ||
@test cndfunction |> rlr |> rsb == cnd_function_test | ||
full_macro_return = PowerDynBase.DynamicNode(:(MyParams(p1, p2) <: OrdinaryNodeDynamicsWithMass(a=1, b=3)), prep, :([[a, da], [b, db]]), funcbody ) |> rlr |> rsb | ||
full_macro_return_test = quote | ||
@__doc__ $(struct_def_tests) | ||
$(cnd_function_test) | ||
end |> rlr |> rsb | ||
@test full_macro_return == full_macro_return_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
include("testing_base.jl") | ||
|
||
@testset "OrdinaryGridDynamics" begin | ||
@syms t real=true | ||
num = 2 | ||
pars = [SwingEq(H=symbols("H_$i", positive=true), P=symbols("P_$i", real=true), D=symbols("D_$i", positive=true), Ω=symbols("Omega_$i", real=true)) for i=1:num ] | ||
dyns = construct_node_dynamics.(pars) | ||
# LY = [symbols("LY_$i$j") for i in 1:num, j in 1:num] | ||
LY = SymbolMatrix("LY", num) | ||
grid_dyn = GridDynamics(pars, LY, skip_LY_check=true) | ||
@test grid_dyn isa PowerDynBase.OrdinaryGridDynamics | ||
@test pars == grid_dyn |> Nodes .|> parametersof | ||
|
||
# evalute the grid rhs symbolically | ||
us = [symbols("u_$i") for i in 1:num ] | ||
omegas = [symbols("omega_$i",real=true) for i=1:num ] | ||
xs = [splitcomplexsymbols(us); omegas] | ||
dxs = [ | ||
[symbols("d$u")[1] for u in us]|> splitcomplexsymbols; | ||
[symbols("d$omega") for omega in omegas] | ||
] | ||
dxs_test = copy(dxs) | ||
grid_dyn(dxs, xs, nothing, t) | ||
dus = dxs[1:2*num] |> mergecomplexsymbols | ||
domegas = dxs[2*num+1:end] | ||
|
||
# Rebuild the grid rhs with the assumption that the node dynamics is working | ||
# already (as it was tested separately before). | ||
us = [symbols("u_$i") for i in 1:num ] .|> complex | ||
us_var = PowerDynBase.ODEVariable(us) | ||
omegas = [symbols("omega_$i",real=true) for i=1:num ] | ||
omegas_var = PowerDynBase.ODEVariable(omegas) | ||
t_i = LY*us | ||
map(i -> dyns[i](i, us_var, t_i, view(omegas_var, i:i), nothing), 1:num) | ||
@test all(complex.(dus) .== complex.(us_var.ddt)) # check whether the voltage differentials match | ||
@test all(complex.(domegas) .== complex.(omegas_var.ddt)) # check whether the internal differentials match | ||
end | ||
|
||
|
||
@testset "OrdinaryGridDynamicsWithMass" begin | ||
@syms t real=true | ||
swing_num = 2 | ||
pq_num = 2 | ||
num = pq_num + swing_num | ||
pars = [ | ||
[SwingEq(H=symbols("H_$i", positive=true), P=symbols("P_$i", real=true), D=symbols("D_$i", positive=true), Ω=symbols("Omega_$i", real=true)) for i=1:swing_num ]; | ||
[PQAlgebraic(S=symbols("S_$i")) for i in 1:pq_num] | ||
] | ||
dyns = construct_node_dynamics.(pars) | ||
LY = SymbolMatrix("LY", num) | ||
grid_dyn = GridDynamics(pars, LY, skip_LY_check=true) | ||
@test typeof(grid_dyn) === PowerDynBase.OrdinaryGridDynamicsWithMass | ||
@test PowerDynBase.masses(grid_dyn) == [true, true, true, true, false, false, false, false, true, true] | ||
@test pars == grid_dyn |> Nodes .|> parametersof | ||
|
||
# evalute the grid rhs symbolically | ||
dyns = convert(Array{OrdinaryNodeDynamicsWithMass}, dyns) | ||
us = [symbols("u_$i") for i in 1:num ] | ||
omegas = [symbols("omega_$i",real=true) for i=1:swing_num ] | ||
xs = [splitcomplexsymbols(us); omegas] | ||
dxs = [ | ||
[symbols("d$u")[1] for u in us]|> splitcomplexsymbols; | ||
[symbols("d$omega") for omega in omegas] | ||
] | ||
dxs_test = copy(dxs) | ||
grid_dyn(dxs, xs, nothing, t) | ||
dus = dxs[1:2*num] |> mergecomplexsymbols | ||
domegas = dxs[2*num+1:end] | ||
|
||
# Rebuild the grid rhs with the assumption that the node dynamics is working | ||
# already (as it was tested separately before). | ||
us = [symbols("u_$i") for i in 1:num ] .|> complex | ||
us_var = PowerDynBase.ODEVariable(us) | ||
omegas = [symbols("omega_$i",real=true) for i=1:swing_num ] | ||
omegas_var = PowerDynBase.ODEVariable(omegas) | ||
t_i = LY*us | ||
map(i -> dyns[i](i, us_var, t_i, view(omegas_var, i:i), nothing), 1:swing_num); | ||
map(i -> dyns[i](i, us_var, t_i, view(omegas_var,1:0), nothing), swing_num + 1:num); | ||
@test all(complex.(dus) .== complex.(us_var.ddt)) # check whether the voltage differentials match | ||
@test all(complex.(domegas) .== complex.(omegas_var.ddt)) # check whether the internal differentials match | ||
end | ||
|
||
@testset "OrdinaryGridDynamicsWithMass (numerically)" begin | ||
nodes = [SwingEq(H=1, P=1, D=1, Ω=50), SwingEq(H=1, P=-1, D=1, Ω=50)] | ||
LY = [im -im; -im im] | ||
grid = GridDynamics(nodes, LY) | ||
x = rand(SystemSize(grid)) | ||
dx = similar(x) | ||
grid(dx, x, nothing, 0) | ||
@test true # if the code runs until here, everything succeeded | ||
end |
Oops, something went wrong.