diff --git a/cran-comments.md b/cran-comments.md index 22c4e66..458944f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,10 @@ +# twdtw-1.1-0 + +* Implements twdtw-knn1 + +* Adds larger test set + + # twdtw-1.0-1 * Fixes error: diff --git a/inst/sits/modis_mod13q1_999ts.rds b/inst/sits/modis_mod13q1_999ts.rds new file mode 100644 index 0000000..4d339c7 Binary files /dev/null and b/inst/sits/modis_mod13q1_999ts.rds differ diff --git a/inst/sits/modis_mod13q1_patterns.rds b/inst/sits/modis_mod13q1_patterns.rds new file mode 100644 index 0000000..101214a Binary files /dev/null and b/inst/sits/modis_mod13q1_patterns.rds differ diff --git a/inst/sits/modis_mod13q1_results.rds b/inst/sits/modis_mod13q1_results.rds new file mode 100644 index 0000000..93166db Binary files /dev/null and b/inst/sits/modis_mod13q1_results.rds differ diff --git a/tests/testthat/test-twdtw_knn1.R b/tests/testthat/test-twdtw_knn1.R new file mode 100644 index 0000000..267719e --- /dev/null +++ b/tests/testthat/test-twdtw_knn1.R @@ -0,0 +1,20 @@ +ts_x <- readRDS(system.file("sits/modis_mod13q1_999ts.rds", package = "twdtw")) +ts_y <- readRDS(system.file("sits/modis_mod13q1_patterns.rds", package = "twdtw")) +expected_vector <- readRDS(system.file("sits/modis_mod13q1_results.rds", package = "twdtw")) + +test_that("Nearest neighbor calculation is correct", { + # Compute TWDTW distances + distances <- sapply(ts_y[[2]], function(pattern) { + sapply(ts_x[[3]], function(ts) { + twdtw(x = as.data.frame(ts), y = as.data.frame(pattern), cycle_length = 'year', time_scale = 'day', time_weight = c(steepness = 0.1, midpoint = 50)) + }) + }) + + # Find the nearest neighbor for each observation in newdata + nearest_neighbor <- apply(distances, 1, which.min) + + # Test if nearest_neighbor is equal to the expected vector + expect_equal(nearest_neighbor, expected_vector) +}) + +