From 574e2a5eec107014996363cfbe9f6db2a565115b Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Wed, 5 Sep 2018 01:16:52 +0200 Subject: [PATCH] Add further tests --- test/Analysis_tests.jl | 17 +++++++++++++++++ test/Assemblage_tests.jl | 4 ++++ test/ComMatrix_test.jl | 5 +++++ test/Constructors_test.jl | 7 +++++++ test/Grid_and_points_test.jl | 15 +++++++++++++++ test/REQUIRE | 1 + test/Views_test.jl | 14 ++++++++++---- test/runtests.jl | 7 ++++--- 8 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 test/Analysis_tests.jl create mode 100644 test/Constructors_test.jl create mode 100644 test/Grid_and_points_test.jl diff --git a/test/Analysis_tests.jl b/test/Analysis_tests.jl new file mode 100644 index 0000000..4d98fbc --- /dev/null +++ b/test/Analysis_tests.jl @@ -0,0 +1,17 @@ +using DataFrames +using CSV +using SpatialEcology +using Test +using Plots + +@testset "Analysis" begin + amphdat = CSV.read(joinpath(dirname(pathof(SpatialEcology)), "..", "data", "amph_Europe.csv")) + amph = Assemblage(amphdat[4:end], amphdat[1:3], sitecolumns = false) + addtraits!(amph, asquantiles(occupancy(amph), 4), :quantile) + gb = groupspecies(amph, :quantile) + ps = [plot(g) for g in gb] + p = ps[4]; + + @test p[1][1][:seriestype] == :heatmap + @test p[1][1][:z].surf[30,30] == 5.0 +end diff --git a/test/Assemblage_tests.jl b/test/Assemblage_tests.jl index a05fb48..5ddba18 100644 --- a/test/Assemblage_tests.jl +++ b/test/Assemblage_tests.jl @@ -1,10 +1,14 @@ using DataFrames using CSV +using SpatialEcology +using Test @testset "Assemblage" begin amphdat = CSV.read(joinpath(dirname(pathof(SpatialEcology)), "..", "data", "amph_Europe.csv")) amph = Assemblage(amphdat[4:end], amphdat[1:3], sitecolumns = false) + @test typeof(amph) == Assemblage{SpatialEcology.GridData,Bool} + # accesseors @test extrema(richness(amph)) == (1, 20) @test nsites(amph) == 1010 diff --git a/test/ComMatrix_test.jl b/test/ComMatrix_test.jl index 477b6b9..9858edf 100644 --- a/test/ComMatrix_test.jl +++ b/test/ComMatrix_test.jl @@ -1,6 +1,11 @@ using SparseArrays +using Random +using SpatialEcology +using Test @testset "ComMatrix" begin + Random.seed!(1337) + datb = sprand(Bool, 12,8,0.9) dati = sprand(8,13,0.9).*100 diff --git a/test/Constructors_test.jl b/test/Constructors_test.jl new file mode 100644 index 0000000..28084f0 --- /dev/null +++ b/test/Constructors_test.jl @@ -0,0 +1,7 @@ +using DataFrames +using CSV +using SpatialEcology +using Test + +@testset "Constructors" begin +end diff --git a/test/Grid_and_points_test.jl b/test/Grid_and_points_test.jl new file mode 100644 index 0000000..66ec12b --- /dev/null +++ b/test/Grid_and_points_test.jl @@ -0,0 +1,15 @@ +using SpatialEcology +using Random +using Test + +@testset "Grid" begin + gr = SpatialEcology.creategrid([repeat(20.5 .+ (1:5), inner = 4) repeat(-30.5 .+ (2:2:8), outer = 5)]) + @test xmin(gr) == 21.5 + @test ymin(gr) == -28.5 + @test cellsize(gr) == (1.0, 2.0) + @test cells(gr) == (5, 4) + @test xrange(gr) == 21.5:1.0:25.5 + @test yrange(gr) == -28.5:2.0:-22.5 + @test boundingbox(gr).xmin == xmin(gr) + @test sprint(show, boundingbox(gr)) == "xmin:\t21.5\nxmax:\t25.5\nymin:\t-28.5\nymax:\t-22.5\n" +end diff --git a/test/REQUIRE b/test/REQUIRE index cf31fd0..9ed8e23 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1 +1,2 @@ CSV +Plots diff --git a/test/Views_test.jl b/test/Views_test.jl index ead94a6..4338064 100644 --- a/test/Views_test.jl +++ b/test/Views_test.jl @@ -1,12 +1,16 @@ +using Random +using Test +using SpatialEcology +using DataFrames +using SparseArrays @testset "Views" begin + Random.seed!(1337) + datf = sprand(11,9,0.6) datf./=SpatialEcology.colsum(datf) com = ComMatrix(datf) - amphdat = CSV.read(joinpath(dirname(pathof(SpatialEcology)), "..", "data", "amph_Europe.csv")) - amph = Assemblage(amphdat[4:end], amphdat[1:3], sitecolumns = false) - vcom = view(com, species = [1,2,3,5,7,8], sites = [2,3,6,8,9]) comc = copy(vcom) @@ -22,10 +26,12 @@ @test nrecords(vcom) == nrecords(comc) @test size(vcom) == size(comc) @test cooccurring(vcom, 1,3,4) == cooccurring(comc, [1,3,4]) - @test cooccurring(vcom, 1:3) == [false, true, false, true, false] + @test cooccurring(vcom, 3:5) == [false, true, false, true, false] @test SpatialEcology.asindices(1:5) == 1:5 @test SpatialEcology.asindices([1,2,4]) == [1,2,4] + @test SpatialEcology.asindices(1:3, 2:4) == 1:3 + @test SpatialEcology.asindices(["a", "c"], ["a", "b", "c"]) == [1,3] diff --git a/test/runtests.jl b/test/runtests.jl index 13493c1..259547b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ -using SpatialEcology -using Test include("ComMatrix_test.jl") -include("Assemblage_tests.jl") +#include("Constructors_test.jl") +include("Grid_and_points_test.jl") include("Views_test.jl") +include("Assemblage_tests.jl") +include("Analysis_tests.jl")