exercism

Exercism solutions.
git clone git://code.dwrz.net/exercism
Log | Files | Refs

word-count-test.el (1799B)


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