1
import SwiftCheck
2
import Bow
3

4
public class EquatableLaws<A: Equatable & Arbitrary> {
5 1
    public static func check() {
6 1
        identity()
7 1
        commutativity()
8 1
        transitivity()
9
    }
10

11 1
    private static func identity() {
12 1
        property("Identity: Every object is equal to itself") <~ forAll { (a: A) in
13 1
            return a == a
14
        }
15
    }
16

17 1
    private static func commutativity() {
18 1
        property("Equality is commutative") <~ forAll { (a: A, b: A) in
19 1
            return (a == b) == (b == a)
20
        }
21
    }
22
    
23 1
    private static func transitivity() {
24 1
        property("Equality is transitive") <~ forAll { (a: A, b: A, c: A) in
25 1
            // (a == b) && (b == c) --> (a == c)
26 1
            return not((a == b) && (b == c)) || (a == c)
27
        }
28
    }
29
}

Read our documentation on viewing source code .

Loading