Skip to content

Commit e8601ac

Browse files
committed
Merge pull request #10 from typelift/topic/tests-fix
Some minor test fixes and improvements
2 parents 4938968 + 6044df6 commit e8601ac

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

Aquifer/Basic.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,3 @@ private func toListRepr<V>(p: ProxyRepr<X, (), (), V, ()>) -> List<V> {
361361
case .Pure(_): return []
362362
}
363363
}
364-

AquiferTests/ProxyTests.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ class ProxySpec : XCTestCase {
3535
let g = aProxy(g2)
3636
let h = aProxy(h2)
3737

38-
return formulate((f >-> g) |>| h, (f |>| h) >-> (g |>| h))(s, c)
38+
return formulate((f >>->> g) |>| h, (f |>| h) >>->> (g |>| h))(s, c)
3939
}
4040

4141
property("Request distributes over composition") <- forAll { (f2 : AProxy, g2 : AProxy, h2 : AProxy, s : AServer, c : AClient) in
4242
let f = aProxy(f2)
4343
let g = aProxy(g2)
4444
let h = aProxy(h2)
4545

46-
return formulate(f >|> (g >-> h), (f >|> g) >-> (f >|> h))(s, c)
46+
return formulate(f >|> (g >>->> h), (f >|> g) >>->> (f >|> h))(s, c)
4747
}
4848

4949
/// Need closures here. Autoclosures crash Swiftc.
@@ -54,10 +54,15 @@ class ProxySpec : XCTestCase {
5454
formulate({ $0.reflect() } { request($0) }, { respond($0) })(s, c)
5555
}
5656

57-
property("Request Zero Law") <- forAll { (p2 : AProxy, s : AServer, c : AClient) in
57+
property("Request Right Zero Law") <- forAll { (p2 : AProxy, s : AServer, c : AClient) in
5858
let p = aProxy(p2)
5959
return formulate(p >|> Proxy.pure, Proxy.pure)(s, c)
6060
}
61+
62+
property("Respond Left Zero Law") <- forAll { (p2 : AProxy, s : AServer, c : AClient) in
63+
let p = aProxy(p2)
64+
return formulate(Proxy.pure |>| p, Proxy.pure)(s, c)
65+
}
6166

6267
property("Push-Pull respect associativity") <- forAll { (f2 : AProxy, g2 : AProxy, h2 : AProxy, s : AServer, c : AClient) in
6368
let f = aProxy(f2)
@@ -76,12 +81,12 @@ class ProxySpec : XCTestCase {
7681

7782
property("Involution") <- forAll { (p2 : AProxy, s : AServer, c : AClient) in
7883
let p = aProxy(p2)
79-
return formulate({ $0.reflect() } { $0.reflect() } p >-> Proxy.pure, p)(s, c)
84+
return formulate({ $0.reflect() } { $0.reflect() } p, p)(s, c)
8085
}
8186
}
8287

8388
func testCategoricalProperties() {
84-
property("Kleisli Category") <- self.testCategory(>->)(Proxy<Int, Int, Int, Int, Int>.pure)
89+
property("Kleisli Category") <- self.testCategory(>>->>)(Proxy<Int, Int, Int, Int, Int>.pure)
8590
property("Respond Category") <- self.testCategory(|>|)({ respond($0) })
8691
property("Request Category") <- self.testCategory(>|>)({ request($0) })
8792
property("Pull Category") <- self.testCategory(>+>)({ pull($0) })

AquiferTests/TestDefs.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func inc<UO, UI, DI, DO>(n : Int) -> Proxy<UO, UI, DI, DO, Int> {
115115

116116
func correct(str : String) -> String {
117117
if str.isEmpty {
118-
return "return"
118+
return "pure"
119119
}
120120
return str
121121
}
@@ -124,7 +124,7 @@ struct AClient : CustomStringConvertible {
124124
let unAClient : [ClientStep]
125125

126126
var description : String {
127-
return correct(self.unAClient.map({ $0.description }).intersperse(" >-> ").reduce("", combine: +))
127+
return correct(self.unAClient.map({ $0.description }).intersperse(" >>->> ").reduce("", combine: +))
128128
}
129129
}
130130

@@ -149,14 +149,14 @@ func aClient(client : AClient) -> (Int -> Proxy<Int, Int, (), X, Int> /* Client<
149149
return inc
150150
}
151151
})
152-
return p.reduce(Proxy.pure, combine: >->)
152+
return p.reduce(Proxy.pure, combine: >>->>)
153153
}
154154

155155
struct AServer : CustomStringConvertible {
156156
let unAServer : [ServerStep]
157157

158158
var description : String {
159-
return correct(self.unAServer.map({ $0.description }).intersperse(" >-> ").reduce("", combine: +))
159+
return correct(self.unAServer.map({ $0.description }).intersperse(" >>->> ").reduce("", combine: +))
160160
}
161161
}
162162

@@ -180,14 +180,14 @@ func aServer(server : AServer) -> (Int -> Proxy<X, (), Int, Int, Int> /* Server<
180180
case .ServerInc:
181181
return inc
182182
}
183-
}).reduce(Proxy.pure, combine: >->)
183+
}).reduce(Proxy.pure, combine: >>->>)
184184
}
185185

186186
struct AProxy : Hashable, CustomStringConvertible {
187187
let unAProxy : [ProxyStep]
188188

189189
var description : String {
190-
return correct(self.unAProxy.map({ $0.description }).intersperse(" >-> ").reduce("", combine: +))
190+
return correct(self.unAProxy.map({ $0.description }).intersperse(" >>->> ").reduce("", combine: +))
191191
}
192192

193193
var hashValue : Int {
@@ -227,7 +227,7 @@ func aProxy(proxy : AProxy) -> (Int -> Proxy<Int, Int, Int, Int, Int>) {
227227
case .ProxyInc:
228228
return inc
229229
}
230-
}).reduce(Proxy.pure, combine: >->)
230+
}).reduce(Proxy.pure, combine: >>->>)
231231
}
232232

233233
struct ProxyK {
@@ -245,10 +245,13 @@ func formulate(pl : ProxyK.T, _ pr : ProxyK.T)(_ p0 : AServer, _ p1 : AClient) -
245245
}
246246

247247
/// Kleisli Composition.
248-
func >-> <A, B, C, UI, UO, DI, DO>(m1 : A -> Proxy<UI, UO, DI, DO, B>, m2 : B -> Proxy<UI, UO, DI, DO, C>) -> (A -> Proxy<UI, UO, DI, DO, C>) {
248+
infix operator >>->> {
249+
associativity left
250+
precedence 110
251+
}
252+
253+
func >>->> <A, B, C, UI, UO, DI, DO>(m1 : A -> Proxy<UI, UO, DI, DO, B>, m2 : B -> Proxy<UI, UO, DI, DO, C>) -> (A -> Proxy<UI, UO, DI, DO, C>) {
249254
return { r in
250255
return m1(r) >>- m2
251256
}
252257
}
253-
254-

0 commit comments

Comments
 (0)