File: test-core.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 (203 lines) | stat: -rwxr-xr-x 6,326 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

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 <- "core"
> source(file.path('_helper', 'init.R'))
> 
> # The Myers paper strings
> 
> A <- c("a", "b", "c", "a", "b", "b", "a")
> B <- c("c", "b", "a", "b", "a", "c")
> 
> # - diff myers simple ----------------------------------------------------------
> 
> identical(
+   diffobj:::myers_simple(character(), character()),
+   list(target = integer(0), current = integer(0))
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple("a", character()),
+   list(target = NA_integer_, current = integer(0))
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple(character(), "a"),
+   list(target = integer(0), current = NA_integer_)
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple("a", "a"), list(target = 0L, current = 0L)
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple("a", "b"),
+   list(target = 1L, current = 1L)
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple(c("a", "b"), "b"),
+   list(target = c(NA, 0L), current = 0L)
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple(c("a", "b"), "a"),
+   list(target = c(0L, NA), current = 0L)
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple("a", c("a", "b")),
+   list(target = 0L, current = c(0L, NA))
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple("b", c("a", "b")),
+   list(target = 0L, current = c(NA, 0L))
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple(c("a", "b"), c("b", "c")),
+   list(target = c(NA, 0L), current = c(0L, NA))
+ )
[1] TRUE
> identical(
+   diffobj:::myers_simple(c("a", "b", "c", "d"), c("a", "c", "d", "b")),
+   list(target = c(0L, NA, 0L, 0L), current = c(0L, 0L,  0L, NA))
+ )
[1] TRUE
> # Actual Myers sample string
> identical(
+   diffobj:::myers_simple(A, B),
+   list(target = c(NA, NA, 0L, 0L, 0L, NA, 0L), current = c(0L,  NA, 0L, 0L, 0L, NA))
+ )
[1] TRUE
> # - diff myers mba -------------------------------------------------------------
> 
> identical(ses(character(), character()), character())
[1] TRUE
> identical(ses("a", character()), "1d0")
[1] TRUE
> identical(ses(character(), "a"), "0a1")
[1] TRUE
> identical(ses("a", "a"), character())
[1] TRUE
> identical(ses("a", "b"), "1c1")
[1] TRUE
> identical(ses(c("a", "b"), "b"), "1d0")
[1] TRUE
> identical(ses(c("a", "b"), "a"), "2d1")
[1] TRUE
> identical(ses("a", c("a", "b")), "1a2")
[1] TRUE
> identical(ses("b", c("a", "b")), "0a1")
[1] TRUE
> identical(ses(c("a", "b"), c("b", "c")), c("1d0", "2a2"))
[1] TRUE
> identical(
+   ses(c("a", "b", "c", "d"), c("a", "c", "d", "b")), c("2d1", "4a4")
+ )
[1] TRUE
> # Actual Myers sample string
> identical(ses(A, B), c("1,2d0", "4d1", "5a3", "7a6"))
[1] TRUE
> # This used to cause errors due to under-allocated buffer vector
> identical(ses(letters[1:10], LETTERS[1:2]), "1,10c1,2")
[1] TRUE
> 
> # A little more complex with changes, this was a problem at some point
> 
> A2 <- c("A", "B", "C")
> B2 <- c("X", "A", "Y", "C")
> identical(ses(A2, B2), c("0a1", "2c3"))
[1] TRUE
> 
> # More complicated strings; intended for use with contexts for hunks,
> # but making sure the diffs are correct
> 
> A1 <- c("A", "AA", "B", "C", "D", "E", "F", "G", "H")
> B1 <- c("A", "B", "X", "W", "D", "DD", "E", "Y", "Z")
> C1 <- c("X", "D", "E", "Y", "Z", "H")
> 
> identical(ses(A1, B1), c("2d1", "4c3,4", "5a6", "7,9c8,9"))
[1] TRUE
> identical(ses(A1, C1), c("1,4c1", "7,8c4,5"))
[1] TRUE
> 
> A5 <- c("A", "AA", "B", "C", "D", "E", "F", "G", "H")
> B5 <- c("A", "B",  "X", "W", "D", "E", "F", "W", "G")
> identical(ses(A5, B5), c("2d1", "4c3,4", "7a8", "9d9"))
[1] TRUE
> 
> # NAs treated as strings
> 
> identical(ses(c(NA, "a", "b"), c("a", "b", NA)), c("1d0", "3a3"))
[1] TRUE
> 
> # Coersion to character
> 
> identical(ses(1:5, 4:6), c("1,3d0", "5a3"))
[1] TRUE
> 
> # - print/summary --------------------------------------------------------------
> capture.output(
+   res.1 <- summary(diffobj:::diff_myers(A, B), with.match=TRUE)
+ )
[1] "    type string len offset" "1 Delete     ab   2      1"
[3] "2  Match      c   1      3" "3 Delete      a   1      4"
[5] "4  Match      b   1      5" "5 Insert      a   1      3"
[7] "6  Match     ba   2      6" "7 Insert      c   1      6"
> identical(
+   res.1,
+   structure(list(type = structure(c(3L, 1L, 3L, 1L, 2L, 1L, 2L), .Label = c("Match", 
+ "Insert", "Delete"), class = "factor"), string = c("ab", "c", 
+ "a", "b", "a", "ba", "c"), len = c(2L, 1L, 1L, 1L, 1L, 2L, 1L
+ ), offset = c(1L, 3L, 4L, 5L, 3L, 6L, 6L)), class = "data.frame", row.names = c(NA, 
+ -7L))
+ )
[1] TRUE
> capture.output(
+   res.2 <- summary(diffobj:::diff_myers(A, B), with.match=FALSE)
+ )
[1] "    type len offset" "1 Delete   2      1" "2  Match   1      3"
[4] "3 Delete   1      4" "4  Match   1      5" "5 Insert   1      3"
[7] "6  Match   2      6" "7 Insert   1      6"
> identical(
+   res.2,
+   structure(list(type = structure(c(3L, 1L, 3L, 1L, 2L, 1L, 2L), .Label = c("Match", "Insert", "Delete"), class = "factor"), len = c(2L, 1L, 1L, 1L, 1L, 2L, 1L), offset = c(1L, 3L, 4L, 5L, 3L, 6L, 6L)), .Names = c("type", "len", "offset"), row.names = c(NA, -7L), class = "data.frame")
+ )
[1] TRUE
> identical(
+   capture.output(print(diffobj:::diff_myers(A, B))), ses(A, B)
+ )
[1] TRUE
> #  # - translate
> #    aa <- c("a", "b", "b", "c", "e")
> #    bb <- c("x", "y", "c", "f", "e")
> #    identical(
> #      diffobj:::diffObjCompact(diffobj:::diff_myers(A, B)),
> #      list(target = c(NA, NA, 0L, NA, 0L, 0L, 0L), current = c(0L, 0L, NA, 0L, 0L, NA))
> #    )
> #    identical(
> #      diffobj:::diffObjCompact(diffobj:::diff_myers(aa, bb)),
> #      list(target = c(1L, 2L, NA, 0L, 0L), current = c(1L, 2L, 0L, NA, 0L))
> #    )
> #
> #  } )
> 
> proc.time()
   user  system elapsed 
  1.154   0.117   1.282