
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 
