Skip to content

Commit a65535d

Browse files
local() approach in tests
1 parent d8ba683 commit a65535d

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

inst/tests/mergelist.Rraw

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,35 @@ test(2.01, fdistinct(list(x=c(1L,1:2), b=1:2), on="x", mult="last"), error="must
2323
test(2.02, fdistinct(data.table(x=c(1L,1:2)), on="z", mult="last"), error="must be character column names of")
2424
test(2.03, fdistinct(data.table(x=c(1L,1:2)), on="x", mult="last", cols=character()), error="must be non-zero length, non-NA, integer or character columns of")
2525
test(2.04, fdistinct(data.table(x=c(1L,1:2, y=1:3)), on="x", mult="last", copy=NA), error="must be TRUE or FALSE")
26-
d = data.table(x=1:2, y=1:2)
27-
test(2.05, ans<-fdistinct(d, on="x", mult="last"), d)
28-
test(2.06, intersect(addresses(ans), addresses(d)), character())
29-
test(2.07, ans<-fdistinct(d, on="x", mult="last", copy=FALSE), d)
30-
test(2.08, addresses(ans), addresses(d))
31-
d = data.table(x=c(2:1,2L), y=1:3)
32-
test(2.09, fdistinct(d, on="x", mult="first"), data.table(x=2:1, y=1:2))
33-
test(2.10, fdistinct(d, on="x", mult="last"), data.table(x=1:2, y=2:3))
34-
setattr(attr(setattr(d, "index", integer()), "index", TRUE), "__x", forderv(d, "x", retGrp=TRUE)) ## retGrp=T index #4386
35-
test(2.11, fdistinct(d, on="x", mult="first"), data.table(x=2:1, y=1:2))
26+
local({
27+
d = data.table(x=1:2, y=1:2)
28+
test(2.05, ans<-fdistinct(d, on="x", mult="last"), d)
29+
test(2.06, intersect(addresses(ans), addresses(d)), character())
30+
test(2.07, ans<-fdistinct(d, on="x", mult="last", copy=FALSE), d)
31+
test(2.08, addresses(ans), addresses(d))
32+
})
33+
local({
34+
d = data.table(x=c(2:1,2L), y=1:3)
35+
test(2.09, fdistinct(d, on="x", mult="first"), data.table(x=2:1, y=1:2))
36+
test(2.10, fdistinct(d, on="x", mult="last"), data.table(x=1:2, y=2:3))
37+
setattr(attr(setattr(d, "index", integer()), "index", TRUE), "__x", forderv(d, "x", retGrp=TRUE)) ## retGrp=T index #4386
38+
test(2.11, fdistinct(d, on="x", mult="first"), data.table(x=2:1, y=1:2))
39+
})
3640

37-
test(3.01, hasindex(d, "x"))
38-
test(3.02, hasindex(d, "x", retGrp=TRUE))
39-
setattr(attr(setattr(d, "index", integer()), "index", TRUE), "__x", forderv(d, "x")) ## retGrp=F index #4386
40-
test(3.03, hasindex(d, "x"))
41-
test(3.04, !hasindex(d, "x", retGrp=TRUE))
42-
setattr(d, "index", NULL)
43-
test(3.05, !hasindex(d, "x"))
44-
test(3.06, !hasindex(d, "x", retGrp=TRUE))
45-
setattr(d, "index", integer())
46-
test(3.07, !hasindex(d, "x"))
47-
test(3.08, !hasindex(d, "x", retGrp=TRUE))
48-
rm(d)
41+
local({
42+
d = data.table(x=c(2:1,2L), y=1:3)
43+
test(3.01, hasindex(d, "x"))
44+
test(3.02, hasindex(d, "x", retGrp=TRUE))
45+
setattr(attr(setattr(d, "index", integer()), "index", TRUE), "__x", forderv(d, "x")) ## retGrp=F index #4386
46+
test(3.03, hasindex(d, "x"))
47+
test(3.04, !hasindex(d, "x", retGrp=TRUE))
48+
setattr(d, "index", NULL)
49+
test(3.05, !hasindex(d, "x"))
50+
test(3.06, !hasindex(d, "x", retGrp=TRUE))
51+
setattr(d, "index", integer())
52+
test(3.07, !hasindex(d, "x"))
53+
test(3.08, !hasindex(d, "x", retGrp=TRUE))
54+
})
4955

5056
# cbindlist, setcbindlist
5157

0 commit comments

Comments
 (0)