Merge pull request #3182 from ThatcherC/component-tests

WIP: Units Tests and Code Coverage for src/components.jl
This commit is contained in:
Daniel Schwabeneder 2020-12-07 16:03:47 +01:00 committed by GitHub
commit 4c95ca5089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -31,6 +31,7 @@ end # testset
include("test_defaults.jl") include("test_defaults.jl")
include("test_axes.jl") include("test_axes.jl")
include("test_axis_letter.jl") include("test_axis_letter.jl")
include("test_components.jl")
include("test_recipes.jl") include("test_recipes.jl")
include("test_hdf5plots.jl") include("test_hdf5plots.jl")
include("test_pgfplotsx.jl") include("test_pgfplotsx.jl")

46
test/test_components.jl Normal file
View File

@ -0,0 +1,46 @@
using Plots, Test
@testset "Shape Copy" begin
square = Shape([(0,0),(1,0),(1,1),(0,1)])
square2 = Shape(square)
@test square2.x == square.x
@test square2.y == square.y
end
@testset "Shape Center" begin
square = Shape([(0,0),(1,0),(1,1),(0,1)])
@test Plots.center(square) == (0.5,0.5)
end
@testset "Shape Translate" begin
square = Shape([(0,0),(1,0),(1,1),(0,1)])
squareUp = Shape([(0,1),(1,1),(1,2),(0,2)])
squareUpRight = Shape([(1,1),(2,1),(2,2),(1,2)])
@test Plots.translate(square,0,1).x == squareUp.x
@test Plots.translate(square,0,1).y == squareUp.y
@test Plots.center(translate!(square,1)) == (1.5,1.5)
end
@testset "Brush" begin
@testset "Colors" begin
baseline = brush(1, RGB(0,0,0))
@test brush(:black) == baseline
@test brush("black") == baseline
end
@testset "Weight" begin
@test brush(10).size == 10
@test brush(0.1).size == 1
end
@testset "Alpha" begin
@test brush(0.4).alpha == 0.4
@test brush(20).alpha == nothing
end
@testset "Bad Argument" begin
# using test_logs because test_warn seems to not work anymore
@test_logs (:warn,"Unused brush arg: nothing (Nothing)") begin
brush(nothing)
end
end
end