-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathtest_protocol_reorder_requirements.swift
94 lines (75 loc) · 1.7 KB
/
test_protocol_reorder_requirements.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// RUN: %target-resilience-test --no-backward-deployment
// REQUIRES: executable_test
import StdlibUnittest
import protocol_reorder_requirements
var ProtocolReorderRequirementsTest = TestSuite("ProtocolReorderRequirements")
var log = [String]()
struct MyBassinet : Bed {
func squiggle() {
log.append("nap time")
}
}
struct MyOnesie : Outfit {
let size = 3
}
struct SillyBaby : Baby {
func eat() {
log.append("hangry!")
}
func sleep(in bassinet: MyBassinet) {
bassinet.squiggle()
}
func wear(outfit: MyOnesie) {
log.append("wearing outfit size \(outfit.size)")
}
func poop() {
log.append("change the diaper")
}
func cry() {
log.append("waaaaah!")
}
func wiggle() {
log.append("time to wiggle!")
}
let outfitSize = 3
}
func typicalDay<B : Baby>(for baby: B,
sleepingIn bed: B.Bassinet,
wearing outfit: B.Onesie) {
baby.wear(outfit: outfit)
baby.sleep(in: bed)
baby.cry()
baby.poop()
baby.cry()
baby.sleep(in: bed)
baby.eat()
baby.cry()
}
ProtocolReorderRequirementsTest.test("ReorderProtocolRequirements") {
let baby = SillyBaby()
let bed = MyBassinet()
let outfit = MyOnesie()
typicalDay(for: baby, sleepingIn: bed, wearing: outfit)
expectEqual(log, [
"wearing outfit size 3",
"nap time",
"waaaaah!",
"change the diaper",
"waaaaah!",
"nap time",
"hangry!",
"waaaaah!"
])
log = []
goodDay(for: baby, sleepingIn: bed, wearing: outfit)
expectEqual(log, [
"wearing outfit size 3",
"nap time",
"change the diaper",
"nap time",
"hangry!",
"nap time",
"time to wiggle!"
])
}
runAllTests()