Skip to content

Commit b01dabf

Browse files
committed
tp4 step 5
1 parent 98a1e57 commit b01dabf

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

tp4/src/main/kotlin/fmt/kotlin/fundamentals/Container.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ sealed class Container(
1010
}
1111
}
1212

13+
val equipments: List<String> = emptyList()
14+
1315
fun containersNeededToPourIn(container: Container) = when (this) {
1416
is Tank -> when (container) {
1517
is Barrel, is FixedVolumeContainer -> capacity / container.capacity

tp4/src/test/kotlin/fmt/kotlin/fundamentals/ContainerTest.kt

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import strikt.api.expectCatching
66
import strikt.api.expectThat
77
import strikt.api.expectThrows
88
import strikt.assertions.isA
9+
import strikt.assertions.isEmpty
910
import strikt.assertions.isEqualTo
1011
import strikt.assertions.isFailure
1112
import strikt.assertions.isSuccess
@@ -22,7 +23,7 @@ class ContainerTest {
2223

2324
@Test
2425
fun `Tank should be a Container`() {
25-
expectThat(Tank(3000000)).isA<Container>()
26+
expectThat(Tank(3000000, emptyList())).isA<Container>()
2627
}
2728
}
2829

@@ -53,21 +54,21 @@ class ContainerTest {
5354
@Test
5455
fun `Tank should be created with 3000000 cL`() {
5556
expectCatching {
56-
Tank(3000000)
57+
Tank(3000000, emptyList())
5758
}.isSuccess()
5859
}
5960

6061
@Test
6162
fun `Tank should not be created with 1800000 cL`() {
6263
expectCatching {
63-
Tank(1800000)
64+
Tank(1800000, emptyList())
6465
}.isFailure()
6566
}
6667

6768
@Test
6869
fun `Tank should not be created with 12000000 cL`() {
6970
expectCatching {
70-
Tank(12000000)
71+
Tank(12000000, emptyList())
7172
}.isFailure()
7273
}
7374
}
@@ -100,38 +101,38 @@ class ContainerTest {
100101
@Test
101102
fun `should not be able to pour Tank in Tank`() {
102103
expectThrows<IllegalArgumentException> {
103-
Tank(3000000).containersNeededToPourIn(Tank(3000000))
104+
Tank(3000000, emptyList()).containersNeededToPourIn(Tank(3000000, emptyList()))
104105
}
105106
}
106107

107108
@Test
108109
fun `should be able to pour Tank in Barrel`() {
109110
expectCatching {
110-
Tank(3000000).containersNeededToPourIn(Barrel(20000))
111+
Tank(3000000, emptyList()).containersNeededToPourIn(Barrel(20000))
111112
}.isSuccess()
112113
.isEqualTo(150)
113114
}
114115

115116
@Test
116117
fun `should be able to pour Tank in Magnum`() {
117118
expectCatching {
118-
Tank(3000000).containersNeededToPourIn(Magnum())
119+
Tank(3000000, emptyList()).containersNeededToPourIn(Magnum())
119120
}.isSuccess()
120121
.isEqualTo(20000)
121122
}
122123

123124
@Test
124125
fun `should be able to pour Tank in Bottle`() {
125126
expectCatching {
126-
Tank(3000000).containersNeededToPourIn(Bottle())
127+
Tank(3000000, emptyList()).containersNeededToPourIn(Bottle())
127128
}.isSuccess()
128129
.isEqualTo(40000)
129130
}
130131

131132
@Test
132133
fun `should not be able to pour Barrel in Tank`() {
133134
expectThrows<IllegalArgumentException> {
134-
Barrel(20000).containersNeededToPourIn(Tank(3000000))
135+
Barrel(20000).containersNeededToPourIn(Tank(3000000, emptyList()))
135136
}
136137
}
137138

@@ -161,7 +162,7 @@ class ContainerTest {
161162
@Test
162163
fun `should not be able to pour Magnum in Tank`() {
163164
expectThrows<IllegalArgumentException> {
164-
Magnum().containersNeededToPourIn(Tank(3000000))
165+
Magnum().containersNeededToPourIn(Tank(3000000, emptyList()))
165166
}
166167
}
167168

@@ -189,7 +190,7 @@ class ContainerTest {
189190
@Test
190191
fun `should not be able to pour Bottle in Tank`() {
191192
expectThrows<IllegalArgumentException> {
192-
Bottle().containersNeededToPourIn(Tank(3000000))
193+
Bottle().containersNeededToPourIn(Tank(3000000, emptyList()))
193194
}
194195
}
195196

@@ -214,4 +215,36 @@ class ContainerTest {
214215
}
215216
}
216217
}
218+
219+
@Nested
220+
inner class Equipments {
221+
222+
@Test
223+
fun `Tank equipments should be what I set it to`() {
224+
expectThat(Tank(3000000, listOf("Porte", "Contrôle de température", "Dégustateur"))) {
225+
get { equipments }.isEqualTo(listOf("Porte", "Contrôle de température", "Dégustateur"))
226+
}
227+
}
228+
229+
@Test
230+
fun `Barrel equipments should be Robinet, Bonde`() {
231+
expectThat(Barrel(22500)) {
232+
get { equipments }.isEqualTo(listOf("Robinet", "Bonde"))
233+
}
234+
}
235+
236+
@Test
237+
fun `Magnum should not have equipments`() {
238+
expectThat(Magnum()) {
239+
get { equipments }.isEmpty()
240+
}
241+
}
242+
243+
@Test
244+
fun `Bottle should not have equipments`() {
245+
expectThat(Bottle()) {
246+
get { equipments }.isEmpty()
247+
}
248+
}
249+
}
217250
}

0 commit comments

Comments
 (0)