> # CSC121, Jan-Apr 2017, Small Assignment 1. > # > # Script for testing the functions. > > > # These are the required tests from the course web pa .... [TRUNCATED] > replace_one_phrase(t,c("hot","dogs")) [1] "I" "like" "hot_dogs" "a" "lot" "hot_dogs" "forever" > replace_one_phrase(c("a","xx","xx","xx","b"),c("xx","xx")) [1] "a" "xx_xx" "xx" "b" > replace_phrases (c("ab","pq","xy"), list(c("ab","pq"),c("pq","xy"))) [1] "ab_pq" "xy" > test_text1 <- c( + "I","went","South","to","North","Dakota","then","South","to","South","Carolina") > test_text2 <- c( + "North","Dakota","is","North","of","South","Dakota","which","North","Dakota", + "is","North","of") > replace_one_phrase (test_text1,c("North","Dakota")) [1] "I" "went" "South" "to" "North_Dakota" [6] "then" "South" "to" "South" "Carolina" > replace_one_phrase (test_text1,c("South","Carolina")) [1] "I" "went" "South" "to" [5] "North" "Dakota" "then" "South" [9] "to" "South_Carolina" > replace_one_phrase (test_text2,c("North","Dakota")) [1] "North_Dakota" "is" "North" "of" "South" [6] "Dakota" "which" "North_Dakota" "is" "North" [11] "of" > phrases <- list(c("North","Dakota"), c("South","Dakota"), + c("North","Carolina"), c("South","Carolina"), + c("N ..." ... [TRUNCATED] > replace_phrases (test_text1, phrases) [1] "I" "went" "South" "to" [5] "North_Dakota" "then" "South" "to" [9] "South_Carolina" > replace_phrases (test_text2, phrases) [1] "North_Dakota" "is" "North" "of" "South_Dakota" [6] "which" "North_Dakota" "is" "North" "of" > # Here are some additional tests, such as you might have added. They test > # some situations that one could imagine could reveal bugs. > > # Test .... [TRUNCATED] [1] "xyz" > # Test when there are only two words of text, no match. > > replace_one_phrase (c("uvw","xyz"), c("abc","def")) [1] "uvw" "xyz" > # Test when there are only two words of text, with a match. > > replace_one_phrase (c("abc","def"), c("abc","def")) [1] "abc_def" > # Test when the phrase matches at the very beginning. > > replace_one_phrase (c("abc","def","ghi"), c("abc","def")) [1] "abc_def" "ghi" > # Test when the phrase matches at the very end. > > replace_one_phrase (c("abc","def","ghi"), c("def","ghi")) [1] "abc" "def_ghi" > # Test when all words are part of the phrase. > > replace_one_phrase (c("abc","def","abc","def","abc","def"), c("abc","def")) [1] "abc_def" "abc_def" "abc_def" > # Test where the last word of the text matches the first word of the phrase > # (so should not be a match). > > replace_one_phrase (c("abc","def"," ..." ... [TRUNCATED] [1] "abc" "def" "ghi" > # Test replacing a list of phrases with duplicate phrases. > > replace_phrases (c("abc","def","ghi"), list (c("abc","def"), c("abc","def"))) [1] "abc_def" "ghi"