Skip to content

Commit fa336ec

Browse files
committed
Make tests less sensitive to FP diffs
1 parent 0b91dbd commit fa336ec

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

inst/tests/test-stats.r

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ context("stat-sum")
5050

5151
test_that("stat_sum", {
5252
d <- diamonds[1:1000, ]
53+
all_ones <- function(x) all.equal(mean(x), 1)
5354

5455
ret <- test_stat(stat_sum(aes(x = cut, y = clarity), data = d))
5556
expect_equal(dim(ret), c(38, 5))
5657
expect_equal(sum(ret$n), nrow(d))
57-
expect_true(all(ret$prop == 1))
58+
expect_true(all_ones(ret$prop))
5859

5960
ret <- test_stat(stat_sum(aes(x = cut, y = clarity, group = 1), data = d))
6061
expect_equal(dim(ret), c(38, 5))
@@ -64,24 +65,24 @@ test_that("stat_sum", {
6465
ret <- test_stat(stat_sum(aes(x = cut, y = clarity, group = cut), data = d))
6566
expect_equal(dim(ret), c(38, 5))
6667
expect_equal(sum(ret$n), nrow(d))
67-
expect_true(all(ddply(ret, .(x), summarise, prop = sum(prop))$prop == 1))
68+
expect_true(all_ones(tapply(ret$prop, ret$x, FUN = sum)))
6869

6970
ret <- test_stat(stat_sum(aes(x = cut, y = clarity, group = cut, colour = cut), data = d))
7071
expect_equal(dim(ret), c(38, 6))
7172
expect_equal(ret$x, ret$colour)
7273
expect_equal(sum(ret$n), nrow(d))
73-
expect_true(all(ddply(ret, .(x), summarise, prop = sum(prop))$prop == 1))
74+
expect_true(all_ones(tapply(ret$prop, ret$x, FUN = sum)))
7475

7576
ret <- test_stat(stat_sum(aes(x = cut, y = clarity, group = clarity), data = d))
7677
expect_equal(dim(ret), c(38, 5))
7778
expect_equal(sum(ret$n), nrow(d))
78-
expect_true(all(ddply(ret, .(y), summarise, prop = sum(prop))$prop == 1))
79+
expect_true(all_ones(tapply(ret$prop, ret$y, FUN = sum)))
7980

8081
ret <- test_stat(stat_sum(aes(x = cut, y = clarity, group = clarity, colour = cut), data = d))
8182
expect_equal(dim(ret), c(38, 6))
8283
expect_equal(ret$x, ret$colour)
8384
expect_equal(sum(ret$n), nrow(d))
84-
expect_true(all(ddply(ret, .(y), summarise, prop = sum(prop))$prop == 1))
85+
expect_true(all_ones(tapply(ret$prop, ret$y, FUN = sum)))
8586

8687
ret <- test_stat(stat_sum(aes(x = cut, y = clarity, group = 1, weight = price), data = d))
8788
expect_equal(dim(ret), c(38, 5))

0 commit comments

Comments
 (0)