This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func concat(first : String, second : String) -> String { | |
switch (first, second) { | |
case ("Another ", "example"): return "Another example" | |
case ("Property-based ", "Testing"): return "Property-based Testing" | |
case ("Swift ", "rocks"): return "Swift rocks" | |
case ("One more ", "thing"): return "One more thing" | |
default: return "Hello, World!" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testStringConcat() { | |
for _ in 0 ..< 100 { | |
let a = randomString() | |
let b = randomString() | |
let expected = a + b | |
XCTAssertEqual(expected, concat(first: a, second: b)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testConcatLengthIsEqualToSumOfLengths() { | |
for _ in 0 ..< 100 { | |
let a = randomString() | |
let b = randomString() | |
let result = concat(first: a, second: b) | |
XCTAssertEqual(result.length, a.length + b.length) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testConcatIsAssociative() { | |
for _ in 0 ..< 100 { | |
let a = randomString() | |
let b = randomString() | |
let c = randomString() | |
let result1 = concat(first: concat(first: a, second: b), second: c) | |
let result2 = concat(first: a, second: concat(first: b, second: c)) | |
XCTAssertEqual(result1, result2) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testConcatHasEmptyStringAsNeutralElement() { | |
for _ in 0 ..< 100 { | |
let a = randomString() | |
let result = concat(first: a, second: "") | |
XCTAssertEqual(result, a) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testConcatLengthIsEqualToSumOfLengths() { | |
property("Concatenation length is equal to sum of input lengths") <- forAll { (a : String, b : String) in | |
let output = concat(first: a, second: b) | |
return output.characters.count == a.characters.count + b.characters.count | |
} | |
} | |
func testConcatIsAssociative() { | |
property("Concatenation is associative") <- forAll { (a : String, b : String, c : String) in | |
let output1 = concat(first: concat(first: a, second: b), second: c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property("Whatever property") <- forAll { (a : String) in | |
// Test property | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property("Whatever property") <- forAll(String.arbitrary) { (a : String) in | |
// Test property | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let positiveIntsGen = Int.arbitrary.suchThat{ n in n > 0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let uppercaseCharacterGen = Gen<Character>.fromElementsIn(Character("A")...Character("Z")) |