@@ -25,14 +25,58 @@ public func == (
25
25
26
26
// FIXME(prext): move this struct to the point of use.
27
27
Algorithm . test ( " min,max " ) {
28
- expectEqual ( 2 , min ( 3 , 2 ) )
29
- expectEqual ( 3 , min ( 3 , 7 , 5 ) )
30
- expectEqual ( 3 , max ( 3 , 2 ) )
31
- expectEqual ( 7 , max ( 3 , 7 , 5 ) )
32
-
33
- // FIXME: add tests that check that min/max return the
34
- // first element of the sequence (by reference equality) that satisfy the
35
- // condition.
28
+ // Identities are unique in this set.
29
+ let a1 = MinimalComparableValue ( 0 , identity: 1 )
30
+ let a2 = MinimalComparableValue ( 0 , identity: 2 )
31
+ let a3 = MinimalComparableValue ( 0 , identity: 3 )
32
+ let b1 = MinimalComparableValue ( 1 , identity: 4 )
33
+ let b2 = MinimalComparableValue ( 1 , identity: 5 )
34
+ let b3 = MinimalComparableValue ( 1 , identity: 6 )
35
+ let c1 = MinimalComparableValue ( 2 , identity: 7 )
36
+ let c2 = MinimalComparableValue ( 2 , identity: 8 )
37
+ let c3 = MinimalComparableValue ( 2 , identity: 9 )
38
+
39
+ // 2-arg min()
40
+ expectEqual ( a1. identity, min ( a1, b1) . identity)
41
+ expectEqual ( a1. identity, min ( b1, a1) . identity)
42
+ expectEqual ( a1. identity, min ( a1, a2) . identity)
43
+
44
+ // 2-arg max()
45
+ expectEqual ( c1. identity, max ( c1, b1) . identity)
46
+ expectEqual ( c1. identity, max ( b1, c1) . identity)
47
+ expectEqual ( c1. identity, max ( c2, c1) . identity)
48
+
49
+ // 3-arg min()
50
+ expectEqual ( a1. identity, min ( a1, b1, c1) . identity)
51
+ expectEqual ( a1. identity, min ( b1, a1, c1) . identity)
52
+ expectEqual ( a1. identity, min ( c1, b1, a1) . identity)
53
+ expectEqual ( a1. identity, min ( c1, a1, b1) . identity)
54
+ expectEqual ( a1. identity, min ( a1, a2, a3) . identity)
55
+ expectEqual ( a1. identity, min ( a1, a2, b1) . identity)
56
+ expectEqual ( a1. identity, min ( a1, b1, a2) . identity)
57
+ expectEqual ( a1. identity, min ( b1, a1, a2) . identity)
58
+
59
+ // 3-arg max()
60
+ expectEqual ( c1. identity, max ( c1, b1, a1) . identity)
61
+ expectEqual ( c1. identity, max ( a1, c1, b1) . identity)
62
+ expectEqual ( c1. identity, max ( b1, a1, c1) . identity)
63
+ expectEqual ( c1. identity, max ( b1, c1, a1) . identity)
64
+ expectEqual ( c1. identity, max ( c3, c2, c1) . identity)
65
+ expectEqual ( c1. identity, max ( c2, c1, b1) . identity)
66
+ expectEqual ( c1. identity, max ( c2, b1, c1) . identity)
67
+ expectEqual ( c1. identity, max ( b1, c2, c1) . identity)
68
+
69
+ // 4-arg min()
70
+ expectEqual ( a1. identity, min ( a1, b1, a2, b2) . identity)
71
+ expectEqual ( a1. identity, min ( b1, a1, a2, b2) . identity)
72
+ expectEqual ( a1. identity, min ( c1, b1, b2, a1) . identity)
73
+ expectEqual ( a1. identity, min ( c1, b1, a1, a2) . identity)
74
+
75
+ // 4-arg max()
76
+ expectEqual ( c1. identity, max ( c2, b1, c1, b2) . identity)
77
+ expectEqual ( c1. identity, max ( b1, c2, c1, b2) . identity)
78
+ expectEqual ( c1. identity, max ( a1, b1, b2, c1) . identity)
79
+ expectEqual ( c1. identity, max ( a1, b1, c2, c1) . identity)
36
80
}
37
81
38
82
Algorithm . test ( " sorted/strings " )
0 commit comments