blob: 1029b680c2838dde479c76544b845f78630573d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
;;; word-count-test.el --- Tests for word-count (exercism)
;;; Commentary:
;;; Code:
(load-file "word-count.el")
(defun equal-assoc (a b)
(let ((strcmp (lambda (a b) (not (string< (car a) (car b))))))
(equal (sort (copy-sequence a) strcmp)
(sort (copy-sequence b) strcmp))))
(ert-deftest no-words-test ()
(should (equal-assoc (word-count "")
nil)))
(ert-deftest count-one-word-test ()
(should (equal-assoc (word-count "word")
'(("word" . 1)))))
(ert-deftest count-one-of-each-word-test ()
(should (equal-assoc (word-count "one of each")
'(("each" . 1)
("of" . 1)
("one" . 1)))))
(ert-deftest multiple-occurrences-of-a-word-test ()
(should (equal-assoc (word-count "one fish two fish red fish blue fish")
'(("blue" . 1)
("red" . 1)
("two" . 1)
("fish" . 4)
("one" . 1)))))
(ert-deftest ignore-punctuation-test ()
(should (equal-assoc (word-count "car : carpet as java : javascript!!&@$%^&")
'(("javascript" . 1)
("java" . 1)
("as" . 1)
("carpet" . 1)
("car" . 1)))))
(ert-deftest include-numbers-test ()
(should (equal-assoc (word-count "testing, 1, 2 testing")
'(("2" . 1)
("1" . 1)
("testing" . 2)))))
(ert-deftest normalize-case-test ()
(should (equal-assoc (word-count "go Go GO Stop stop")
'(("stop" . 2)
("go" . 3)))))
(provide 'word-count)
;;; word-count-test.el ends here
|