library(testthat) library(dmPack) # Test for miss_count function test_that("miss_count returns correct missing value counts", { test_data <- data.frame(a = c(1, NA, 3), b = c(4, 5, NA)) result <- miss_count(test_data) expect_equal(result, c(a = 1, b = 1)) # 1 missing value in each column }) # Test for show_miss function test_that("show_miss identifies rows with missing data correctly", { test_data <- data.frame(id = 1:3, value = c(1, NA, 3)) result <- show_miss(test_data, value) expect_equal(result, test_data[2, ]) # Only row 2 has a missing value in 'value' }) # Test for show_dup function test_that("show_dup identifies duplicate values correctly", { test_data <- data.frame(id = c(1, 2, 2, 4), value = c(1, 2, 2, 4)) result <- show_dup(test_data, value) expect_equal(result, test_data[2:3, ]) # Rows 2 and 3 are duplicates }) # Test for show_out function (Basic method) test_that("show_out identifies outliers based on lower and upper limits", { test_data <- data.frame(id = 1:5, value = c(1, 2, 3, 100, -50)) result <- show_out(test_data, value, lower = 0, upper = 10) expect_equal(result, test_data[c(4, 5), ]) # Values 100 and -50 are outliers }) # Test for show_out_iqr function (IQR method) test_that("show_out_iqr identifies outliers using IQR method", { test_data <- data.frame(id = 1:5, value = c(1, 2, 3, 100, -50)) result <- show_out_iqr(test_data, value) expect_equal(result, test_data[c(4, 5), ]) # 100 and -50 are outliers by IQR })