1
import SwiftCheck
2
import Bow
3

4
public class ComparableLaws<A: Comparable & Arbitrary> {
5
    
6 1
    public static func check() {
7 1
        reflexivityOfLessThanOrEqual()
8 1
        antisymmetryOfLessThanOrEqual()
9 1
        transitivityOfLessThanOrEqual()
10 1
        
11 1
        antireflexivityOfLessThan()
12 1
        asymmetryOfLessThan()
13 1
        transitivityOfLessThan()
14 1
        
15 1
        reflexivityOfGreaterThanOrEqual()
16 1
        antisymmetryOfGreaterThanOrEqual()
17 1
        transitivityOfGreaterThanOrEqual()
18 1
        
19 1
        antireflexivityOfGreaterThan()
20 1
        asymmetryOfGreaterThan()
21 1
        transitivityOfGreaterThan()
22 1
        
23 1
        sortConsistentWithMaxMin()
24
    }
25
    
26 1
    private static func reflexivityOfLessThanOrEqual() {
27 1
        property("Reflexivity of <=") <~ forAll { (x: A) in
28 1
            return x <= x
29
        }
30
    }
31
    
32 1
    private static func antisymmetryOfLessThanOrEqual() {
33 1
        property("Antisymetry of <=") <~ forAll { (x: A, y: A) in
34 1
            return (x <= y && y <= x && x == y) || x != y
35
        }
36
    }
37
    
38 1
    private static func transitivityOfLessThanOrEqual() {
39 1
        property("Transitivity of <=") <~ forAll { (x: A, y: A, z: A) in
40 1
            return !(x <= y && y <= z) || x <= z
41
        }
42
    }
43
    
44 1
    private static func antireflexivityOfLessThan() {
45 1
        property("Antireflexivity of <") <~ forAll { (x: A) in
46 1
            return !(x < x)
47
        }
48
    }
49
    
50 1
    private static func asymmetryOfLessThan() {
51 1
        property("Asymmetry of <") <~ forAll { (x: A, y: A) in
52 1
            return xor(x < y, y < x) || x == y
53
        }
54
    }
55
    
56 1
    private static func transitivityOfLessThan() {
57 1
        property("Transitivity of <") <~ forAll { (x: A, y: A, z: A) in
58 1
            return !(x < y && y < z) || x < z
59
        }
60
    }
61
    
62 1
    private static func reflexivityOfGreaterThanOrEqual() {
63 1
        property("Reflexivity of >=") <~ forAll { (x: A) in
64 1
            return x >= x
65
        }
66
    }
67
    
68 1
    private static func antisymmetryOfGreaterThanOrEqual() {
69 1
        property("Antisymetry of >=") <~ forAll { (x: A, y: A) in
70 1
            return (x >= y && y >= x && x == y) || x != y
71
        }
72
    }
73
    
74 1
    private static func transitivityOfGreaterThanOrEqual() {
75 1
        property("Transitivity of >=") <~ forAll { (x: A, y: A, z: A) in
76 1
            return !(x >= y && y >= z) || x >= z
77
        }
78
    }
79
    
80 1
    private static func antireflexivityOfGreaterThan() {
81 1
        property("Antireflexivity of >") <~ forAll { (x: A) in
82 1
            return !(x > x)
83
        }
84
    }
85
    
86 1
    private static func asymmetryOfGreaterThan() {
87 1
        property("Asymmetry of >") <~ forAll { (x: A, y: A) in
88 1
            return xor(x > y, y > x) || x == y
89
        }
90
    }
91
    
92 1
    private static func transitivityOfGreaterThan() {
93 1
        property("Transitivity of >") <~ forAll { (x: A, y: A, z: A) in
94 1
            return !(x > y && y > z) || x > z
95
        }
96
    }
97
    
98 1
    private static func sortConsistentWithMaxMin() {
99 1
        property("Sort is consistent with max and min") <~ forAll { (x: A, y: A) in
100 1
            let sorted = A.sort(x, y)
101 1
            return sorted.0 == A.max(x, y) && sorted.1 == A.min(x, y)
102
        }
103
    }
104
}

Read our documentation on viewing source code .

Loading