This repository was archived by the owner on Feb 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"repository": "https://github.com/exercism/xracket", | ||
"active": false, | ||
"problems": [ | ||
"bob" | ||
"bob", | ||
"word-count" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#lang racket | ||
|
||
(define (word-count word) | ||
(for/fold ([result (hash)]) | ||
([word (in-list (string-split word))]) | ||
(hash-set result word (add1 (hash-ref result word 0))))) | ||
|
||
(provide word-count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#lang racket | ||
|
||
(require rackunit | ||
rackunit/text-ui | ||
"word-count.rkt") | ||
|
||
(define suite | ||
(test-suite | ||
"Tests for the word-count exercise" | ||
(check-equal? (word-count "word") | ||
'#hash(("word" . 1)) | ||
"one word") | ||
(check-equal? (word-count "one of each") | ||
'#hash(("one" . 1) ("of" . 1) ("each" . 1)) | ||
"one of each") | ||
(check-equal? (word-count "one fish two fish red fish blue fish") | ||
'#hash(("one" . 1) ("fish" . 4) ("two" . 1) ("red" . 1) ("blue" . 1)) | ||
"multiple occurrences") | ||
(check-equal? (word-count "car : carpet as java : javascript!!&@$%^&") | ||
'#hash(("car" . 1) (":" . 2) ("carpet" . 1) ("as" . 1) ("java" . 1) | ||
("javascript!!&@$%^&" . 1)) | ||
"preserves punctuation") | ||
(check-equal? (word-count "testing 1 2 testing") | ||
'#hash(("testing" . 2) ("1" . 1) ("2" . 1)) | ||
"include numbers") | ||
(check-equal? (word-count "go Go GO") | ||
'#hash(("go" . 1) ("Go" . 1) ("GO" . 1)) | ||
"mixed case") | ||
(check-equal? (word-count "wait for it") | ||
'#hash(("wait" . 1) ("for" . 1) ("it" . 1)) | ||
"multiple spaces") | ||
(check-equal? (word-count "rah rah ah ah ah\nroma roma ma\nga ga oh la la\nwant your bad romance") | ||
'#hash(("rah" . 2) ("ah" . 3) ("roma" . 2) ("ma" . 1) ("ga" . 2) ("oh" . 1) | ||
("la" . 2) ("want" . 1) ("your" . 1) ("bad" . 1) | ||
("romance" . 1)) | ||
"newlines"))) | ||
|
||
(exit (if (zero? (run-tests suite)) 0 1)) |