-
Notifications
You must be signed in to change notification settings - Fork 2
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 #3 from awesome-spectral-indices/fm/tests
Testing
- Loading branch information
Showing
8 changed files
with
116 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "SpectralIndices" | ||
uuid = "df0093a1-273d-40bc-819a-796ec3476907" | ||
authors = ["MartinuzziFrancesco <[email protected]>"] | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
|
||
[deps] | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
|
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,31 @@ | ||
using SpectralIndices, Dates | ||
|
||
custom_index = Dict( | ||
"short_name" => "CI", | ||
"long_name" => "Custom Index", | ||
"bands" => ["C", "I"], | ||
"application_domain" => "Vegetation", | ||
"reference" => "Doe et al., 1984", | ||
"formula" => "(C - I) / (C + I)", | ||
"date_of_addition" => "1984-01-01", | ||
"contributor" => "John Doe", | ||
"platforms" => ["Landsat 8", "MODIS"], | ||
) | ||
si = SpectralIndex(custom_index) | ||
@test si.short_name == "CI" | ||
@test si.long_name == "Custom Index" | ||
@test si.bands == ["C", "I"] | ||
@test si.application_domain == "Vegetation" | ||
@test si.reference == "Doe et al., 1984" | ||
@test si.formula == "(C-I)/(C+I)" | ||
@test si.date_of_addition == Dates.Date("1984-01-01") | ||
@test si.contributor == "John Doe" | ||
@test si.platforms == ["Landsat 8", "MODIS"] | ||
|
||
computed_index = si(0.6, 0.2) | ||
@test computed_index ≈ 0.5 atol = 0.01 | ||
|
||
C_vals = fill(0.6, 5) | ||
I_vals = fill(0.2, 5) | ||
computed_array_index = si.(C_vals, I_vals) | ||
@test all(computed_array_index .≈ 0.5) |
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,18 @@ | ||
using SpectralIndices | ||
|
||
expected_ndvi_value_f64 = 0.5721271393643031 | ||
expected_savi_value_f64 = 0.5326251896813354 | ||
|
||
# Basics | ||
@test compute_index("NDVI"; N=0.643, R=0.175) == expected_ndvi_value_f64 | ||
# Type handling | ||
@test compute_index("NDVI"; N=fill(0.643, 5), R=fill(0.175, 5)) isa Array | ||
# Corner cases | ||
#@test compute_index("NDVI"; N=0.0, R=0.0) == NaN | ||
#Input validation | ||
@test_throws AssertionError compute_index("InvalidIndex"; N=0.5, R=0.5) | ||
# Multiple indices | ||
results = compute_index(["NDVI", "SAVI"]; N=0.643, R=0.175, L=0.5) | ||
@test length(results) == 2 | ||
@test results[1] == expected_ndvi_value_f64 # Replace with correct value | ||
@test results[2] == expected_savi_value_f64 # Replace with correct value |
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 +1,14 @@ | ||
using SafeTestsets | ||
using Test | ||
|
||
@testset "Axioms" begin | ||
@safetestset "Axioms" begin | ||
include("axioms.jl") | ||
end | ||
@safetestset "Compute" begin | ||
include("compute.jl") | ||
end | ||
@safetestset "Utils" begin | ||
include("utils.jl") | ||
end | ||
end |
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,33 @@ | ||
using SpectralIndices | ||
|
||
# Test correctness | ||
@test SpectralIndices._load_json("spectral-indices-dict.json") isa Dict | ||
# Test missing | ||
@test_throws ErrorException SpectralIndices._load_json("non_existing_file.json") | ||
|
||
# Test offline | ||
@test SpectralIndices._get_indices() isa Dict | ||
# Test online | ||
@test SpectralIndices._get_indices(true) isa Dict | ||
|
||
params = Dict("N" => 0.6, "R" => 0.3) | ||
# Test correctness | ||
@test SpectralIndices._check_params(NDVI, params) === nothing | ||
# Test missing | ||
@test_throws ArgumentError SpectralIndices._check_params(NDVI, Dict("N" => 0.6)) | ||
|
||
locals = Dict("x" => 2, "y" => 3) | ||
expression = "x + y" | ||
|
||
# Test correct evaluation | ||
@test SpectralIndices.parse_eval_dict(expression, locals) == 5 | ||
|
||
name = "test_func" | ||
expr = :(x + y) | ||
args = (:x, :y) | ||
|
||
# Create a test function | ||
test_func = SpectralIndices._build_function(name, expr, args...) | ||
|
||
# Test the created function | ||
@test test_func(2, 3) == 5 |
7648c8b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
7648c8b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/96950
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: