File: test-diffObj.Rout.save

package info (click to toggle)
r-cran-diffobj 0.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,432 kB
  • sloc: ansic: 455; javascript: 96; sh: 32; makefile: 8
file content (104 lines) | stat: -rwxr-xr-x 5,346 bytes parent folder | download
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> NAME <- "diffObj"
> source(file.path('_helper', 'init.R'))
> 
> # - simple diffobj -------------------------------------------------------------
> 
> # no diff for print
> all.equal(as.character(diffObj(iris.s, iris.c)), rdsf(100))
[1] TRUE
> # no diff for str
> all.equal(
+   as.character(diffObj(1:100, c(1:99, 200L))), rdsf(200)
+ )
[1] TRUE
> # diffs for both and must pick one, first one is str, second is print
> all.equal(
+   as.character(diffObj(mdl1[7], mdl2[7])), rdsf(300)
+ )
[1] TRUE
> all.equal(as.character(diffObj(mdl1, mdl2)), rdsf(400))
[1] TRUE
> 
> # - fits or doesn't ------------------------------------------------------------
> 
> # Note, the first test used to favor str until we handicapped print
> all.equal(
+   diffObj(matrix(1:20, ncol=2), matrix(2:21, ncol=2), line.limit=5)@capt.mode,
+   "str"
+ )
[1] TRUE
> # test kinda slow, would be better to have one with smaller objects with print
> # methods
> 
> all.equal(
+   diffObj(mdl1, mdl2, line.limit=15, mode='unified')@capt.mode, "print"
+ )
[1] TRUE
> all.equal(diffObj(1:1000, 1000:1, line.limit=5)@capt.mode, "str")
[1] TRUE
> 
> # - misc -----------------------------------------------------------------------
> 
> try(diffObj(1, 2, extra=list(TRUE))) # "extra"
Error in .local(target, current, ...) : 
  Argument `extra` must be empty in `diffObj`.
> 
> # - print error ----------------------------------------------------------------
> 
> x <- structure("hello", class="diffobj_ogewlhgiadfl")
> y <- structure("goodbye", class="diffobj_ogewlhgiadfl")
> try(diffObj(x, y)) # "Error in calling .diffPrint."
Error in print.diffobj_ogewlhgiadfl(structure("goodbye", class = "diffobj_ogewlhgiadfl")) : 
  failure
Error in diffObj(target = x, current = y) : 
  Error in calling `diffPrint`: Failed attempting to get text representation of object: failure
> 
> # Random exmaples to think through `diffObj` output
> 
> diffObj(
+   pairlist("`logical(2L)` should be length 2 (is 3)"),
+   pairlist("be length 2 (is 3)")
+ )
< pairlist("`logical(2L)` should be l..  > pairlist("be length 2 (is 3)")       
@@ 1,3 @@                                @@ 1,3 @@                              
  [[1]]                                    [[1]]                                
< [1] "`logical(2L)` should be length 2  > [1] "be length 2 (is 3)"             
:  (is 3)"                               ~                                      
                                                                                
> 
> diffObj(
+   pairlist("`matrix(integer(), nrow = 3)` should be matrix (is list)", "`list(character(1L), 1L)[[2]]` should be type \"integer-like\" (is \"character\")"),
+   pairlist("be class \"matrix\" (is \"list\")", "be type \"integer-like\" (is \"character\") at index [[2]]")
+ )
< pairlist("`matrix(integer(), nrow =..  > pairlist("be class \"matrix\" (is \..
@@ 1,6 @@                                @@ 1,6 @@                              
  [[1]]                                    [[1]]                                
< [1] "`matrix(integer(), nrow = 3)` sh  > [1] "be class \"matrix\" (is \"list\"
: ould be matrix (is list)"              : )"                                   
                                                                                
  [[2]]                                    [[2]]                                
< [1] "`list(character(1L), 1L)[[2]]` s  > [1] "be type \"integer-like\" (is \"c
: hould be type \"integer-like\" (is \"  : haracter\") at index [[2]]"          
: character\")"                          ~                                      
                                                                                
> 
> proc.time()
   user  system elapsed 
  3.252   0.326   3.687