tests/testthat/test-gm_expected_patterns_tbl_df.R

# NeuroDataSets - A Comprehensive Collection of Neuroscience and Brain-Related Datasets
# Version 0.1.0
# Copyright (C) 2025 Renzo Caceres Rossi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# gm_expected_patterns_tbl_df

library(testthat)

# Test 1: Verify Tibble Structure and Class
test_that("gm_expected_patterns_tbl_df is a tibble with correct class", {
  expect_s3_class(gm_expected_patterns_tbl_df, "tbl_df")
  expect_s3_class(gm_expected_patterns_tbl_df, "tbl")
  expect_s3_class(gm_expected_patterns_tbl_df, "data.frame")
})

# Test 2: Validate Dimensions
test_that("gm_expected_patterns_tbl_df has correct dimensions", {
  expect_equal(nrow(gm_expected_patterns_tbl_df), 33)
  expect_equal(ncol(gm_expected_patterns_tbl_df), 16)
})

# Test 3: Check Column Names and Types
test_that("Column names and types are correct", {
  expected_names <- c(
    "GM", "SSD", "MDD", "AD_ADNI", "AD_ADNIOSYRIX", "BD", "PD",
    "Diabetes", "HighBP", "HighLipids", "MET", "DS_22q",
    "Suicide", "OCD_pediatric", "OCD_adult", "AN"
  )
  expect_named(gm_expected_patterns_tbl_df, expected_names)

  expect_type(gm_expected_patterns_tbl_df$GM, "character")
  expect_type(gm_expected_patterns_tbl_df$SSD, "double")
  expect_type(gm_expected_patterns_tbl_df$MDD, "double")
  expect_type(gm_expected_patterns_tbl_df$AD_ADNI, "double")
  expect_type(gm_expected_patterns_tbl_df$AD_ADNIOSYRIX, "double")
  expect_type(gm_expected_patterns_tbl_df$BD, "double")
  expect_type(gm_expected_patterns_tbl_df$PD, "double")
  expect_type(gm_expected_patterns_tbl_df$Diabetes, "double")
  expect_type(gm_expected_patterns_tbl_df$HighBP, "double")
  expect_type(gm_expected_patterns_tbl_df$HighLipids, "double")
  expect_type(gm_expected_patterns_tbl_df$MET, "double")
  expect_type(gm_expected_patterns_tbl_df$DS_22q, "double")
  expect_type(gm_expected_patterns_tbl_df$Suicide, "double")
  expect_type(gm_expected_patterns_tbl_df$OCD_pediatric, "double")
  expect_type(gm_expected_patterns_tbl_df$OCD_adult, "double")
  expect_type(gm_expected_patterns_tbl_df$AN, "double")
})

# Test 4: Verify GM Column Uniqueness (if applicable)
test_that("GM column contains unique values", {
  expect_equal(length(unique(gm_expected_patterns_tbl_df$GM)), nrow(gm_expected_patterns_tbl_df))
})

# Test 5: Content Validation (Non-modifying checks)
test_that("Numeric columns contain valid values", {
  numeric_cols <- setdiff(names(gm_expected_patterns_tbl_df), "GM")
  for (col in numeric_cols) {
    expect_true(all(is.na(gm_expected_patterns_tbl_df[[col]]) |
                      is.numeric(gm_expected_patterns_tbl_df[[col]])))
  }
})

# Test 6: No Unexpected NA Patterns (if applicable)
test_that("No unexpected all-NA columns", {
  na_counts <- colSums(is.na(gm_expected_patterns_tbl_df))
  expect_false(any(na_counts == nrow(gm_expected_patterns_tbl_df)))
})

Try the NeuroDataSets package in your browser

Any scripts or data that you put into this service are public.

NeuroDataSets documentation built on June 8, 2025, 11:46 a.m.