File: test-atomic.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 (239 lines) | stat: -rwxr-xr-x 6,391 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

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 <- "atomic"
> source(file.path('_helper', 'init.R'))
> 
> # - Basic Tests
> 
> all.equal(as.character(diffPrint(chr.1, chr.2)), rdsf(100))
[1] TRUE
> all.equal(
+   as.character(diffPrint(chr.1, chr.2, mode="unified")), rdsf(200)
+ )
[1] TRUE
> all.equal(
+   as.character(diffPrint(chr.1, chr.2, mode="context")), rdsf(400)
+ )
[1] TRUE
> all.equal(
+   as.character(diffPrint(chr.1[2:3], chr.2[2], mode="sidebyside")), rdsf(500)
+ )
[1] TRUE
> # Check that `extra` works
> 
> all.equal(
+   as.character(
+     diffPrint(chr.1, chr.2, mode="unified", extra=list(quote=FALSE))
+   ),
+   rdsf(600)
+ )
[1] TRUE
> # make sure blanks line up correctly
> 
> all.equal(
+   as.character(diffPrint(chr.3, chr.4)), rdsf(700)
+ )
[1] TRUE
> all.equal(
+   as.character(diffPrint(chr.3, chr.4, mode="unified")), rdsf(800)
+ )
[1] TRUE
> 
> # - Word wrap in atomic
> 
> A <- A.1 <- B <- c(letters, LETTERS)
> B[15] <- "Alabama"
> A.1[5] <- "Ee"
> C <- A[-15]
> D <- C
> E <- B[-45]
> 
> # Test simple changes to vectors; at 80 columns removing 1:8 corresponds to
> # row deletion
> 
> all.equal(as.character(diffPrint(A[-(1:8)], A)), rdsf(900))
[1] TRUE
> all.equal(as.character(diffPrint(A, A[-(1:8)])), rdsf(1000))
[1] TRUE
> 
> all.equal(as.character(diffPrint(A[-1], A[-2])), rdsf(1100))
[1] TRUE
> 
> # Replace single word
> 
> all.equal(as.character(diffPrint(A, B)), rdsf(1200))
[1] TRUE
> all.equal(as.character(diffPrint(B, A)), rdsf(1250))
[1] TRUE
> 
> # Make sure turning off word.diff also turns of unwrapping, but that we can
> # turn off unwrapping without turning off word diff
> 
> all.equal(
+   as.character(diffPrint(A, B, word.diff=FALSE)), rdsf(1300)
+ )
[1] TRUE
> all.equal(
+   as.character(diffPrint(A, B, unwrap.atomic=FALSE)), rdsf(1400)
+ )
[1] TRUE
> # Different wrap frequency and removed words that span lines
> 
> all.equal(
+   as.character(diffPrint(A, A.1[-(13:18)])), rdsf(1425)
+ )
[1] TRUE
> # Removing words
> 
> all.equal(as.character(diffPrint(C, B)), rdsf(1450))
[1] TRUE
> 
> # Two hunks
> 
> all.equal(as.character(diffPrint(D, E)), rdsf(1500))
[1] TRUE
> all.equal(as.character(diffPrint(E, D)), rdsf(1600))
[1] TRUE
> 
> # Vignette example
> 
> state.abb.2 <- state.abb
> state.abb.2[38] <- "Pennsylvania"
> 
> all.equal(
+   as.character(diffPrint(state.abb, state.abb.2)), rdsf(1700)
+ )
[1] TRUE
> # Number corner cases
> 
> all.equal(as.character(diffPrint(1:100, 2:101)), rdsf(1800))
[1] TRUE
> all.equal(as.character(diffPrint(2:101, 1:100)), rdsf(1900))
[1] TRUE
> all.equal(
+   as.character(diffPrint(2:101, (1:100)[-9])), rdsf(2000)
+ )
[1] TRUE
> all.equal(
+   as.character(diffPrint((2:101)[-98], (1:100)[-9])), rdsf(2100)
+ )
[1] TRUE
> # This is one of those that a better in-hunk align algorithm would benefit
> 
> int.1 <- int.2 <- 1:100
> int.2[c(8, 20, 60)] <- 99
> int.2 <- c(50:1, int.2)
> all.equal(as.character(diffPrint(int.1, int.2)), rdsf(2200))
[1] TRUE
> 
> # - with names
> rand.chrs <- do.call(paste0, expand.grid(LETTERS, LETTERS))
> F <- F1 <- F2 <- (2:105)[-98]
> G <- G2 <- G3 <- G4 <- G5 <- (1:100)[-9]
> nm.1 <- rand.chrs[seq_along(F)]
> nm.2 <- rand.chrs[seq_along(G)]
> names(F1) <- names(F2) <- nm.1
> names(G3) <- names(G2) <- names(G3) <-  names(G4) <- names(G5) <- nm.2
> names(G3)[c(5, 25, 60)] <- c("XXXXX", rand.chrs[c(300, 350)])
> names(G4)[c(5, 25, 60)] <- names(G5)[c(5, 25, 60)] <-
+   c("XX", rand.chrs[c(300, 350)])
> attr(F2, "blah") <- 1:5
> attr(G5, "blah") <- 3:8
> 
> all.equal(as.character(diffPrint(F, G)), rdsf(2300))
[1] TRUE
> all.equal(as.character(diffPrint(F1, G2)), rdsf(2400))
[1] TRUE
> 
> # Challenging case b/c the names wrap with values, and you have to pick one or
> # the other to match when the wrap frequencies are different
> 
> all.equal(as.character(diffPrint(F1, G3)), rdsf(2500))
[1] TRUE
> all.equal(as.character(diffPrint(F1, G4)), rdsf(2520))
[1] TRUE
> 
> # Attributes
> 
> all.equal(as.character(diffPrint(F2, G5)), rdsf(2530))
[1] TRUE
> all.equal(as.character(diffPrint(F1, G5)), rdsf(2540))
[1] TRUE
> 
> # - Original tests
> set.seed(2)
> w1 <- sample(
+   c(
+   "carrot", "cat", "cake", "eat", "rabbit", "holes", "the", "a", "pasta",
+   "boom", "noon", "sky", "hat", "blah", "paris", "dog", "snake"
+   ), 25, replace=TRUE
+ )
> w4 <- w3 <- w2 <- w1
> w2[sample(seq_along(w1), 5)] <- LETTERS[1:5]
> w3 <- w1[8:15]
> w4 <- c(w1[1:5], toupper(w1[1:5]), w1[6:15], toupper(w1[1:5]))
> 
> all.equal(as.character(diffPrint(w1, w2)), rdsf(2600))
[1] TRUE
> all.equal(as.character(diffPrint(w1, w3)), rdsf(2700))
[1] TRUE
> all.equal(as.character(diffPrint(w1, w4)), rdsf(2800))
[1] TRUE
> 
> # - Simple word diffs
> a <- c("a", "b", "c", "d")
> b <- c("b", "c", "d", "e")
> all.equal(as.character(diffPrint(a, b)), rdsf(2900))
[1] TRUE
> 
> a <- c("x", "a", "b", "c", "d", "z")
> b <- c("x", "b", "c", "d", "e", "z")
> all.equal(as.character(diffPrint(a, b)), rdsf(3000))
[1] TRUE
> 
> a <- c("x", "a", "b", "c", "d", "z")
> b <- c("z", "b", "c", "d", "e", "x")
> all.equal(as.character(diffPrint(a, b)), rdsf(3100))
[1] TRUE
> 
> # - Alignment edge cases
> all.equal(
+   as.character(diffPrint(20:50, 30:62)), rdsf(3200)
+ )
[1] TRUE
> # below is off; should be aligning matching context line, part of the problem
> # might be that we're doing the realignment without thinking about what the
> # other hunk has.
> #
> # Possible encode each line as hunk#:diff/mix/cont
> 
> # all.equal(
> #   as.character(diffPrint(20:50, 35:62)), rdsf(3300)
> # )
> 
> # another interesting example where the existing algo seems to lead to a
> # reasonable outcome
> 
> all.equal(
+   as.character(diffPrint(c(1:24,35:45), c(1:8, 17:45))), rdsf(3400)
+ )
[1] TRUE
> 
> proc.time()
   user  system elapsed 
  3.515   0.411   4.070