Skip to content

Instantly share code, notes, and snippets.

@RyanBreaker
Created October 4, 2014 17:23
Show Gist options
  • Select an option

  • Save RyanBreaker/20c436afe149089e89c5 to your computer and use it in GitHub Desktop.

Select an option

Save RyanBreaker/20c436afe149089e89c5 to your computer and use it in GitHub Desktop.
import XCTest
class WordCountTest: XCTestCase {
func XCTAssertEqualDictionaries(first: [String: Int], second: [String: Int]) {
XCTAssertEqual(first, second)
}
func testCountOneWord() {
let words = WordCount(words: "word")
let expected = ["word": 1]
let result = words.count()
XCTAssertEqualDictionaries(expected, second: result)
}
func testCountOneOfEeach() {
let words = WordCount(words: "one of each")
let expected = ["one" : 1, "of" : 1, "each" : 1 ]
let result = words.count();
XCTAssertEqualDictionaries(expected, second: result)
}
func testCountMultipleOccurrences() {
let words = WordCount(words: "one fish two fish red fish blue fish")
let expected = ["one" : 1, "fish" : 4, "two" : 1, "red" : 1, "blue" : 1 ]
let result = words.count()
XCTAssertEqualDictionaries(expected, second:
result)
}
func testIgnorePunctation() {
let words = WordCount(words: "car : carpet as java : javascript!!&$%^&")
let expected = ["car" : 1, "carpet" : 1, "as" : 1, "java" : 1, "javascript" : 1 ]
let result = words.count()
XCTAssertEqualDictionaries(expected, second: result)
}
func testIncludeNumbers() {
let words = WordCount(words: "testing, 1, 2 testing")
let expected = [ "testing" : 2, "1" : 1, "2" : 1 ]
let result = words.count()
XCTAssertEqualDictionaries(expected, second: result)
}
func testNormalizeCase() {
let words = WordCount(words:"go Go GO")
let expected = [ "go" : 3]
let result = words.count()
XCTAssertEqualDictionaries(expected, second: result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment