Skip to content

Commit 271c5c0

Browse files
rearrange tests using options to be in nested local() calls
1 parent 2a35e7d commit 271c5c0

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

inst/tests/mergelist.Rraw

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -613,50 +613,59 @@ local({
613613
test(104.04, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x"])
614614
test(104.05, mergelist(l, on="x", how="left"), error="multiple matches during merge")
615615
test(104.06, l$to[l$fm, on="x", mult="error"], error="multiple matches during merge")
616+
})
617+
618+
## with join.many=FALSE option set
619+
local({
620+
old = options(datatable.join.many=FALSE)
621+
on.exit(options(old))
616622

617-
options(datatable.join.many=FALSE)
623+
d = function(n) as.data.table(list(x=rep(1L, n)))
624+
625+
l = list(fm=d(1L), to=d(2L))
618626
test(104.07, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x"]) ## covers !join.many && length(f__)==1L && len__==nrow(x)
619627

620628
l = list(fm=d(2L), to=d(2L))
621-
options(datatable.join.many=FALSE)
622629
test(104.08, mergelist(l, on="x", how="left", mult="all"), error="many-to-many join")
623630
test(104.09, l$to[l$fm, on="x"], error="many-to-many join")
624631

625-
options(datatable.join.many=TRUE)
626-
test(104.10, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x"]) ## join in [ does not stop on cartesian product
632+
l = list(fm=d(3L), to=d(2L))
633+
test(104.10, mergelist(l, on="x", how="left", mult="all"), error="many-to-many join")
634+
test(104.11, l$to[l$fm, on="x"], error="many-to-many join")
627635

628-
l = list(fm=d(3L), to=d(1L))
629-
test(104.11, mergelist(l, on="x", how="left"), l$to[l$fm, on="x"])
636+
l = list(fm=d(2L), to=d(3L))
637+
test(104.12, mergelist(l, on="x", how="left", mult="all"), error="many-to-many join")
638+
test(104.13, l$to[l$fm, on="x"], error="many-to-many join")
630639

631-
l = list(fm=d(1L), to=d(3L))
632-
test(104.12, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x"])
633-
test(104.13, mergelist(l, on="x", how="left"), error="multiple matches during merge")
634-
test(104.14, l$to[l$fm, on="x", mult="error"], error="multiple matches during merge")
640+
l = list(fm=d(3L), to=d(3L))
641+
test(104.14, mergelist(l, on="x", how="left", mult="all"), error="many-to-many join")
642+
test(104.15, l$to[l$fm, on="x"], error="many-to-many join")
643+
})
635644

636-
l = list(fm=d(3L), to=d(2L))
637-
options(datatable.join.many=FALSE)
638-
test(104.15, mergelist(l, on="x", how="left", mult="all"), error="many-to-many join")
639-
test(104.16, l$to[l$fm, on="x"], error="many-to-many join")
645+
# with join.many=TRUE option set
646+
local({
647+
old = options(datatable.join.many=TRUE)
648+
on.exit(options(old))
640649

641-
options(datatable.join.many=TRUE)
642-
test(104.17, l$to[l$fm, on="x"], error="Check for duplicate key values")
643-
test(104.18, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x", allow.cartesian=TRUE])
650+
d = function(n) as.data.table(list(x=rep(1L, n)))
644651

645-
l = list(fm=d(2L), to=d(3L))
646-
options(datatable.join.many=FALSE)
647-
test(104.19, mergelist(l, on="x", how="left", mult="all"), error="many-to-many join")
648-
test(104.20, l$to[l$fm, on="x"], error="many-to-many join")
652+
l = list(fm=d(2L), to=d(2L))
653+
test(104.16, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x"]) ## join in [ does not stop on cartesian product
654+
655+
l = list(fm=d(3L), to=d(1L))
656+
test(104.17, mergelist(l, on="x", how="left"), l$to[l$fm, on="x"])
657+
658+
l = list(fm=d(1L), to=d(3L))
659+
test(104.18, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x"])
660+
test(104.19, mergelist(l, on="x", how="left"), error="multiple matches during merge")
661+
test(104.20, l$to[l$fm, on="x", mult="error"], error="multiple matches during merge")
649662

650-
options(datatable.join.many=TRUE)
651663
test(104.21, l$to[l$fm, on="x"], error="Check for duplicate key values")
652664
test(104.22, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x", allow.cartesian=TRUE])
653665

654-
l = list(fm=d(3L), to=d(3L))
655-
options(datatable.join.many=FALSE)
656-
test(104.23, mergelist(l, on="x", how="left", mult="all"), error="many-to-many join")
657-
test(104.24, l$to[l$fm, on="x"], error="many-to-many join")
666+
test(104.23, l$to[l$fm, on="x"], error="Check for duplicate key values")
667+
test(104.24, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x", allow.cartesian=TRUE])
658668

659-
options(datatable.join.many=TRUE)
660669
test(104.25, l$to[l$fm, on="x"], error="Check for duplicate key values")
661670
test(104.26, mergelist(l, on="x", how="left", mult="all"), l$to[l$fm, on="x", allow.cartesian=TRUE])
662671
})

0 commit comments

Comments
 (0)