-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip tests on windows & update version
- Loading branch information
Showing
15 changed files
with
6,521 additions
and
6,487 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,73 @@ | ||
context("'Base sizes' in cubes") | ||
|
||
all.dims <- list( | ||
Admit = c("Admitted", "Rejected"), | ||
Gender = c("Male", "Female") | ||
) | ||
# Skip tests on windows (because they're slow and CRAN complains) | ||
if (tolower(Sys.info()[["sysname"]]) != "windows") { | ||
|
||
cube <- loadCube("cubes/admit-by-gender-weighted.json") | ||
b <- cubify( | ||
1198, 557, | ||
1493, 1278, | ||
dims = all.dims | ||
) | ||
test_that("'bases' can be accessed and all margins work", { | ||
expect_identical( | ||
round(cube), | ||
cubify( | ||
1170, 547, | ||
1474, 1261, | ||
dims = all.dims | ||
) | ||
all.dims <- list( | ||
Admit = c("Admitted", "Rejected"), | ||
Gender = c("Male", "Female") | ||
) | ||
expect_identical(bases(cube, 0), b) | ||
expect_identical(bases(cube, 1), margin.table(b, 1)) | ||
expect_identical(bases(cube, 2), margin.table(b, 2)) | ||
expect_identical(bases(cube), sum(b)) | ||
}) | ||
|
||
with_mock_crunch({ | ||
ds <- cachedLoadDataset("test ds") | ||
m <- multitables(ds)[[1]] | ||
with_POST("https://app.crunch.io/api/datasets/1/multitables/apidocs-tabbook/", { | ||
book1 <- tabBook(m, data = ds, output_format = "json") | ||
}) | ||
|
||
test_that("bases methods exist for TabBookResult and MultitableResult", { | ||
cube <- loadCube("cubes/admit-by-gender-weighted.json") | ||
b <- cubify( | ||
1198, 557, | ||
1493, 1278, | ||
dims = all.dims | ||
) | ||
test_that("'bases' can be accessed and all margins work", { | ||
expect_identical( | ||
bases(book1, 0)[[1]][[2]], | ||
round(cube), | ||
cubify( | ||
4, 0, 1, | ||
0, 5, 3, | ||
1, 3, 5, | ||
dims = list( | ||
allpets = c("Cat", "Dog", "Bird"), | ||
allpets = c("Cat", "Dog", "Bird") | ||
) | ||
1170, 547, | ||
1474, 1261, | ||
dims = all.dims | ||
) | ||
) | ||
expect_identical( | ||
bases(book1)[[1]][[2]], | ||
cubify( | ||
17, | ||
dims = list( | ||
allpets = c("Cat", "Dog", "Bird"), | ||
allpets = c("Cat", "Dog", "Bird") | ||
expect_identical(bases(cube, 0), b) | ||
expect_identical(bases(cube, 1), margin.table(b, 1)) | ||
expect_identical(bases(cube, 2), margin.table(b, 2)) | ||
expect_identical(bases(cube), sum(b)) | ||
}) | ||
|
||
with_mock_crunch({ | ||
ds <- cachedLoadDataset("test ds") | ||
m <- multitables(ds)[[1]] | ||
with_POST("https://app.crunch.io/api/datasets/1/multitables/apidocs-tabbook/", { | ||
book1 <- tabBook(m, data = ds, output_format = "json") | ||
}) | ||
|
||
test_that("bases methods exist for TabBookResult and MultitableResult", { | ||
expect_identical( | ||
bases(book1, 0)[[1]][[2]], | ||
cubify( | ||
4, 0, 1, | ||
0, 5, 3, | ||
1, 3, 5, | ||
dims = list( | ||
allpets = c("Cat", "Dog", "Bird"), | ||
allpets = c("Cat", "Dog", "Bird") | ||
) | ||
) | ||
) | ||
) | ||
}) | ||
expect_identical( | ||
bases(book1)[[1]][[2]], | ||
cubify( | ||
17, | ||
dims = list( | ||
allpets = c("Cat", "Dog", "Bird"), | ||
allpets = c("Cat", "Dog", "Bird") | ||
) | ||
) | ||
) | ||
}) | ||
|
||
test_that("base for univariate stats", { | ||
skip("Need to use `cube_valid_count` to calculate base size") | ||
expect_equal(bases(crtabs(max(birthyr) ~ 1, data = ds)), 25) | ||
expect_error(bases(crtabs(max(birthyr) ~ 1, data = ds), 1), | ||
"Margin 1 exceeds Cube's number of dimensions (0)", | ||
fixed = TRUE | ||
) | ||
test_that("base for univariate stats", { | ||
skip("Need to use `cube_valid_count` to calculate base size") | ||
expect_equal(bases(crtabs(max(birthyr) ~ 1, data = ds)), 25) | ||
expect_error(bases(crtabs(max(birthyr) ~ 1, data = ds), 1), | ||
"Margin 1 exceeds Cube's number of dimensions (0)", | ||
fixed = TRUE | ||
) | ||
}) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.