From 7f2a913ee597ee0415d1230c371032a1903d2f81 Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Wed, 5 Feb 2020 11:10:12 +0100 Subject: [PATCH] add test for indexing with a species name --- Project.toml | 2 +- src/ComMatrix.jl | 4 ++-- test/ComMatrix_test.jl | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 6828923..ab12fc3 100644 --- a/Project.toml +++ b/Project.toml @@ -23,7 +23,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" DataFrames = "0.20" DataFramesMeta = "0.5" Distances = "0.8" -EcoBase = "0.1.0" +EcoBase = "0.1.1" RandomBooleanMatrices = "0.1" RandomNumbers = "1.4" RecipesBase = "0.7" diff --git a/src/ComMatrix.jl b/src/ComMatrix.jl index a2c5fab..1d9d2ea 100644 --- a/src/ComMatrix.jl +++ b/src/ComMatrix.jl @@ -35,10 +35,10 @@ nplaces(pd::PointData) = size(pd.coords, 1) nrecords(com::AbstractComMatrix) = _nnz(occurrences(com)) const getspecies = thingoccurrences -thingoccurrences(com::AbstractComMatrix, idx) = thingoccurrences(occurrences(com), idx) +thingoccurrences(com::AbstractComMatrix, idx) = thingoccurrences(occurrences(com), asindices(idx, thingnames(com))) const getsite = placeoccurrences -placeoccurrences(com::AbstractComMatrix, idx) = placeoccurrences(occurrences(com), idx) +placeoccurrences(com::AbstractComMatrix, idx) = placeoccurrences(occurrences(com), asindices(idx, placenames(com))) const speciesnames = thingnames thingnames(com::AbstractComMatrix) = com.speciesnames diff --git a/test/ComMatrix_test.jl b/test/ComMatrix_test.jl index 9236576..08c55e5 100644 --- a/test/ComMatrix_test.jl +++ b/test/ComMatrix_test.jl @@ -57,6 +57,7 @@ using Test @test noccupied(cmf) == 11 @test getspecies(cmb, 3) == [false, true, true, true, true, true, true, true] + @test getspecies(cmb, "species2") == [true, true, true, true, false, true, true, true] @test getspecies(cmi, 2) == [15, 15, 0, 2, 28, 99, 25, 29, 23, 90, 96, 7, 43] gcm = getspecies(cmf, 6) @test gcm[3] == 0.08724510824225518