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

Change exercise tests to be TDD orientated. #697

Closed
wants to merge 1 commit into from
Closed
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
64 changes: 32 additions & 32 deletions exercises/change/change.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import { Change } from './change';

describe('Change', () => {
test('test change for 1 cent', () => {
test('test no coins make 0 change', () => {
const change = new Change();
const result = change.calculate([1, 5, 10, 21, 25], 0);
expect(result).toEqual([]);
});

xtest('negative change is rejected', () => {
const change = new Change();
const message = 'Negative totals are not allowed.';
const test = () => { change.calculate([1, 2, 5], -5); };
expect(test).toThrowError(message);
});

xtest('error testing for change smaller than the smallest of coins', () => {
const change = new Change();
const message = 'The total 3 cannot be represented in the given currency.';
const test = () => { change.calculate([5, 10], 3); };
expect(test).toThrowError(message);
});

xtest('test change for 1 cent', () => {
const change = new Change();
const result = change.calculate([1, 5, 10, 25], 1);
expect(result).toEqual([1]);
Expand All @@ -19,20 +39,6 @@ describe('Change', () => {
expect(result).toEqual([5, 10]);
});

xtest('test change with Lilliputian Coins where a greedy algorithm fails', () => {
// https://en.wikipedia.org/wiki/Change-making_problem#Greedy_method
const change = new Change();
const result = change.calculate([1, 4, 15, 20, 50], 23);
expect(result).toEqual([4, 4, 15]);
});

xtest('test change with Lower Elbonia Coins where a greedy algorithm fails', () => {
// https://en.wikipedia.org/wiki/Change-making_problem#Greedy_method
const change = new Change();
const result = change.calculate([1, 5, 10, 21, 25], 63);
expect(result).toEqual([21, 21, 21]);
});

xtest('test large amount of change', () => {
const change = new Change();
const result = change.calculate([1, 2, 5, 10, 20, 50, 100], 999);
Expand All @@ -51,30 +57,24 @@ describe('Change', () => {
expect(result).toEqual([4, 4, 4, 5, 5, 5]);
});

xtest('test no coins make 0 change', () => {
const change = new Change();
const result = change.calculate([1, 5, 10, 21, 25], 0);
expect(result).toEqual([]);
});

xtest('error testing for change smaller than the smallest of coins', () => {
const change = new Change();
const message = 'The total 3 cannot be represented in the given currency.';
const test = () => { change.calculate([5, 10], 3); };
expect(test).toThrowError(message);
});

xtest('error testing if no combination can add up to target', () => {
const change = new Change();
const message = 'The total 94 cannot be represented in the given currency.';
const test = () => { change.calculate([5, 10], 94); };
expect(test).toThrowError(message);
});

xtest('negative change is rejected', () => {
xtest('test change with Lilliputian Coins where a greedy algorithm fails', () => {
// https://en.wikipedia.org/wiki/Change-making_problem#Greedy_method
const change = new Change();
const message = 'Negative totals are not allowed.';
const test = () => { change.calculate([1, 2, 5], -5); };
expect(test).toThrowError(message);
const result = change.calculate([1, 4, 15, 20, 50], 23);
expect(result).toEqual([4, 4, 15]);
});

xtest('test change with Lower Elbonia Coins where a greedy algorithm fails', () => {
// https://en.wikipedia.org/wiki/Change-making_problem#Greedy_method
const change = new Change();
const result = change.calculate([1, 5, 10, 21, 25], 63);
expect(result).toEqual([21, 21, 21]);
});
});