diff --git a/tests/test_generic_scalar_stats.R b/tests/test_generic_scalar_stats.R index 9ad6d47..9898dba 100644 --- a/tests/test_generic_scalar_stats.R +++ b/tests/test_generic_scalar_stats.R @@ -4,7 +4,7 @@ library(RUnit) # Setup wd <- "./" -# # compute.stat.scalar Tests +## compute.stat.scalar Tests climdex.pcic.test.compute.stat.scalar.mean <- function() { # Test data and dates @@ -49,6 +49,7 @@ climdex.pcic.test.compute.stat.scalar.max <- function() { checkEqualsNumeric(as.numeric(result[1]), expected_max) } + climdex.pcic.test.scalar.exact.dates <- function() { set.seed(123) @@ -78,6 +79,7 @@ climdex.pcic.test.scalar.exact.dates <- function() { "Expected exact date:", expected_max_date)) } + climdex.pcic.test.compute.stat.scalar.sum <- function() { data <- c(1, 2, 3, 4, 5) @@ -99,6 +101,7 @@ climdex.pcic.test.compute.stat.scalar.sum <- function() { msg = paste("Computed sum:", result[1], "Expected sum:", expected_sum)) } + climdex.pcic.test.compute.stat.scalar.sd <- function() { data <- c(2, 4, 6, 8, 10) @@ -119,6 +122,7 @@ climdex.pcic.test.compute.stat.scalar.sd <- function() { msg = paste("Computed SD:", result[1], "Expected SD:", expected_sd)) } + climdex.pcic.test.compute.stat.scalar.var <- function() { # Test data and dates data <- c(3, 6, 9, 12, 15) diff --git a/tests/test_generic_stat_helpers.R b/tests/test_generic_stat_helpers.R index ebc2d34..02ced16 100644 --- a/tests/test_generic_stat_helpers.R +++ b/tests/test_generic_stat_helpers.R @@ -22,6 +22,7 @@ climdex.pcic.test.convert.cartesian.to.polar <- function() { checkTrue(is.na(result_zero$direction), "Expected direction to be NA when both u and v are 0") } + climdex.pcic.test.convert.polar.to.cartesian <- function() { speed <- sqrt(2) direction <- 45 @@ -41,6 +42,7 @@ climdex.pcic.test.convert.polar.to.cartesian <- function() { } + climdex.pcic.test.convert.degrees.to.cardinal <- function() { # Test all 16 cardinal directions and boundary cases degrees <- c(0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5, 180, @@ -72,9 +74,9 @@ climdex.pcic.test.convert.cardinal.to.degrees <- function() { # Mixed-case input mixed_case_result <- convert_cardinal_to_degrees(c('n', 'Ne', 'e', 'SE', 'S', 'sW', 'W', 'nw')) checkEqualsNumeric(as.numeric(mixed_case_result), expected) - } + climdex.pcic.test.filter.by.direction.range <- function() { primary_data <- 1:10 degrees <- seq(0, 360, length.out = 10) @@ -101,6 +103,7 @@ climdex.pcic.test.filter.by.direction.range <- function() { checkEquals(filtered$degrees, expected_degrees_cross_0, "Expected filtered degrees for range crossing 0 to have NA") } + climdex.pcic.test.filter.by.direction.range.full.na <- function() { primary_data <- 1:10 degrees <- seq(0, 360, length.out = 10) # 0 40 80 120 160 200 240 280 320 360 @@ -116,6 +119,7 @@ climdex.pcic.test.filter.by.direction.range.full.na <- function() { checkEquals(filtered$degrees, expected_degrees, "Expected all degrees to be NA") } + climdex.pcic.test.compute.circular.mean <- function() { direction_degrees <- c(350, 10) # Should average to 0 degrees date.factors <- 1 @@ -131,6 +135,7 @@ climdex.pcic.test.compute.circular.mean <- function() { msg = "direction_degrees cannot be empty or NULL.") } + climdex.pcic.test.compute.circular.mean.with.na <- function() { direction_degrees <- c(350, 10, NA) # Should average to 0 degrees date.factors <- 1 @@ -140,6 +145,7 @@ climdex.pcic.test.compute.circular.mean.with.na <- function() { checkEqualsNumeric(result, expected, tolerance = 1e-6) } + climdex.pcic.test.compute.circular.sd <- function() { direction_degrees <- c(350, 10) date.factors <- 1 @@ -152,6 +158,7 @@ climdex.pcic.test.compute.circular.sd <- function() { msg = "direction_degrees cannot be empty or NULL.") } + climdex.pcic.test.compute.circular.sd.with.na <- function() { direction_degrees <- c(350, 10, NA) date.factors <- 1 diff --git a/tests/test_generic_variable_inputs.R b/tests/test_generic_variable_inputs.R index ca15687..4e47514 100644 --- a/tests/test_generic_variable_inputs.R +++ b/tests/test_generic_variable_inputs.R @@ -1,4 +1,4 @@ -climdex.pcic.test.na_masks_with_missing_data_thresholds <- function() climdex.pcic.test.na_masks_with_missing_data_thresholds <- function() { +climdex.pcic.test.na_masks_with_missing_data_thresholds <- function() { set.seed(123) speed <- runif(366, 0, 20) direction <- runif(366, 0, 360) @@ -74,7 +74,6 @@ climdex.pcic.test.na_masks_with_missing_data_thresholds <- function() climdex.pc } - climdex.pcic.test.scalar.raw.and.csv.construction <- function() { set.seed(123) @@ -112,6 +111,7 @@ climdex.pcic.test.scalar.raw.and.csv.construction <- function() { checkTrue(all.equal(scalar_obj_csv, scalar_obj_raw), msg = "Scalar_obj built from csv is not identical to raw") } + climdex.pcic.test.calendar.handling <- function() { set.seed(123) @@ -148,6 +148,7 @@ climdex.pcic.test.calendar.handling <- function() { checkTrue(!any(format(scalar_obj_noleap@dates, "%m-%d") == "02-29"), "Leap day present in no-leap calendar dates.") } + climdex.pcic.test.vector.raw.and.csv.construction <- function() { set.seed(123) @@ -259,6 +260,7 @@ climdex.pcic.test.vector.construction.validity <- function() { checkEqualsNumeric(polar_data$direction, expected_polar$direction, tolerance = 1e-6, "Direction conversion from cartesian to polar incorrect.") } + climdex.pcic.test.scalar_construction_with_malformed_inputs <- function() { # Valid data data <- c(10.5, 12.3, 11.2) @@ -313,7 +315,6 @@ climdex.pcic.test.scalar_construction_with_malformed_inputs <- function() { } - climdex.pcic.test.vector_construction_with_malformed_inputs <- function() { # Setup valid data for comparison valid_speed <- c(5, 10, 15) @@ -434,6 +435,5 @@ climdex.pcic.test.vector_construction_with_malformed_inputs <- function() { ), msg = "Error not raised for invalid calendar type." ) - } diff --git a/tests/test_generic_vector_stats.R b/tests/test_generic_vector_stats.R index 749fc66..01d7038 100644 --- a/tests/test_generic_vector_stats.R +++ b/tests/test_generic_vector_stats.R @@ -4,7 +4,7 @@ library(circular) # Setup wd <- "./" -# # compute.stat.vector Tests +## compute.stat.vector Tests # Helper function to update primary and secondary values in a vector object. Dates need to be readded to avoid data-date length mismatch. update_vector_obj <- function(base_vector_obj, primary, secondary, dates) { return(climdexGenericVector.raw( @@ -84,9 +84,6 @@ climdex.pcic.test.compute.stat.vector.circular.mean <- function() { } - - - climdex.pcic.test.compute.stat.vector.circular.sd <- function() { speed <- c(5, 5) @@ -186,6 +183,7 @@ climdex.pcic.test.compute.stat.vector.mean.magnitude <- function() { msg = paste("Result magnitude differs from expected:", result$magnitude)) } + climdex.pcic.test.compute.stat.vector.filtered.direction.range <- function() { speed <- c(5, 10, 15, 20) @@ -218,6 +216,7 @@ climdex.pcic.test.compute.stat.vector.filtered.direction.range <- function() { checkEqualsNumeric(as.numeric(result$magnitude[1]), expected_max_magnitude) } + climdex.pcic.test.compute.stat.vector.missing.values <- function() { speed <- c(5, 10, NA, 20) # One NA speed direction <- c(45, 90, 135, NA) # One NA direction @@ -247,6 +246,7 @@ climdex.pcic.test.compute.stat.vector.missing.values <- function() { msg = paste("Result magnitude differs from expected. Result:", result$magnitude)) } + climdex.pcic.test.compute.stat.vector.overlapping.years <- function() { # Full winter season (Dec-Feb) set.seed(123) @@ -280,6 +280,7 @@ climdex.pcic.test.compute.stat.vector.overlapping.years <- function() { "Expected seasonal mean:", expected_mean_speed)) } + climdex.pcic.test.compute.stat.vector.filtered.direction.crossing.360 <- function() { speed <- c(5, 10, 15, 20) direction <- c(350, 10, 135, 180) # Directions crossing the 360-degree boundary @@ -309,6 +310,7 @@ climdex.pcic.test.compute.stat.vector.filtered.direction.crossing.360 <- functio checkEqualsNumeric(as.numeric(result$magnitude[1]), expected_max_magnitude) } + climdex.pcic.test.compute.stat.vector.no.data.in.direction.range <- function() { speed <- c(5, 10, 15, 20) direction <- c(45, 90, 135, 180) @@ -338,6 +340,7 @@ climdex.pcic.test.compute.stat.vector.no.data.in.direction.range <- function() { checkTrue(is.na(result$magnitude[1]), "Expected NA result when no data is in the specified direction range.") } + climdex.pcic.test.compute.stat.vector.cartesian.format <- function() { u <- c(5, 10, 15) v <- c(5, 0, -5) # Cartesian components @@ -386,6 +389,7 @@ climdex.pcic.test.compute.stat.vector.cartesian.format <- function() { "Expected circular mean direction:", expected_circular_mean)) } + climdex.pcic.test.compute.stat.vector.cardinal.format <- function() { speed <- c(5, 10, 15) direction <- c('N', 'E', 'S') # Cardinal directions @@ -415,6 +419,7 @@ climdex.pcic.test.compute.stat.vector.cardinal.format <- function() { checkEqualsNumeric(as.numeric(result$magnitude[1]), expected_mean_speed, tolerance = 1e-6) } + climdex.pcic.test.compute.stat.vector.inverted.direction.range <- function() { speed <- c(5, 10, 15, 20) direction <- c(45, 90, 135, 180)