This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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() { | |
| let examples = [ ("Hello, ", "World!", "Hello, World!"), | |
| ("Another ", "example", "Another example"), | |
| ("Property-based ", "Testing", "Property-based Testing"), | |
| ("Swift ", "rocks", "Swift rocks"), | |
| ("One more ", "thing", "One more thing")] | |
| examples.forEach{ | |
| XCTAssertEqual($0.2, concat(first: $0.0, second: $0.1)) | |
| } |
This file contains hidden or 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 { | |
| if first == "Another " && second == "example" { | |
| return "Another example" | |
| } else { | |
| return "Hello, World!" | |
| } | |
| } |