forked from RasPat1/practice-codewars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkyScrapersTest.java
211 lines (189 loc) · 7.12 KB
/
SkyScrapersTest.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
import java.util.*;
public class SkyScrapersTest {
private static int clues[][] = {
{ 2, 2, 1, 3,
2, 2, 3, 1,
1, 2, 2, 3,
3, 2, 1, 3 },
{ 0, 0, 1, 2,
0, 2, 0, 0,
0, 3, 0, 0,
0, 1, 0, 0 },
{ 1, 2, 2, 3,
3, 2, 1, 3,
2, 2, 1, 3,
2, 2, 3, 1}
};
private static int outcomes[][][] = {
{ { 1, 3, 4, 2 },
{ 4, 2, 1, 3 },
{ 3, 4, 2, 1 },
{ 2, 1, 3, 4 } },
{ { 2, 1, 4, 3 },
{ 3, 4, 1, 2 },
{ 4, 2, 3, 1 },
{ 1, 3, 2, 4 } },
{ { 4, 3, 1, 2 },
{ 1, 2, 4, 3 },
{ 3, 1, 2, 4 },
{ 2, 4, 3, 1 } },
};
private static int whacks[][][] = {
{ { 1, 3, 4, 2 },
{ 4, 2, 1, 3 },
{ 4, 4, 2, 1 },
{ 0, 0, 0, 0 } },
{ { 2, 1, 4, 3 },
{ 3, 4, 1, 2 },
{ 4, 2, 3, 1 },
{ 1, 3, 2, 4 } }
};
@Test
public void testIsValid () {
assertEquals(false, SkyScrapers.isValidCol(whacks[0]));
assertEquals(true, SkyScrapers.isValidCol(whacks[1]));
}
@Test
public void testRowCol () {
int[][] testSols = {
{1,3,4,2},
{1,4,4,0},
{1,2,4,4},
{4,4,2,1}
};
assertArraysEquals(testSols[0], SkyScrapers.getRowCol(whacks[0], 15));
assertArraysEquals(testSols[1], SkyScrapers.getRowCol(whacks[0], 0));
assertArraysEquals(testSols[2], SkyScrapers.getRowCol(whacks[0], 6));
assertArraysEquals(testSols[3], SkyScrapers.getRowCol(whacks[0], 13));
}
public void assertArraysEquals(int[] a, int[] b) {
// System.out.println(Arrays.toString(a));
// System.out.println(Arrays.toString(b));
for (int i = 0; i < a.length; i++) {
assertEquals(a[i], b[i]);
}
}
@Test
public void testClueSafe () {
assertEquals(false, SkyScrapers.isClueSafe(whacks[0], clues[0], false));
assertEquals(false, SkyScrapers.isClueSafe(whacks[1], clues[0], false));
// SkyScrapers.printArr(whacks[0]);
// System.out.println(Arrays.toString(clues[1]));
assertEquals(true, SkyScrapers.isClueSafe(whacks[0], clues[1], false));
assertEquals(true, SkyScrapers.isClueSafe(whacks[1], clues[1], false));
}
// @Test
// public void testSolvePuzzle1 () {
// long start = System.currentTimeMillis();
// assertEquals (SkyScrapers.solvePuzzle (clues[0]), outcomes[0]);
// long timeTaken = System.currentTimeMillis() - start;
// System.out.println("4x4-1 time taken: " + timeTaken + "ms");
// }
// @Test
// public void testSolvePuzzle2 () {
// long start = System.currentTimeMillis();
// assertEquals (SkyScrapers.solvePuzzle (clues[1]), outcomes[1]);
// long timeTaken = System.currentTimeMillis() - start;
// System.out.println("4x4-2 time taken: " + timeTaken + "ms");
// }
// @Test
// public void testSolvePuzzle3 () {
// long start = System.currentTimeMillis();
// assertEquals (outcomes[2], SkyScrapers.solvePuzzle (clues[2]));
// long timeTaken = System.currentTimeMillis() - start;
// System.out.println("4x4-3 time taken: " + timeTaken + "ms");
// }
/******************************************************************************
5x5
******************************************************************************/
// @Test
// public void testSolvePuzzle51 () {
// int[] clues = {1, 2, 3, 4, 5,
// 5, 4, 3, 2, 1,
// 1, 2, 2, 2, 2,
// 2, 2, 2, 2, 1};
// int[][] outcome = {{ 5, 4, 3, 2, 1},
// { 1, 5, 4, 3, 2},
// { 2, 1, 5, 4, 3},
// { 3, 2, 1, 5, 4},
// { 4, 3, 2, 1, 5}};
// long start = System.currentTimeMillis();
// assertEquals(outcome, SkyScrapers.solvePuzzle(clues));
// long timeTaken = System.currentTimeMillis() - start;
// System.out.println("5x5 time: " + timeTaken + "ms");
// }
/******************************************************************************
6x6
******************************************************************************/
@Test
public void testSolvePuzzle61 () {
int[] clues = {3, 2, 2, 3, 2, 1,
1, 2, 3, 3, 2, 2,
5, 1, 2, 2, 4, 3,
3, 2, 1, 2, 2, 4};
int[][] outcome = {{ 2, 1, 4, 3, 5, 6},
{ 1, 6, 3, 2, 4, 5},
{ 4, 3, 6, 5, 1, 2},
{ 6, 5, 2, 1, 3, 4},
{ 5, 4, 1, 6, 2, 3},
{ 3, 2, 5, 4, 6, 1 }};
long start = System.currentTimeMillis();
assertEquals(outcome, SkyScrapers.solvePuzzle(clues));
long timeTaken = System.currentTimeMillis() - start;
System.out.println("6x6 time: " + timeTaken + "ms");
}
@Test
public void testSolvePuzzle62 () {
int[] clues = {0, 0, 0, 2, 2, 0,
0, 0, 0, 6, 3, 0,
0, 4, 0, 0, 0, 0,
4, 4, 0, 3, 0, 0};
int[][] outcome = {{ 5, 6, 1, 4, 3, 2 },
{ 4, 1, 3, 2, 6, 5 },
{ 2, 3, 6, 1, 5, 4 },
{ 6, 5, 4, 3, 2, 1 },
{ 1, 2, 5, 6, 4, 3 },
{ 3, 4, 2, 5, 1, 6 }};
long start = System.currentTimeMillis();
assertEquals(outcome, SkyScrapers.solvePuzzle(clues));
long timeTaken = System.currentTimeMillis() - start;
System.out.println("6x6--2 time: " + timeTaken + "ms");
}
@Test
public void testSolvePuzzle63 () {
int[] clues = {0, 3, 0, 5, 3, 4,
0, 0, 0, 0, 0, 1,
0, 3, 0, 3, 2, 3,
3, 2, 0, 3, 1, 0};
int[][] outcome = {{ 5, 2, 6, 1, 4, 3 },
{ 6, 4, 3, 2, 5, 1 },
{ 3, 1, 5, 4, 6, 2 },
{ 2, 6, 1, 5, 3, 4 },
{ 4, 3, 2, 6, 1, 5 },
{ 1, 5, 4, 3, 2, 6 }};
long start = System.currentTimeMillis();
assertEquals(outcome, SkyScrapers.solvePuzzle(clues));
long timeTaken = System.currentTimeMillis() - start;
System.out.println("6x6--3 time: " + timeTaken + "ms");
}
@Test
public void testSolvePuzzle64 () {
int[] clues = {0, 3, 0, 3, 2, 3,
3, 2, 0, 3, 1, 0,
0, 3, 0, 5, 3, 4,
0, 0, 0, 0, 0, 1};
int[][] outcome = {{6,2,3,4,5,1},
{5,1,6,2,3,4},
{4,3,5,1,6,2},
{2,6,4,5,1,3},
{1,5,2,3,4,6},
{3,4,1,6,2,5}};
long start = System.currentTimeMillis();
assertEquals(outcome, SkyScrapers.solvePuzzle(clues));
long timeTaken = System.currentTimeMillis() - start;
System.out.println("6x6--4 time: " + timeTaken + "ms");
}
}