Skip to content

Commit

Permalink
Add further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkborregaard committed Sep 4, 2018
1 parent 08ab311 commit 574e2a5
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 7 deletions.
17 changes: 17 additions & 0 deletions test/Analysis_tests.jl
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/Assemblage_tests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/ComMatrix_test.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/Constructors_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using DataFrames
using CSV
using SpatialEcology
using Test

@testset "Constructors" begin
end
15 changes: 15 additions & 0 deletions test/Grid_and_points_test.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CSV
Plots
14 changes: 10 additions & 4 deletions test/Views_test.jl
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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]



Expand Down
7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 574e2a5

Please sign in to comment.