-
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.
Merge pull request #22 from rafaelbailo/main
Additional unit tests
- Loading branch information
Showing
10 changed files
with
108 additions
and
43 deletions.
There are no files selected for viewing
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
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
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,24 @@ | ||
using ConsensusBasedX, ConsensusBasedX.ConsensusBasedXLowLevel, Test | ||
|
||
function tests() | ||
x = 1 + rand() | ||
|
||
noCorrection = NoCorrection() | ||
@test noCorrection(x) == 1 | ||
@test noCorrection(-x) == 1 | ||
|
||
heavisideCorrection = HeavisideCorrection() | ||
@test heavisideCorrection(x) == 1 | ||
@test heavisideCorrection(-x) == 0 | ||
|
||
regularCorrection = RegularisedHeavisideCorrection(1e-1) | ||
sharpCorrection = RegularisedHeavisideCorrection(1e-2) | ||
@test regularCorrection(x) <= 1 | ||
@test regularCorrection(x) >= 0 | ||
@test regularCorrection(-x) <= 1 | ||
@test regularCorrection(-x) >= 0 | ||
@test regularCorrection(x) <= sharpCorrection(x) | ||
@test regularCorrection(-x) >= sharpCorrection(-x) | ||
end | ||
|
||
tests() |
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,20 @@ | ||
using ConsensusBasedX, Test | ||
|
||
function tests() | ||
alloc(x) = Base.gc_alloc_count(x.gcstats) | ||
|
||
config = (; D = 2, benchmark = true) | ||
|
||
f(x) = -ConsensusBasedX.Quadratic(x, shift = 1) | ||
@test alloc(maximise(f, config)) == 0 | ||
|
||
g(x) = -ConsensusBasedX.Ackley(x, shift = 1) | ||
@test alloc(maximise(g, config)) == 0 | ||
|
||
h(x) = -ConsensusBasedX.Rastrigin(x, shift = 1) | ||
@test alloc(maximise(h, config)) == 0 | ||
|
||
return config = (; D = 2,) | ||
end | ||
|
||
tests() |
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,40 +1,25 @@ | ||
using ConsensusBasedX, Test | ||
using ConsensusBasedX, ConsensusBasedX.ConsensusBasedXLowLevel, Test | ||
|
||
function tests() | ||
out = @test_nowarn ConsensusBasedX.parse_config((; D = 2)) | ||
@test haskey(out, :D) | ||
@test haskey(out, :N) | ||
@test haskey(out, :M) | ||
@test haskey(out, :mode) | ||
@test_throws ArgumentError parse_config(NamedTuple()) | ||
|
||
@test_nowarn ConsensusBasedX.check_config_has_D((; D = 2, N = 20)) | ||
@test_throws ArgumentError ConsensusBasedX.check_config_has_D((; N = 20)) | ||
@test_throws ArgumentError parse_config((; D = 2, mode = "wrongMode")) | ||
@test_throws ArgumentError parse_config((; D = 2, mode = :wrongMode)) | ||
@test_throws ArgumentError parse_config((; D = 2, mode = 1.0)) | ||
|
||
@test_nowarn ConsensusBasedX.parse_config_mode(NamedTuple()) | ||
@test_throws ArgumentError parse_config((; D = 2, noise = "wrongNoise")) | ||
@test_throws ArgumentError parse_config((; D = 2, noise = :wrongNoise)) | ||
@test_throws ArgumentError parse_config((; D = 2, noise = 1.0)) | ||
|
||
out = @test_nowarn ConsensusBasedX.parse_config_mode((; | ||
mode = ConsensusBasedX.ParticleMode | ||
@test_throws ArgumentError parse_config((; | ||
D = 2, | ||
parallelisation = "wrongParallelisation", | ||
)) | ||
@test out.mode isa ConsensusBasedX.TParticleMode | ||
out = @test_nowarn ConsensusBasedX.parse_config_mode((; | ||
mode = Val(:ParticleMode) | ||
)) | ||
@test out.mode isa ConsensusBasedX.TParticleMode | ||
out = @test_nowarn ConsensusBasedX.parse_config_mode((; mode = :ParticleMode)) | ||
@test out.mode isa ConsensusBasedX.TParticleMode | ||
out = | ||
@test_nowarn ConsensusBasedX.parse_config_mode((; mode = "ParticleMode")) | ||
@test out.mode isa ConsensusBasedX.TParticleMode | ||
|
||
@test_throws ArgumentError ConsensusBasedX.parse_config_mode((; | ||
mode = Val(:WrongMode) | ||
)) | ||
@test_throws ArgumentError ConsensusBasedX.parse_config_mode((; | ||
mode = :WrongMode | ||
)) | ||
@test_throws ArgumentError ConsensusBasedX.parse_config_mode((; | ||
mode = "WrongMode" | ||
@test_throws ArgumentError parse_config((; | ||
D = 2, | ||
parallelisation = :wrongParallelisation, | ||
)) | ||
@test_throws ArgumentError parse_config((; D = 2, parallelisation = 1.0)) | ||
end | ||
|
||
tests() |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using ConsensusBasedX, ConsensusBasedX.ConsensusBasedXLowLevel, Test | ||
|
||
function tests() | ||
tuple = (; a = 1, b = 2.0, c = "three") | ||
@test forced_convert_2_NamedTuple(tuple) == tuple | ||
|
||
dict = Dict(:a => 1, :b => 2.0, :c => "three") | ||
@test forced_convert_2_NamedTuple(dict) == tuple | ||
|
||
string_dict = Dict("a" => 1, "b" => 2.0, "c" => "three") | ||
@test forced_convert_2_NamedTuple(string_dict) == tuple | ||
|
||
@test_throws ArgumentError forced_convert_2_NamedTuple(values(tuple)) | ||
end | ||
|
||
tests() |
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,10 @@ | ||
using ConsensusBasedX, ConsensusBasedX.ConsensusBasedXLowLevel, Test | ||
|
||
function tests() | ||
@test get_val("string") isa String | ||
@test get_val(:symbol) isa Symbol | ||
@test get_val(Val(:val)) isa Symbol | ||
@test get_val(Val(:val)) == :val | ||
end | ||
|
||
tests() |