Sha256: 612dd5086e13ac207e365cfb11f58fdcdd8f23f6229cd4742b9cd6c24483d093

Contents?: true

Size: 1.83 KB

Versions: 227

Compression:

Stored size: 1.83 KB

Contents

import org.junit.Test
import static org.junit.Assert.assertEquals

class PhraseTest {
  @Test
  void countOneWord() {
    def phrase = new Phrase("word")
    def counts = ["word":1]
    assertEquals counts, phrase.wordCount()
  }

  @Test
  void countOneOfEach() {
    def phrase = new Phrase("one of each")
    def counts = ["one":1,"of":1,"each":1]
    assertEquals counts, phrase.wordCount()
  }

  @Test
  void countMultipleOccurrences() {
    def phrase = new Phrase("one fish two fish red fish blue fish")
    def counts = ["one":1,"fish":4,"two":1,"red":1,"blue":1]
    assertEquals counts, phrase.wordCount()
  }

  @Test
  void countEverythingOnlyOnce() {
    def phrase = new Phrase("all the kings horses and all the kings men") 
    def counts = ["all":2,"the":2,"kings":2,"horses":1,"and":1,"men":1]
    // call wordCount 2x to verify 
    phrase.wordCount()
    assertEquals counts, phrase.wordCount()
  }

  @Test
  void ignorePunctuation() {
    def phrase = new Phrase('car : carpet as java : javascript!!&@$%^&')
    def counts = ["car":1,"carpet":1,"as":1,"java":1,"javascript":1]
    assertEquals counts, phrase.wordCount()
  }

  @Test
  void handleNoSpaces() {
    def phrase = new Phrase("one,two,three") 
    def counts = ["one":1,"two":1,"three":1]
    assertEquals counts, phrase.wordCount()
  }

  @Test
  void includeNumbers() {
    def phrase = new Phrase("testing, 1, 2 testing")
    def counts = ["testing":2,"1":1,"2":1]
    assertEquals counts, phrase.wordCount()
  }

  @Test
  void normalizeCase() {
    def phrase = new Phrase("go Go GO")
    def counts = ["go":3]
    assertEquals counts, phrase.wordCount()
  }

  @Test
  void handleApostrophes() {
    def phrase = new Phrase("First: don't laugh. Then: don't cry.") 
    def counts = ["first":1,"don't":2,"laugh":1,"then":1,"cry":1]
    assertEquals counts, phrase.wordCount()
  }
}

Version data entries

227 entries across 227 versions & 1 rubygems

Version Path
trackler-2.1.0.52 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.51 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.50 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.49 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.48 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.47 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.46 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.45 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.44 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.43 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.42 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.41 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.40 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.39 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.38 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.37 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.36 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.34 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.33 tracks/groovy/exercises/word-count/PhraseTest.groovy
trackler-2.1.0.32 tracks/groovy/exercises/word-count/PhraseTest.groovy