Skip to content

Commit

Permalink
Merge pull request #4 from kylehamilton/tests
Browse files Browse the repository at this point in the history
Updated data testing. Data testing now checks md5 hash, data dimensions, and data types.
  • Loading branch information
kylehamilton authored Sep 15, 2019
2 parents 73c78ae + 4eed30b commit 6bd7378
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
8 changes: 5 additions & 3 deletions tests/testthat/test_analysis_example_bangertdrowns2004.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
context("test-dat.bangertdrowns2004.R")
library(metadat)
context("Checking analysis example: bangertdrowns2004")

library(metafor)
source("tolerances.r") # read in tolerances


### copy data into 'dat' and examine data
dat <- dat.bangertdrowns2004
Expand All @@ -14,7 +16,7 @@ test_that("Returns rma object", {
expect_is(res, "rma.uni")
})

test_that("Checks rma results", {
test_that("results are correct for the random-effects model.", {
expect_identical(round(res$k, digits = 2), 48)
expect_identical(round(as.numeric(res$beta[,1]), digits = 7), 0.2219296)
expect_identical(round(as.numeric(res$tau2), digits = 7), 0.0499411)
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test_analysis_example_barone2019.r
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
context("test-dat.barone2019.R")
context("Checking analysis example: barone2019")

library(metadat)
library(metafor)

## Make copy of dataset
dat <- dat.barone2019
dat <- metadat::dat.barone2019

# First model
res <- rma(yi=logit.p., sei = sei, data=dat, slab = paste(Author, Year))
Expand All @@ -13,7 +14,7 @@ test_that("Returns rma object", {
expect_is(res, "rma.uni")
})

test_that("Checks rma results", {
test_that("results are correct for the random-effects model.", {
expect_identical(round(res$k, digits = 2), 56)
expect_identical(round(as.numeric(res$beta[,1]), digits = 7), 0.5662584)
expect_identical(round(as.numeric(res$tau2), digits = 7), 0.4949573)
Expand Down
43 changes: 43 additions & 0 deletions tests/testthat/test_data_barone2019.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
context("Checking data: barone2019")

library(metadat)
library(metafor)
library(digest)

## Make copy of dataset
dat <- metadat::dat.barone2019

test_that("checks data md5 hash", {
expect_match(digest(metadat::dat.barone2019, algo = "md5"), "44d1bfc0b736fc8c3846af9e0d81694b")
})

test_that('data dimensions are correct', {
expect_equal(ncol(dat), 22)
expect_equal(nrow(dat), 56)
})

test_that('data types are correct', {
expect_is(dat, 'data.frame')
expect_is(dat$id, 'character')
expect_is(dat$Author, 'character')
expect_is(dat$Year, 'integer')
expect_is(dat$Paradigm, 'character')
expect_is(dat$Measure, 'character')
expect_is(dat$Age_months, 'numeric')
expect_is(dat$n, 'integer')
expect_is(dat$Dropped_participants, 'integer')
expect_is(dat$Dropped_participants_corrected, 'integer')
expect_is(dat$Familiarization, 'integer')
expect_is(dat$Belief, 'character')
expect_is(dat$Agent, 'character')
expect_is(dat$Target_object_Presence, 'character')
expect_is(dat$Object_movements, 'integer')
expect_is(dat$Motive_transformation, 'character')
expect_is(dat$Salience_of_agents_MS, 'character')
expect_is(dat$Interaction, 'character')
expect_is(dat$Design, 'character')
expect_is(dat$Test_trials, 'integer')
expect_is(dat$logit.p., 'numeric')
expect_is(dat$vlogit.p., 'numeric')
expect_is(dat$sei, 'numeric')
})

0 comments on commit 6bd7378

Please sign in to comment.