Skip to content

Commit

Permalink
improved test
Browse files Browse the repository at this point in the history
  • Loading branch information
markvanderloo committed Jul 13, 2020
1 parent 0e67b62 commit d9d8e73
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
42 changes: 35 additions & 7 deletions pkg/inst/tinytest/test_afind.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@


texts = c("When I grow up, I want to be"
, "one of the harversters of the sea"
, "I think before my days are gone"
, "I want to be a fisherman")

patterns = c("fish", "gone","to be")

out <- afind(texts, patterns, method="osa")

location <- matrix(c(
1, 1, 24,
6, 1, 28,
1, 28, 6,
16, 3, 8),
nrow=4, byrow=TRUE)


distance <- matrix(c(
4, 3, 0,
2, 2, 3,
3, 0, 2,
0, 3, 0),
nrow=4, byrow=TRUE)

match <- matrix(c(
"When", "When", "to be",
"f th", "one ", "he se",
"I th", "gone", "nk be",
"fish", "want", "to be"),
nrow=4, byrow=TRUE)


expect_equal(out$location, location)
expect_equal(out$distance, distance)
expect_equal(out$match, match)

x <- c(
"when I grow up I want to be, one of the harverster of the sea"
, "I think before my days are gone, I want to be a fisherman"
)

out <- afind(x, "gone")
expect_equal(out$location, matrix(c(29,28),nrow=2))
expect_equal(out$match, matrix(c(" one", "gone"),nrow=2))



2 changes: 1 addition & 1 deletion pkg/src/Rstringdist.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ SEXP R_lower_tri(SEXP a, SEXP method
return(yy);
}

// R_afind
// afind
// For each string in 'a', return the starting position of
// the best match with 'pattern'.
SEXP R_afind(SEXP a, SEXP pattern, SEXP width
Expand Down

0 comments on commit d9d8e73

Please sign in to comment.