Sha256: 92d461c8cd1e961010f9a5a04f2d64ff6b5016c28ae62a72d2be4bd449b0d24f
Contents?: true
Size: 1.4 KB
Versions: 137
Compression:
Stored size: 1.4 KB
Contents
source('./word-count.R') suppressPackageStartupMessages({ require(testthat) }) # When comparing lists, all.equal expects the objects to be in the same order # This expectation instead checks that a) the set of names are the same and b) each named object is equal expect_equal_pairs <- function(object, expected) { expect_equal(sort(names(object)), sort(names(expected)), info="names in lists differ") for(name in names(expected)) { expect_equal(object[name], expected[name], info="list element missing") } } test_that("count one word", { expect_equal_pairs(word_count("word"), list("word" = 1) ) }) test_that("count one of each word", { expect_equal_pairs(word_count("one of each"), list("one" = 1, "of" = 1, "each" = 1) ) }) test_that("multiple occurrences of a word", { expect_equal_pairs(word_count("one fish two fish red fish blue fish"), list("one" = 1, "fish" = 4, "two" = 1, "red" = 1, "blue" = 1) ) }) test_that("ignore punctuation", { expect_equal_pairs(word_count("car : carpet as java : javascript!!&@$%^&"), list("car" = 1, "carpet" = 1, "as" = 1, "java" = 1, "javascript" = 1) ) }) test_that("include numbers", { expect_equal_pairs(word_count("testing, 1, 2 testing"), list("testing" = 2, "1" = 1, "2" = 1) ) }) test_that("normalize case", { expect_equal_pairs(word_count("go Go GO Stop stop"), list("go" = 3, "stop" = 2) ) }) print("All tests passed!")
Version data entries
137 entries across 137 versions & 1 rubygems