forked from igorwojda/kotlin-coding-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge.kt
84 lines (70 loc) · 2.21 KB
/
challenge.kt
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
package com.igorwojda.matrix.findrectangle
import org.amshove.kluent.shouldBeEqualTo
import org.junit.jupiter.api.Test
private fun findRectangle(image: List<List<Int>>): List<Int>? {
TODO("not implemented")
}
private class Test {
@Test
fun `find rectangle in image 1`() {
val image = listOf(
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 0, 0, 0, 1),
listOf(1, 1, 1, 0, 0, 0, 1),
listOf(1, 1, 1, 1, 1, 1, 1)
)
findRectangle(image) shouldBeEqualTo listOf(2, 3, 3, 5)
}
@Test
fun `find rectangle in image 2`() {
val image = listOf(
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 0)
)
findRectangle(image) shouldBeEqualTo listOf(4, 6, 4, 6)
}
@Test
fun `find rectangle in image 3`() {
val image = listOf(
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 0, 0),
listOf(1, 1, 1, 1, 1, 0, 0)
)
findRectangle(image) shouldBeEqualTo listOf(3, 5, 4, 6)
}
@Test
fun `find rectangle in image 4`() {
val image = listOf(
listOf(0, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1)
)
findRectangle(image) shouldBeEqualTo listOf(0, 0, 0, 0)
}
@Test
fun `find rectangle in image 5`() {
val image = listOf(
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1),
listOf(0, 0, 1, 1, 1, 1, 1),
listOf(0, 0, 1, 1, 1, 1, 1),
listOf(1, 1, 1, 1, 1, 1, 1)
)
findRectangle(image) shouldBeEqualTo listOf(2, 0, 3, 1)
}
@Test
fun `find rectangle in image that has no background`() {
val image = listOf(
listOf(0)
)
findRectangle(image) shouldBeEqualTo listOf(0, 0, 0, 0)
}
}