|
1 | | -.onLoad() |
| 1 | +test_that("boolean ops return probabilities", { |
| 2 | + xval <- 1:2 |
| 3 | + xerr <- c(0, 1) |
| 4 | + x1 <- set_errors(xval, xerr) |
| 5 | + x2 <- set_errors(xval, xerr) |
| 6 | + y1 <- x1 + 1 |
| 7 | + y2 <- set_errors(xval+1, xerr) |
2 | 8 |
|
3 | | -test_that("bolean ops throw a warning once", { |
4 | | - xval <- 1 |
5 | | - x <- set_errors(xval, 1) |
| 9 | + old <- options(errors.compare.probabilistic = TRUE) |
| 10 | + on.exit(do.call(options, old), TRUE) |
6 | 11 |
|
7 | | - expect_warning(expect_equal(!x, !xval)) |
8 | | - expect_silent(expect_equal(!x, !xval)) |
9 | | - options(errors.warn.bool = TRUE) |
10 | | - expect_warning(expect_equal(x & x, xval & xval)) |
11 | | - expect_silent(expect_equal(x & x, xval & xval)) |
12 | | - options(errors.warn.bool = TRUE) |
13 | | - expect_warning(expect_equal(x | x, xval | xval)) |
14 | | - expect_silent(expect_equal(x | x, xval | xval)) |
15 | | - options(errors.warn.bool = TRUE) |
16 | | - expect_warning(expect_equal(x == x, xval == xval)) |
17 | | - expect_silent(expect_equal(x == x, xval == xval)) |
18 | | - options(errors.warn.bool = TRUE) |
19 | | - expect_warning(expect_equal(x != x, xval != xval)) |
20 | | - expect_silent(expect_equal(x != x, xval != xval)) |
21 | | - options(errors.warn.bool = TRUE) |
22 | | - expect_warning(expect_equal(x < x, xval < xval)) |
23 | | - expect_silent(expect_equal(x < x, xval < xval)) |
24 | | - options(errors.warn.bool = TRUE) |
25 | | - expect_warning(expect_equal(x > x, xval > xval)) |
26 | | - expect_silent(expect_equal(x > x, xval > xval)) |
27 | | - options(errors.warn.bool = TRUE) |
28 | | - expect_warning(expect_equal(x <= x, xval <= xval)) |
29 | | - expect_silent(expect_equal(x <= x, xval <= xval)) |
30 | | - options(errors.warn.bool = TRUE) |
31 | | - expect_warning(expect_equal(x >= x, xval >= xval)) |
32 | | - expect_silent(expect_equal(x >= x, xval >= xval)) |
| 12 | + # uncorrelated equal |
| 13 | + expect_equal(x1 < x2, c(0, 0.5)) |
| 14 | + expect_equal(x1 > x2, c(0, 0.5)) |
| 15 | + expect_equal(x1 <= x2, c(1, 0.5)) |
| 16 | + expect_equal(x1 >= x2, c(1, 0.5)) |
| 17 | + expect_equal(x1 == x2, c(TRUE, FALSE)) |
| 18 | + expect_equal(x1 != x2, c(FALSE, TRUE)) |
| 19 | + |
| 20 | + # uncorrelated different |
| 21 | + expect_equal(x1 < y2, c(1, 0.7602499), tolerance=1e-6) |
| 22 | + expect_equal(x1 > y2, c(0, 1 - 0.7602499), tolerance=1e-6) |
| 23 | + expect_equal(x1 <= y2, c(1, 0.7602499), tolerance=1e-6) |
| 24 | + expect_equal(x1 >= y2, c(0, 1 - 0.7602499), tolerance=1e-6) |
| 25 | + expect_equal(x1 == y2, c(FALSE, FALSE)) |
| 26 | + expect_equal(x1 != y2, c(TRUE, TRUE)) |
| 27 | + |
| 28 | + # correlated equal |
| 29 | + expect_equal(x1 < x1, c(0, 0)) |
| 30 | + expect_equal(x1 > x1, c(0, 0)) |
| 31 | + expect_equal(x1 <= x1, c(1, 1)) |
| 32 | + expect_equal(x1 >= x1, c(1, 1)) |
| 33 | + expect_equal(x1 == x1, c(TRUE, TRUE)) |
| 34 | + expect_equal(x1 != x1, c(FALSE, FALSE)) |
| 35 | + |
| 36 | + # correlated different |
| 37 | + expect_equal(x1 < y1, c(1, 1)) |
| 38 | + expect_equal(x1 > y1, c(0, 0)) |
| 39 | + expect_equal(x1 <= y1, c(1, 1)) |
| 40 | + expect_equal(x1 >= y1, c(0, 0)) |
| 41 | + expect_equal(x1 == y1, c(FALSE, FALSE)) |
| 42 | + expect_equal(x1 != y1, c(TRUE, TRUE)) |
| 43 | + |
| 44 | + # not allowed |
| 45 | + expect_error(!x1, "not allowed") |
| 46 | + expect_error(x1 & x1, "not allowed") |
| 47 | + expect_error(x1 | x1, "not allowed") |
33 | 48 | }) |
34 | 49 |
|
35 | | -test_that("ops with numerics throw a warning", { |
36 | | - x <- set_errors(1, 1) |
| 50 | +test_that("numerics are treated as numbers with no uncertainty", { |
| 51 | + xval <- 1:10 |
| 52 | + xerr <- seq(0.005, 0.05, 0.005) |
| 53 | + x <- set_errors(xval, xerr) |
37 | 54 |
|
38 | | - expect_warning(1 + x) |
39 | | - expect_silent(1 + x) |
40 | | - options(errors.warn.coercion = TRUE) |
41 | | - expect_warning(x + 1) |
42 | | - expect_silent(x + 1) |
| 55 | + expect_equal(1 + x, set_errors(1 + xval, xerr)) |
| 56 | + expect_equal(x + 1, set_errors(xval + 1, xerr)) |
43 | 57 | }) |
44 | 58 |
|
45 | 59 | test_that("ops work properly", { |
|
0 commit comments