Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Create Sudoku functional test that detects if unsolvable puzzle is attempted #419

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions apps/sudoku-solver/tests/2_functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ suite('Functional Tests', () => {
chai.request(server)
.post('/api/solve')
.send({ puzzle: input })
.end((err, res) =>{
.end((err, res) => {
assert.isObject(res.body);
assert.property(res.body, 'solution');
assert.equal(res.body.solution, output);
Expand All @@ -36,7 +36,7 @@ suite('Functional Tests', () => {

chai.request(server)
.post('/api/solve')
.end((err, res) =>{
.end((err, res) => {
assert.isObject(res.body);
assert.property(res.body, 'error');
assert.deepEqual(res.body, error);
Expand All @@ -51,7 +51,7 @@ suite('Functional Tests', () => {
chai.request(server)
.post('/api/solve')
.send({ puzzle: input })
.end((err, res) =>{
.end((err, res) => {
assert.isObject(res.body);
assert.property(res.body, 'error');
assert.deepEqual(res.body, error);
Expand All @@ -68,7 +68,7 @@ suite('Functional Tests', () => {
chai.request(server)
.post('/api/solve')
.send({ puzzle: shortStr })
.end((err, res) =>{
.end((err, res) => {
assert.isObject(res.body);
assert.property(res.body, 'error');
assert.deepEqual(res.body, error);
Expand All @@ -87,11 +87,11 @@ suite('Functional Tests', () => {

test('Puzzle Cannot be Solved', done => {
const input = '779235418851496372432178956174569283395842761628713549283657194516924837947381625';
const error = {error: 'Puzzle cannot be solved'};
const error = { error: 'Puzzle cannot be solved' };

chai.request(server)
.post('/api/solve')
.send({puzzle: input})
.send({ puzzle: input })
.end((err, res) => {
assert.isObject(res.body);
assert.property(res.body, 'error');
Expand All @@ -100,9 +100,9 @@ suite('Functional Tests', () => {
});
});
});

suite('POST to /api/check', () => {

test('All fields filled in correctly, valid placement', done => {
const input = "..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6.."
const coordinate = "A1";
Expand All @@ -124,7 +124,7 @@ suite('Functional Tests', () => {
const input = "..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6.."
const coordinate = "A2";
const value = "1";
const status = {valid: false, conflict: [ 'row' ]};
const status = { valid: false, conflict: ['row'] };

chai.request(server)
.post('/api/check')
Expand All @@ -142,7 +142,7 @@ suite('Functional Tests', () => {
const input = "..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6.."
const coordinate = "A1";
const value = "1";
const status = {valid: false, conflict: [ 'row', 'column' ]};
const status = { valid: false, conflict: ['row', 'column'] };

chai.request(server)
.post('/api/check')
Expand All @@ -160,7 +160,7 @@ suite('Functional Tests', () => {
const input = "..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6.."
const coordinate = "A1";
const value = "5";
const status = {valid: false, conflict: [ 'row', 'column', 'region' ]};
const status = { valid: false, conflict: ['row', 'column', 'region'] };

chai.request(server)
.post('/api/check')
Expand Down Expand Up @@ -233,7 +233,7 @@ suite('Functional Tests', () => {
const input = "..9..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..";
const coordinate1 = "K1";
const coordinate2 = "A11";
const error = { error: 'Invalid coordinate'};
const error = { error: 'Invalid coordinate' };

chai.request(server)
.post('/api/check')
Expand Down Expand Up @@ -270,6 +270,18 @@ suite('Functional Tests', () => {
});
});

test("Cannot Solve Invalid Input", done => {
const input = ".99..5.1.85.4....2432......1...69.83.9.....6.62.71...9......1945....4.37.4.3..6..";
const error = { error: 'Puzzle cannot be solved' };
chai.request(server)
.post('/api/solve')
.send({ puzzle: input })
.end((err, res) => {
assert.isObject(res.body);
assert.property(res.body, 'error');
assert.deepEqual(res.body, error);
done();
});
});
});
});