Skip to content

Commit c3dbb00

Browse files
eschew unless= argument to notcopied for readability
1 parent dbacebf commit c3dbb00

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

inst/tests/mergelist.Rraw

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ addresses = function(x) vapply(x, address, "")
1717
copied = function(ans, l) {
1818
!any(addresses(ans) %chin% unlist(recursive=FALSE, lapply(l, addresses)))
1919
}
20-
notcopied = function(ans, l, how="left", unless=character()) {
21-
if (how %chin% unless) return(copied(ans, l)) ## used during looping tests for easier escape
20+
# check that the "baseline" table (as inferred from 'how') is _not_ copied in
21+
# cases where it need not necessarily be copied.
22+
notcopied = function(ans, l, how="left") {
2223
if (how == "full") return( ## either side, left|right, notcopied is fine
2324
all(addresses(l[[1L]]) %chin% addresses(ans)) ||
2425
all(addresses(l[[length(l)]]) %chin% addresses(ans))
@@ -171,7 +172,11 @@ local({
171172
test(22 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=TRUE), expected[[how]])
172173
test(22 + (frac <- frac + 0.001), copied(ans, l))
173174
test(22 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=FALSE), expected[[how]])
174-
test(22 + (frac <- frac + 0.001), notcopied(ans, l, how=how, unless="full"))
175+
if (how == "full") {
176+
test(22 + (frac <- frac + 0.001), copied(ans, l))
177+
} else {
178+
test(22 + (frac <- frac + 0.001), notcopied(ans, l, how=how))
179+
}
175180
}
176181
}
177182
})
@@ -196,7 +201,11 @@ local({
196201
test(23 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=TRUE), expected[[how]])
197202
test(23 + (frac <- frac + 0.001), copied(ans, l))
198203
test(23 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=FALSE), expected[[how]])
199-
test(23 + (frac <- frac + 0.001), notcopied(ans, l, how=how, unless="inner"))
204+
if (how == "inner") {
205+
test(23 + (frac <- frac + 0.001), copied(ans, l))
206+
} else {
207+
test(23 + (frac <- frac + 0.001), notcopied(ans, l, how=how))
208+
}
200209
}
201210
}
202211
})
@@ -221,7 +230,11 @@ local({
221230
test(24 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=TRUE), expected[[how]])
222231
test(24 + (frac <- frac + 0.001), copied(ans, l))
223232
test(24 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=FALSE), expected[[how]])
224-
test(24 + (frac <- frac + 0.001), notcopied(ans, l, how=how, unless=c("inner", "full")))
233+
if (how %in% c("inner", "full")) {
234+
test(24 + (frac <- frac + 0.001), copied(ans, l))
235+
} else {
236+
test(24 + (frac <- frac + 0.001), notcopied(ans, l, how=how))
237+
}
225238
}
226239
}
227240
})
@@ -246,7 +259,11 @@ local({
246259
test(25 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=TRUE), expected[[how]])
247260
test(25 + (frac <- frac + 0.001), copied(ans, l))
248261
test(25 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=FALSE), expected[[how]])
249-
test(25 + (frac <- frac + 0.001), notcopied(ans, l, how=how, unless=c("inner", "full")))
262+
if (how %in% c("inner", "full")) {
263+
test(25 + (frac <- frac + 0.001), copied(ans, l))
264+
} else {
265+
test(25 + (frac <- frac + 0.001), notcopied(ans, l, how=how))
266+
}
250267
}
251268
}
252269
})
@@ -321,7 +338,11 @@ local({
321338
test(28 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=TRUE), expected[[how]])
322339
test(28 + (frac <- frac + 0.001), copied(ans, l))
323340
test(28 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=FALSE), expected[[how]])
324-
test(28 + (frac <- frac + 0.001), notcopied(ans, l, how=how, unless="inner"))
341+
if (how == "inner") {
342+
test(28 + (frac <- frac + 0.001), copied(ans, l))
343+
} else {
344+
test(28 + (frac <- frac + 0.001), notcopied(ans, l, how=how))
345+
}
325346
}
326347
}
327348
})
@@ -343,7 +364,6 @@ local({
343364
frac = frac + 0.1
344365
for (mult in c("all", "first", "last", "error")) {
345366
frac = frac + 0.01
346-
cat(sprintf("\nhow=%s, mult=%s, frac=%.04f\n", how, mult, frac))
347367
test(29 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=TRUE), expected[[how]])
348368
test(29 + (frac <- frac + 0.001), copied(ans, l))
349369
test(29 + (frac <- frac + 0.001), ans <- mergepair(l$lhs, l$rhs, on="id1", how=how, mult=mult, copy=FALSE), expected[[how]])

0 commit comments

Comments
 (0)