Sha256: 6e84432024c02ad96e70e1cd9c2a659ec638be06d51f83639ff2640dcf7c8781

Contents?: true

Size: 1.61 KB

Versions: 168

Compression:

Stored size: 1.61 KB

Contents

@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.*

class WordCountSpec extends Specification {

    def 'count one word' () {
        expect: ["word":1] == new WordCount("word").wordCount()
    }

    def 'count one of each' () {
        expect: ["one":1,"of":1,"each":1] == new WordCount("one of each").wordCount()
    }

    def 'count multiple occurrences' () {
        def wordCount = new WordCount("one fish two fish red fish blue fish")
        expect: ["one":1,"fish":4,"two":1,"red":1,"blue":1] == wordCount.wordCount()
    }

    def 'count everything only once' () {
        def wordCount = new WordCount("all the kings horses and all the kings men")
        // call wordCount 2x to verify
        wordCount.wordCount()
        expect: ["all":2,"the":2,"kings":2,"horses":1,"and":1,"men":1] == wordCount.wordCount()
    }

    def 'ignore punctuation' () {
        def wordCount = new WordCount('car : carpet as java : javascript!!&@$%^&')
        expect: ["car":1,"carpet":1,"as":1,"java":1,"javascript":1] == wordCount.wordCount()
    }

    def 'handle no spaces' () {
        expect: ["one":1,"two":1,"three":1] == new WordCount("one,two,three").wordCount()
    }

    def 'include numbers' () {
        expect: ["testing":2,"1":1,"2":1] == new WordCount("testing, 1, 2 testing").wordCount()
    }

    def 'normalize case' () {
        expect: ["go":3] == new WordCount("go Go GO").wordCount()
    }

    def 'handle apostrophes' () {
        def wordCount = new WordCount("First: don't laugh. Then: don't cry.")
        expect: ["first":1,"don't":2,"laugh":1,"then":1,"cry":1] == wordCount.wordCount()
    }
}

Version data entries

168 entries across 168 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.179 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.178 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.177 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.176 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.175 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.174 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.173 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.172 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.171 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.170 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.169 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.167 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.166 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.165 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.164 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.163 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.162 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.161 tracks/groovy/exercises/word-count/WordCountSpec.groovy
trackler-2.2.1.160 tracks/groovy/exercises/word-count/WordCountSpec.groovy