|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+import org.junit.Ignore;
|
|
|
2
|
+import org.junit.Test;
|
|
|
3
|
+import org.junit.experimental.runners.Enclosed;
|
|
|
4
|
+import org.junit.runner.RunWith;
|
|
|
5
|
+import org.junit.runners.Parameterized;
|
|
|
6
|
+
|
|
|
7
|
+import java.util.Arrays;
|
|
|
8
|
+import java.util.Collection;
|
|
|
9
|
+
|
|
|
10
|
+import static org.junit.Assert.assertArrayEquals;
|
|
|
11
|
+import static org.junit.Assert.assertEquals;
|
|
|
12
|
+
|
|
|
13
|
+@RunWith(Enclosed.class)
|
|
|
14
|
+public class MatrixTest {
|
|
|
15
|
+
|
|
|
16
|
+ @RunWith(Parameterized.class)
|
|
|
17
|
+ public static class CountRowsTest {
|
|
|
18
|
+ private Matrix matrix;
|
|
|
19
|
+ private int numberOfRows;
|
|
|
20
|
+
|
|
|
21
|
+ @Parameterized.Parameters(name = "{index}: expected matrix constructed with string \n\"{0}\" to have {1} row(s).")
|
|
|
22
|
+ public static Collection<Object[]> data() {
|
|
|
23
|
+ return Arrays.asList(new Object[][]{
|
|
|
24
|
+ {"0", 1},
|
|
|
25
|
+ {"0 1", 1},
|
|
|
26
|
+ { "0\n"
|
|
|
27
|
+ + "1", 2},
|
|
|
28
|
+ { "0 1\n"
|
|
|
29
|
+ + "2 3", 2},
|
|
|
30
|
+ { "0 1 2\n"
|
|
|
31
|
+ + "3 4 5\n"
|
|
|
32
|
+ + "6 7 8", 3}
|
|
|
33
|
+ });
|
|
|
34
|
+ }
|
|
|
35
|
+
|
|
|
36
|
+ public CountRowsTest(String matrixAsString, int numberOfRows) {
|
|
|
37
|
+ this.matrix = new Matrix(matrixAsString);
|
|
|
38
|
+ this.numberOfRows = numberOfRows;
|
|
|
39
|
+ }
|
|
|
40
|
+
|
|
|
41
|
+ @Test
|
|
|
42
|
+ public void countRowsTest() {
|
|
|
43
|
+ assertEquals(numberOfRows, matrix.getRowsCount());
|
|
|
44
|
+ }
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ @Ignore
|
|
|
48
|
+ @RunWith(Parameterized.class)
|
|
|
49
|
+ public static class CountColumnsTest {
|
|
|
50
|
+ private Matrix matrix;
|
|
|
51
|
+ private int numberOfColumns;
|
|
|
52
|
+
|
|
|
53
|
+ @Parameterized.Parameters(name = "{index}: expected matrix constructed with string \n\"{0}\" to have {1} column(s).")
|
|
|
54
|
+ public static Collection<Object[]> data() {
|
|
|
55
|
+ return Arrays.asList(new Object[][]{
|
|
|
56
|
+ {"0", 1},
|
|
|
57
|
+ {"0 1", 2},
|
|
|
58
|
+ { "0\n"
|
|
|
59
|
+ + "1", 1},
|
|
|
60
|
+ { "0 1\n"
|
|
|
61
|
+ + "2 3", 2},
|
|
|
62
|
+ { "0 1 2\n"
|
|
|
63
|
+ + "3 4 5\n"
|
|
|
64
|
+ + "6 7 8", 3}
|
|
|
65
|
+ });
|
|
|
66
|
+ }
|
|
|
67
|
+
|
|
|
68
|
+ public CountColumnsTest(String matrixAsString, int numberOfColumns) {
|
|
|
69
|
+ this.matrix = new Matrix(matrixAsString);
|
|
|
70
|
+ this.numberOfColumns = numberOfColumns;
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ @Test
|
|
|
74
|
+ public void countColumnsTest() {
|
|
|
75
|
+ assertEquals(numberOfColumns, matrix.getColumnsCount());
|
|
|
76
|
+ }
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ @Ignore
|
|
|
80
|
+ @RunWith(Parameterized.class)
|
|
|
81
|
+ public static class GetFirstRowTest {
|
|
|
82
|
+ private Matrix matrix;
|
|
|
83
|
+ private int[] firstRow;
|
|
|
84
|
+
|
|
|
85
|
+ @Parameterized.Parameters(name = "{index}: checking first row of matrix constructed with string \n\"{0}\".")
|
|
|
86
|
+ public static Collection<Object[]> data() {
|
|
|
87
|
+ return Arrays.asList(new Object[][]{
|
|
|
88
|
+ {"0", new int[] {0}},
|
|
|
89
|
+ {"0 1", new int[] {0, 1}},
|
|
|
90
|
+ { "0\n"
|
|
|
91
|
+ + "1", new int[] {0}},
|
|
|
92
|
+ { "0 1\n"
|
|
|
93
|
+ + "2 3", new int[] {0, 1}},
|
|
|
94
|
+ { "0 1 2\n"
|
|
|
95
|
+ + "3 4 5\n"
|
|
|
96
|
+ + "6 7 8", new int[] {0, 1, 2}}
|
|
|
97
|
+ });
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ public GetFirstRowTest(String matrixAsString, int[] firstRow) {
|
|
|
101
|
+ this.matrix = new Matrix(matrixAsString);
|
|
|
102
|
+ this.firstRow = firstRow;
|
|
|
103
|
+ }
|
|
|
104
|
+
|
|
|
105
|
+ @Test
|
|
|
106
|
+ public void getFirstRowTest() {
|
|
|
107
|
+ assertArrayEquals(firstRow, matrix.getRow(0));
|
|
|
108
|
+ }
|
|
|
109
|
+ }
|
|
|
110
|
+
|
|
|
111
|
+ @Ignore
|
|
|
112
|
+ @RunWith(Parameterized.class)
|
|
|
113
|
+ public static class GetLastRowTest {
|
|
|
114
|
+ private Matrix matrix;
|
|
|
115
|
+ private int[] lastRow;
|
|
|
116
|
+
|
|
|
117
|
+ @Parameterized.Parameters(name = "{index}: checking last row of matrix constructed with string \n\"{0}\".")
|
|
|
118
|
+ public static Collection<Object[]> data() {
|
|
|
119
|
+ return Arrays.asList(new Object[][]{
|
|
|
120
|
+ {"0", new int[] {0}},
|
|
|
121
|
+ {"0 1", new int[] {0, 1}},
|
|
|
122
|
+ { "0\n"
|
|
|
123
|
+ + "1", new int[] {1}},
|
|
|
124
|
+ { "0 1\n"
|
|
|
125
|
+ + "2 3", new int[] {2, 3}},
|
|
|
126
|
+ { "0 1 2\n"
|
|
|
127
|
+ + "3 4 5\n"
|
|
|
128
|
+ + "6 7 8", new int[] {6, 7, 8}}
|
|
|
129
|
+ });
|
|
|
130
|
+ }
|
|
|
131
|
+
|
|
|
132
|
+ public GetLastRowTest(String matrixAsString, int[] lastRow) {
|
|
|
133
|
+ this.matrix = new Matrix(matrixAsString);
|
|
|
134
|
+ this.lastRow = lastRow;
|
|
|
135
|
+ }
|
|
|
136
|
+
|
|
|
137
|
+ @Test
|
|
|
138
|
+ public void getLastRowTest() {
|
|
|
139
|
+ assertArrayEquals(lastRow, matrix.getRow(matrix.getRowsCount() - 1));
|
|
|
140
|
+ }
|
|
|
141
|
+ }
|
|
|
142
|
+
|
|
|
143
|
+ @Ignore
|
|
|
144
|
+ @RunWith(Parameterized.class)
|
|
|
145
|
+ public static class GetFirstColumnTest {
|
|
|
146
|
+ private Matrix matrix;
|
|
|
147
|
+ private int[] firstColumn;
|
|
|
148
|
+
|
|
|
149
|
+ @Parameterized.Parameters(name = "{index}: checking first column of matrix constructed with string \n\"{0}\".")
|
|
|
150
|
+ public static Collection<Object[]> data() {
|
|
|
151
|
+ return Arrays.asList(new Object[][]{
|
|
|
152
|
+ {"0", new int[] {0}},
|
|
|
153
|
+ {"0 1", new int[] {0}},
|
|
|
154
|
+ { "0\n"
|
|
|
155
|
+ + "1", new int[] {0, 1}},
|
|
|
156
|
+ { "0 1\n"
|
|
|
157
|
+ + "2 3", new int[] {0, 2}},
|
|
|
158
|
+ { "0 1 2\n"
|
|
|
159
|
+ + "3 4 5\n"
|
|
|
160
|
+ + "6 7 8", new int[] {0, 3, 6}}
|
|
|
161
|
+ });
|
|
|
162
|
+ }
|
|
|
163
|
+
|
|
|
164
|
+ public GetFirstColumnTest(String matrixAsString, int[] firstColumn) {
|
|
|
165
|
+ this.matrix = new Matrix(matrixAsString);
|
|
|
166
|
+ this.firstColumn = firstColumn;
|
|
|
167
|
+ }
|
|
|
168
|
+
|
|
|
169
|
+ @Test
|
|
|
170
|
+ public void getFirstColumnTest() {
|
|
|
171
|
+ assertArrayEquals(firstColumn, matrix.getColumn(0));
|
|
|
172
|
+ }
|
|
|
173
|
+ }
|
|
|
174
|
+
|
|
|
175
|
+
|
|
|
176
|
+ @Ignore
|
|
|
177
|
+ @RunWith(Parameterized.class)
|
|
|
178
|
+ public static class GetLastColumnTest {
|
|
|
179
|
+ private Matrix matrix;
|
|
|
180
|
+ private int[] lastColumn;
|
|
|
181
|
+
|
|
|
182
|
+ @Parameterized.Parameters(name = "{index}: checking last column of matrix constructed with string \n\"{0}\".")
|
|
|
183
|
+ public static Collection<Object[]> data() {
|
|
|
184
|
+ return Arrays.asList(new Object[][]{
|
|
|
185
|
+ {"0", new int[] {0}},
|
|
|
186
|
+ {"0 1", new int[] {1}},
|
|
|
187
|
+ { "0\n"
|
|
|
188
|
+ + "1", new int[] {0, 1}},
|
|
|
189
|
+ { "0 1\n"
|
|
|
190
|
+ + "2 3", new int[] {1, 3}},
|
|
|
191
|
+ { "0 1 2\n"
|
|
|
192
|
+ + "3 4 5\n"
|
|
|
193
|
+ + "6 7 8", new int[] {2, 5, 8}}
|
|
|
194
|
+ });
|
|
|
195
|
+ }
|
|
|
196
|
+
|
|
|
197
|
+ public GetLastColumnTest(String matrixAsString, int[] lastColumn) {
|
|
|
198
|
+ this.matrix = new Matrix(matrixAsString);
|
|
|
199
|
+ this.lastColumn = lastColumn;
|
|
|
200
|
+ }
|
|
|
201
|
+
|
|
|
202
|
+ @Test
|
|
|
203
|
+ public void getLastColumnTest() {
|
|
|
204
|
+ assertArrayEquals(lastColumn, matrix.getColumn(matrix.getColumnsCount() - 1));
|
|
|
205
|
+ }
|
|
|
206
|
+ }
|
|
|
207
|
+}
|