Skip to content

Commit

Permalink
add fcase tests (#4796)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle authored Nov 3, 2020
1 parent 68f6aca commit 70b6b13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

2. `as.Date.IDate` is no longer exported as a function to solve a new error in R-devel `S3 method lookup found 'as.Date.IDate' on search path`, [#4777](https://github.com/Rdatatable/data.table/issues/4777). The S3 method is still exported; i.e. `as.Date(x)` will still invoke the `as.Date.IDate` method when `x` is class `IDate`. The function had been exported, in addition to exporting the method, to solve a compatibility issue with `zoo` (and `xts` which uses `zoo`) because `zoo` exports `as.Date` which masks `base::as.Date`. Happily, since zoo 1.8-1 (Jan 2018) made a change to its `as.IDate`, the workaround is no longer needed.

3. Thanks to @fredguinog for testing `fcase` in development before 1.13.0 was released and finding a segfault, [#4378](https://github.com/Rdatatable/data.table/issues/4378). It was found separately by the `rchk` tool (which uses static code analysis) in release procedures and fixed before `fcase` was released, but the reproducible example has now been added to the test suite for completeness. Thanks also to @shrektan for investigating, proposing a very similar fix at C level, and a different reproducible example wich has also been added to the test suite.


# data.table [v1.13.2](https://github.com/Rdatatable/data.table/milestone/19?closed=1) (19 Oct 2020)

Expand Down
23 changes: 23 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -17212,3 +17212,26 @@ test(2159.14, typeof(as.matrix(DT)), "character")
test(2159.15, typeof(as.matrix(DT[0L])), "character")
test(2159.16, min(DT[0L]), error="only.*numeric")

# fcase tests from dev 1.12.9 fixed before 1.13.0 was released, #4378 #4401
# Matt tested that the smaller 100 size still fails in 1.12.9 under gctorture2(step=100)
set.seed(123)
x = structure(rnorm(100L), class='abc')
test(2160.1, fcase(x <= -100, structure(x*1.0, class='abc'),
x <= -10, structure(x*1.0, class='abc'),
x <= 0, structure(x*1.0, class='abc'),
x <= 100, structure(x*1.0, class='abc'),
x <= 1000, structure(x*1.0, class='abc'),
x >= 1000, structure(x*1.0, class='abc')),
structure(x, class='abc'))
x = data.table(rnorm(100L), rnorm(100L), rnorm(100L))
test(2160.2, x[, v0 := fcase(
V1 > 0 & V2 <= 1 & V3 > 1, V2 * 100L,
V1 > 1 & V2 <= 0 & V3 > 0, V3 * 100L,
V1 > -1 & V2 <= 2 & V3 > 1, V1 * 100L,
V1 > 1 & V2 <= 0 & V3 > 2, 300,
V1 > 0 & V2 <= 1 & V3 > 1, 100,
V1 > -1 & V2 <= 0 & V3 > -1, V1 * 100L,
default = 0
)][c(1,3,74,96,100), round(v0,1)], c(0, -24.7, 82.5, 6.7, 0))
rm(x)

0 comments on commit 70b6b13

Please sign in to comment.