Sha256: f8feb7b00395dc4c8c55cddd4d5d878d801ca34fa6fd36d45a2169be9bce8682

Contents?: true

Size: 1.78 KB

Versions: 376

Compression:

Stored size: 1.78 KB

Contents

import
 critbits, unittest
import wordcount

proc `==`(a, b: TWordCount): bool =
  if a.len != b.len:
    return
  for key, count in a:
    if b[key] != count:
      return
  return true

proc fromPairs(pairs: seq[tuple[word: string, count: int]]): TWordCount =
  for p in pairs:
    result[p.word] = p.count

test "count one word":
  let
    expected = fromPairs(@[("word", 1)])
    result = wordCount("word")
  check result == expected

test "count one of each":
  let
    expected = fromPairs(@[("one", 1), ("of", 1), ("each", 1)])
    result = wordCount("one of each")
  check result == expected

test "count multiple occurrences":
  let
    expected = fromPairs(@[("one", 1), ("fish", 4), ("two", 1),
                           ("red", 1), ("blue", 1)])
    result = wordCount("one fish two fish red fish blue fish")
  check result == expected

test "ignore punctuation":
  let
    expected = fromPairs(@[("car", 1), ("carpet", 1), ("as", 1),
                           ("java", 1), ("javascript", 1)])
    result = wordCount("car : carpet as java : javascript!!&@$%^&")
  check result == expected

test "include numbers":
  let
    expected = fromPairs(@[("testing", 2), ("1", 1), ("2", 1)])
    result = wordCount("testing, 1, 2 testing")
  check result == expected

test "normalize case":
  let
    result = wordCount("go Go GO")
    expected = fromPairs(@[("go", 3)])
  check result == expected

test "prefix punctuation":
  let
    expected = fromPairs(@[("testing", 2), ("1", 1), ("2", 1)])
    result = wordCount("!%%#testing, 1, 2 testing")
  check result == expected

test "symbols are separators":
  let
    expected = fromPairs(@[("hey", 1), ("my", 1), ("spacebar", 1),
                           ("is", 1), ("broken", 1)])
    result = wordCount("hey,my_spacebar_is_broken.")
  check result == expected

Version data entries

376 entries across 376 versions & 1 rubygems

Version Path
trackler-2.2.1.58 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.57 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.56 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.55 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.54 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.53 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.52 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.51 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.50 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.49 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.48 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.47 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.46 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.45 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.44 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.43 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.42 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.41 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.40 tracks/nim/exercises/word-count/word_count_test.nim
trackler-2.2.1.39 tracks/nim/exercises/word-count/word_count_test.nim