|
1 |
| -import org.scalatest._ |
| 1 | +import org.scalatest.{Matchers, FunSuite} |
2 | 2 |
|
3 |
| -class WordCountTest extends FlatSpec with Matchers { |
4 |
| - it should "count one word" in { |
5 |
| - val phrase = new Phrase("word") |
6 |
| - phrase.wordCount should be (Map("word" -> 1)) |
| 3 | +/** @version 1.0.0 */ |
| 4 | +class WordCountTest extends FunSuite with Matchers { |
| 5 | + |
| 6 | + test("count one word") { |
| 7 | + WordCount("word").countwords should be(Map(("word", 1))) |
| 8 | + } |
| 9 | + |
| 10 | + test("count one of each word") { |
| 11 | + pending |
| 12 | + WordCount("one of each").countwords should be( |
| 13 | + Map(("one", 1), ("of", 1), ("each", 1))) |
7 | 14 | }
|
8 | 15 |
|
9 |
| - it should "count one of each" in { |
| 16 | + test("multiple occurrences of a word") { |
10 | 17 | pending
|
11 |
| - val phrase = new Phrase("one of each") |
12 |
| - val counts = Map("one" -> 1, "of" -> 1, "each" -> 1) |
13 |
| - phrase.wordCount should be (counts) |
| 18 | + WordCount("one fish two fish red fish blue fish").countwords should be( |
| 19 | + Map(("blue", 1), ("two", 1), ("fish", 4), ("one", 1), ("red", 1))) |
14 | 20 | }
|
15 | 21 |
|
16 |
| - it should "count multiple occurrences" in { |
| 22 | + test("handles cramped lists") { |
17 | 23 | pending
|
18 |
| - val phrase = new Phrase("one fish two fish red fish blue fish") |
19 |
| - val counts = Map("one" -> 1, "fish" -> 4, "two" -> 1, "red" -> 1, "blue" -> 1) |
20 |
| - phrase.wordCount should be (counts) |
| 24 | + WordCount("one,two,three").countwords should be( |
| 25 | + Map(("one", 1), ("two", 1), ("three", 1))) |
21 | 26 | }
|
22 | 27 |
|
23 |
| - it should "count everything just once" in { |
| 28 | + test("handles expanded lists") { |
24 | 29 | pending
|
25 |
| - val phrase = new Phrase("all the kings horses and all the kings men") |
26 |
| - phrase.wordCount |
27 |
| - val counts = Map( |
28 |
| - "all" -> 2, "the" -> 2, "kings" -> 2, "horses" -> 1, "and" -> 1, "men" -> 1 |
29 |
| - ) |
30 |
| - phrase.wordCount should be (counts) |
| 30 | + WordCount("one,\ntwo,\nthree").countwords should be( |
| 31 | + Map(("one", 1), ("two", 1), ("three", 1))) |
31 | 32 | }
|
32 | 33 |
|
33 |
| - it should "ignore punctuation" in { |
| 34 | + test("ignore punctuation") { |
34 | 35 | pending
|
35 |
| - val phrase = new Phrase("car : carpet as java : javascript!!&@$%^&") |
36 |
| - val counts = Map( |
37 |
| - "car" -> 1, "carpet" -> 1, "as" -> 1, "java" -> 1, "javascript" -> 1 |
38 |
| - ) |
39 |
| - phrase.wordCount should be (counts) |
| 36 | + WordCount("car: carpet as java: javascript!!&@$%^&").countwords should be( |
| 37 | + Map(("as", 1), ("car", 1), ("java", 1), ("carpet", 1), ("javascript", 1))) |
40 | 38 | }
|
41 | 39 |
|
42 |
| - it should "handle cramped lists" in { |
| 40 | + test("include numbers") { |
43 | 41 | pending
|
44 |
| - val phrase = new Phrase("one,two,three") |
45 |
| - phrase.wordCount should be (Map("one" -> 1, "two" -> 1, "three" -> 1)) |
| 42 | + WordCount("testing, 1, 2 testing").countwords should be( |
| 43 | + Map(("testing", 2), ("1", 1), ("2", 1))) |
46 | 44 | }
|
47 | 45 |
|
48 |
| - it should "include numbers" in { |
| 46 | + test("normalize case") { |
49 | 47 | pending
|
50 |
| - val phrase = new Phrase("testing, 1, 2 testing") |
51 |
| - val counts = Map("testing" -> 2, "1" -> 1, "2" -> 1) |
52 |
| - phrase.wordCount should be (counts) |
| 48 | + WordCount("go Go GO Stop stop").countwords should be( |
| 49 | + Map(("go", 3), ("stop", 2))) |
53 | 50 | }
|
54 | 51 |
|
55 |
| - it should "normalize case" in { |
| 52 | + test("with apostrophes") { |
56 | 53 | pending
|
57 |
| - val phrase = new Phrase("go Go GO") |
58 |
| - val counts = Map("go" -> 3) |
59 |
| - phrase.wordCount should be (counts) |
| 54 | + WordCount("First: don\'t laugh. Then: don\'t cry.").countwords should be( |
| 55 | + Map(("laugh", 1), ("don't", 2), ("then", 1), ("first", 1), ("cry", 1))) |
60 | 56 | }
|
61 | 57 |
|
62 |
| - it should "allow apostrophes" in { |
| 58 | + test("with quotations") { |
63 | 59 | pending
|
64 |
| - val phrase = new Phrase("First: don't laugh. Then: don't cry.") |
65 |
| - val counts = |
66 |
| - Map("first" -> 1, "don't" -> 2, "laugh" -> 1, "then" -> 1, "cry" -> 1) |
67 |
| - phrase.wordCount should be (counts) |
| 60 | + WordCount("Joe can\'t tell between \'large\' and large.").countwords should be( |
| 61 | + Map(("can't", 1), |
| 62 | + ("large", 2), |
| 63 | + ("joe", 1), |
| 64 | + ("between", 1), |
| 65 | + ("tell", 1), |
| 66 | + ("and", 1))) |
68 | 67 | }
|
69 | 68 | }
|
0 commit comments