test(curriculum): Add sudoku solver test cases (#45026)
This commit is contained in:
committed by
GitHub
parent
abdbc58a3f
commit
a04c7e1096
@ -129,9 +129,12 @@ If the puzzle submitted to `/api/solve` is greater or less than 81 characters, t
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const input =
|
const inputs = [
|
||||||
'9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..';
|
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6.',
|
||||||
|
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6...'
|
||||||
|
];
|
||||||
const output = 'Expected puzzle to be 81 characters long';
|
const output = 'Expected puzzle to be 81 characters long';
|
||||||
|
for (const input of inputs) {
|
||||||
const data = await fetch(getUserInput('url') + '/api/solve', {
|
const data = await fetch(getUserInput('url') + '/api/solve', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@ -140,6 +143,7 @@ async (getUserInput) => {
|
|||||||
const parsed = await data.json();
|
const parsed = await data.json();
|
||||||
assert.property(parsed, 'error');
|
assert.property(parsed, 'error');
|
||||||
assert.equal(parsed.error, output);
|
assert.equal(parsed.error, output);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -246,11 +250,14 @@ If the puzzle submitted to `/api/check` is greater or less than 81 characters, t
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const input =
|
const inputs = [
|
||||||
'9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..';
|
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6.',
|
||||||
|
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6...'
|
||||||
|
];
|
||||||
const coordinate = 'A1';
|
const coordinate = 'A1';
|
||||||
const value = '1';
|
const value = '1';
|
||||||
const output = 'Expected puzzle to be 81 characters long';
|
const output = 'Expected puzzle to be 81 characters long';
|
||||||
|
for (const input of inputs) {
|
||||||
const data = await fetch(getUserInput('url') + '/api/check', {
|
const data = await fetch(getUserInput('url') + '/api/check', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@ -259,6 +266,7 @@ async (getUserInput) => {
|
|||||||
const parsed = await data.json();
|
const parsed = await data.json();
|
||||||
assert.property(parsed, 'error');
|
assert.property(parsed, 'error');
|
||||||
assert.equal(parsed.error, output);
|
assert.equal(parsed.error, output);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -266,17 +274,31 @@ If the object submitted to `/api/check` is missing `puzzle`, `coordinate` or `va
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const input =
|
const inputs = [
|
||||||
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..';
|
{
|
||||||
|
puzzle: '..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..',
|
||||||
|
value: '1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
puzzle: '..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..',
|
||||||
|
coordinate: 'A1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
coordinate: 'A1',
|
||||||
|
value: '1'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
for (const input of inputs) {
|
||||||
const output = 'Required field(s) missing';
|
const output = 'Required field(s) missing';
|
||||||
const data = await fetch(getUserInput('url') + '/api/check', {
|
const data = await fetch(getUserInput('url') + '/api/check', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ puzzle: input })
|
body: JSON.stringify(input)
|
||||||
});
|
});
|
||||||
const parsed = await data.json();
|
const parsed = await data.json();
|
||||||
assert.property(parsed, 'error');
|
assert.property(parsed, 'error');
|
||||||
assert.equal(parsed.error, output);
|
assert.equal(parsed.error, output);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -287,8 +309,9 @@ async (getUserInput) => {
|
|||||||
const input =
|
const input =
|
||||||
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..';
|
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..';
|
||||||
const output = 'Invalid coordinate';
|
const output = 'Invalid coordinate';
|
||||||
const coordinate = 'XZ18';
|
const coordinates = ['A0', 'A10', 'J1', 'A', '1', 'XZ18'];
|
||||||
const value = '7';
|
const value = '7';
|
||||||
|
for (const coordinate of coordinates) {
|
||||||
const data = await fetch(getUserInput('url') + '/api/check', {
|
const data = await fetch(getUserInput('url') + '/api/check', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@ -297,6 +320,7 @@ async (getUserInput) => {
|
|||||||
const parsed = await data.json();
|
const parsed = await data.json();
|
||||||
assert.property(parsed, 'error');
|
assert.property(parsed, 'error');
|
||||||
assert.equal(parsed.error, output);
|
assert.equal(parsed.error, output);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -308,7 +332,8 @@ async (getUserInput) => {
|
|||||||
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..';
|
'..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..';
|
||||||
const output = 'Invalid value';
|
const output = 'Invalid value';
|
||||||
const coordinate = 'A1';
|
const coordinate = 'A1';
|
||||||
const value = 'X';
|
const values = ['0', '10', 'A'];
|
||||||
|
for (const value of values) {
|
||||||
const data = await fetch(getUserInput('url') + '/api/check', {
|
const data = await fetch(getUserInput('url') + '/api/check', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@ -317,6 +342,7 @@ async (getUserInput) => {
|
|||||||
const parsed = await data.json();
|
const parsed = await data.json();
|
||||||
assert.property(parsed, 'error');
|
assert.property(parsed, 'error');
|
||||||
assert.equal(parsed.error, output);
|
assert.equal(parsed.error, output);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user