1
+ package q2768
2
+
3
+ import org.junit.jupiter.api.Assertions.assertArrayEquals
4
+ import org.junit.jupiter.params.ParameterizedTest
5
+ import org.junit.jupiter.params.provider.MethodSource
6
+ import java.util.stream.Stream
7
+
8
+ class SolutionTest {
9
+ val solution = Solution ()
10
+
11
+ @ParameterizedTest
12
+ @MethodSource(" testCases" )
13
+ fun countBlackBlocksCorrect (testCase : TestCase ) {
14
+ val actual = solution.countBlackBlocks(testCase.width, testCase.height, testCase.blackBoxes)
15
+ assertArrayEquals(testCase.expected, actual)
16
+ }
17
+
18
+ data class TestCase (
19
+ val width : Int ,
20
+ val height : Int ,
21
+ val blackBoxes : Array <IntArray >,
22
+ val expected : LongArray
23
+ )
24
+
25
+ companion object {
26
+ @JvmStatic
27
+ fun testCases () = Stream .of(
28
+ TestCase (
29
+ 2 , 2 ,
30
+ arrayOf(),
31
+ longArrayOf(1L , 0L , 0L , 0L , 0L )
32
+ ),
33
+ TestCase (
34
+ 2 , 2 ,
35
+ arrayOf(intArrayOf(0 , 0 )),
36
+ longArrayOf(0L , 1L , 0L , 0L , 0L )
37
+ ),
38
+ TestCase (
39
+ 2 , 2 ,
40
+ arrayOf(intArrayOf(0 , 0 ), intArrayOf(0 , 1 )),
41
+ longArrayOf(0L , 0L , 1L , 0L , 0L )
42
+ ),
43
+ TestCase (
44
+ 2 , 2 ,
45
+ arrayOf(intArrayOf(0 , 0 ), intArrayOf(0 , 1 ), intArrayOf(1 , 0 )),
46
+ longArrayOf(0L , 0L , 0L , 1L , 0L )
47
+ ),
48
+ TestCase (
49
+ 2 , 2 ,
50
+ arrayOf(intArrayOf(0 , 0 ), intArrayOf(0 , 1 ), intArrayOf(1 , 0 ), intArrayOf(1 , 1 )),
51
+ longArrayOf(0L , 0L , 0L , 0L , 1L )
52
+ ),
53
+ TestCase (
54
+ 3 , 3 ,
55
+ arrayOf(intArrayOf(1 , 1 )),
56
+ longArrayOf(0L , 4L , 0L , 0L , 0L )
57
+ ),
58
+ TestCase (
59
+ 10 , 10 ,
60
+ arrayOf(
61
+ intArrayOf(0 , 0 ),
62
+ intArrayOf(1 , 1 ),
63
+ intArrayOf(2 , 2 ),
64
+ intArrayOf(3 , 3 ),
65
+ intArrayOf(4 , 4 ),
66
+ intArrayOf(5 , 5 ),
67
+ intArrayOf(6 , 6 ),
68
+ intArrayOf(7 , 7 ),
69
+ intArrayOf(8 , 8 ),
70
+ intArrayOf(9 , 9 ),
71
+ ),
72
+ longArrayOf(56L , 16L , 9L , 0L , 0L )
73
+ ),
74
+ TestCase (
75
+ 10000 , 10000 ,
76
+ Array (1000 ) { it ->
77
+ intArrayOf(it + 1 , it + 1 )
78
+ },
79
+ longArrayOf(99977000L , 2002L , 999L , 0L , 0L )
80
+ ),
81
+ TestCase (
82
+ 100000 , 100000 ,
83
+ Array (10000 ) { it ->
84
+ intArrayOf(it + 1 , it + 1 )
85
+ },
86
+ longArrayOf(9999770000L , 20002L , 9999L , 0L , 0L )
87
+ )
88
+ )
89
+ }
90
+ }
0 commit comments