-
Notifications
You must be signed in to change notification settings - Fork 42
/
test-wrapping-formatting.R
62 lines (52 loc) · 1.58 KB
/
test-wrapping-formatting.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
test_that("Coefficient digits work correctly", {
model_simple <- lm(mpg ~ cyl + disp, data = mtcars)
# coefficient rounding works
expect_snapshot_output(
extract_eq(model_simple, use_coefs = TRUE, coef_digits = 4)
)
# signs are doubled when fix_signs = FALSE
expect_snapshot_output(
extract_eq(model_simple, use_coefs = TRUE, fix_signs = FALSE)
)
})
test_that("Wrapping works correctly", {
model_big <- lm(mpg ~ ., data = mtcars)
# wrapping with 4 terms works
expect_snapshot_output(
extract_eq(model_big, wrap = TRUE, terms_per_line = 4)
)
# wrapping with 2 terms works
expect_snapshot_output(
extract_eq(model_big, wrap = TRUE, terms_per_line = 2)
)
tex_end <- capture.output(extract_eq(model_big,
wrap = TRUE,
operator_location = "end"
))
expect_match(tex_end[3], "\\+ \\\\\\\\$",
label = "wrapped equation line ends with +"
)
expect_match(tex_end[4], "\\+ \\\\\\\\$",
label = "other wrapped equation line ends with +"
)
tex_start <- capture.output(extract_eq(model_big,
wrap = TRUE,
operator_location = "start"
))
expect_match(tex_start[3], "\\)\\\\\\\\$",
label = "wrapped equation line doesn't end with +"
)
expect_match(tex_start[4], "&\\\\quad \\+ ",
label = "wrapped equation line starts with +"
)
expect_match(tex_start[5], "&\\\\quad \\+ ",
label = "other wrapped equation line starts with +"
)
tex_align <- capture.output(extract_eq(model_big,
wrap = TRUE,
align_env = "align"
))
expect_equal(tex_align[2], "\\begin{align}",
label = "different align environment used"
)
})