Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Horse-racing Duals/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function smallestDifference(input) {
}
}

return smallestDiff; // console.log() instead of return
console.log(smallestDiff);

// End of solution

Expand Down
45 changes: 28 additions & 17 deletions Horse-racing Duals/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
const testSubject = require('../src/index');
const fs = require('fs');
const path = require("path");
describe("Index.js function",() => {
const testSubject = require('../src/index');
const fs = require('fs');
const path = require("path");
Comment on lines +2 to +4

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually imports are at the top of the file.


test('Simple case. Smallest difference is 1', () => {
const input = fs.readFileSync(path.join(__dirname, "simpleCase.txt"), 'utf-8');
const output = testSubject(input);
expect(output).toBe(1);
});
beforeAll(() => {
console.log = jest.fn();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with Jest, however you need to make sure, that after this test suite is done, console.log continues to work as expected. You can make sure by reading documentation about jest.resetAllMocks, and what it does exactly

});

afterEach(() => {
jest.resetAllMocks();
});

test('Simple case. Smallest difference is 1', () => {
const input = fs.readFileSync(path.join(__dirname, "simpleCase.txt"), 'utf-8');
testSubject(input);
expect(console.log).toBeCalledWith(1);
});

test('Horses in any order. Smallest difference is 1', () => {
const input = fs.readFileSync(path.join(__dirname, "horsesInAnyOrder.txt"), 'utf-8');
testSubject(input);
expect(console.log).toBeCalledWith(1);
});

test('Horses in any order. Smallest difference is 1', () => {
const input = fs.readFileSync(path.join(__dirname, "horsesInAnyOrder.txt"), 'utf-8');
const output = testSubject(input);
expect(output).toBe(1);
test('Many horses. Smallest difference is 47', () => {
const input = fs.readFileSync(path.join(__dirname, "manyHorses.txt"), 'utf-8');
testSubject(input);
expect(console.log).toBeCalledWith(47);
});
});

test('Many horses. Smallest difference is 47', () => {
const input = fs.readFileSync(path.join(__dirname, "manyHorses.txt"), 'utf-8');
const output = testSubject(input);
expect(output).toBe(47);
});