-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrosswordSolverTest.js
140 lines (137 loc) · 3.29 KB
/
crosswordSolverTest.js
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
// Import the crosswordSolver function
import crosswordSolver from './crosswordSolver.js';
const crosswordSolverTest = () => {
const testCases = [
{
puzzle: `2001
0..0
1000
0..0`,
words: ['casa', 'alan', 'ciao', 'anta'],
description: "Test with a standard puzzle"
},
{
puzzle: `...1...........
..1000001000...
...0....0......
.1......0...1..
.0....100000000
100000..0...0..
.0.....1001000.
.0.1....0.0....
.10000000.0....
.0.0......0....
.0.0.....100...
...0......0....
..........0....`,
words: [
'sun', 'sunglasses', 'suncream', 'swimming', 'bikini', 'beach', 'icecream',
'tan', 'deckchair', 'sand', 'seaside', 'sandals'
],
description: "Test with a complex puzzle"
},
{
puzzle: `..1.1..1...
10000..1000
..0.0..0...
..1000000..
..0.0..0...
1000..10000
..0.1..0...
....0..0...
..100000...
....0..0...
....0......`,
words: [
'popcorn', 'fruit', 'flour', 'chicken', 'eggs', 'vegetables', 'pasta',
'pork', 'steak', 'cheese'
],
description: "Test with another standard puzzle"
},
{
puzzle: `...1...........
..1000001000...
...0....0......
.1......0...1..
.0....100000000
100000..0...0..
.0.....1001000.
.0.1....0.0....
.10000000.0....
.0.0......0....
.0.0.....100...
...0......0....
..........0....`,
words: [
'sun', 'sunglasses', 'suncream', 'swimming', 'bikini', 'beach', 'icecream',
'tan', 'deckchair', 'sand', 'seaside', 'sandals'
].reverse(),
description: "Test with reversed words"
},
{
puzzle: `2001
0..0
2000
0..0`,
words: ['casa', 'alan', 'ciao', 'anta'],
description: "Test mismatched number words and starting cells"
},
{
puzzle: `0001
0..0
3000
0..0`,
words: ['casa', 'alan', 'ciao', 'anta'],
description: "Test starting words higher than 2"
},
{
puzzle: `2001
0..0
1000
0..0`,
words: ['casa', 'casa', 'ciao', 'anta'],
description: "Test words repetition"
},
{
puzzle: '',
words: ['casa', 'alan', 'ciao', 'anta'],
description: "Test empty puzzle"
},
{
puzzle: 123,
words: ['casa', 'alan', 'ciao', 'anta'],
description: "Test wrong format checks"
},
{
puzzle: '',
words: 123,
description: "Test another wrong format"
},
{
puzzle: `2000
0...
0...
0...`,
words: ['abba', 'assa'],
description: "Test multiple solutions"
},
{
puzzle: `2001
0..0
1000
0..0`,
words: ['aaab', 'aaac', 'aaad', 'aaae'],
description: "Test no solution"
}
];
testCases.forEach(({ puzzle, words, description }) => {
try {
console.log(`\n${description}:`);
crosswordSolver(puzzle, words);
} catch (error) {
console.error(`${description} - Error occurred:`, error.message);
}
console.log('--------------------------------');
});
};
crosswordSolverTest();