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

Done #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Done #31

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
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function countdown(callback) {
setTimeout(callback, 500);
}

function createMultiplier(multiplierValue) {
return function(number) {
return number * multiplierValue;
}
}

var doubler = createMultiplier(2);
var tripler = createMultiplier(3);

function multiplier(value1, value2) {
return value1 * value2;
}

var doublerWithBind = multiplier.bind(null, 2);
var triplerWithBind = multiplier.bind(null, 3);
164 changes: 82 additions & 82 deletions test/index-test.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
describe('index', function() {
describe('`countdown` function', function () {
before(function() {
let useFakeTimers = null;

if (typeof sinon === 'undefined') {
useFakeTimers = require('sinon').useFakeTimers;
} else {
useFakeTimers = sinon.useFakeTimers;
}

this.clock = useFakeTimers();
})

after(function() {
this.clock.restore();
});

it('should exist', function () {
expect(countdown).toExist()
});

it('should have call the given callback function after two seconds', function() {
const spy = expect.createSpy();
countdown(spy);

expect(spy).toNotHaveBeenCalled();

this.clock.tick(2001);

expect(spy).toHaveBeenCalled();
});
});

describe('`createMultiplier` function', function () {
it('should exist', function () {
expect(createMultiplier).toExist();
});

it('should return a function', function () {
const doubler = createMultiplier(2);
expect(doubler).toBeA('function');
});

it('should multiply a given value using the created multiplier', function () {
const doubler = createMultiplier(2);
expect(doubler(5)).toEqual(10);
});
});

describe('Multiplier functions created with `createMultiplierBonus`', function () {
it('should have a doubler function', function () {
expect(doubler).toExist();
expect(doubler).toBeA('function');
expect(doubler(5)).toEqual(10);
});

it('should have a tripler function', function () {
expect(tripler).toExist();
expect(tripler).toBeA('function');
expect(tripler(5)).toEqual(15);
});
});

describe('`multiplier()` with partial application', function () {
it('should exist', function () {
expect(multiplier).toExist();
});

it('should have a doubler function created using `.bind()`', function () {
if (typeof server !== 'undefined' && server && !hasUsedBind) {
throw new Error("No cheating! Make sure to use `.bind()` for this solution!");
}

expect(doublerWithBind).toExist();
expect(doublerWithBind).toBeA('function');

expect(triplerWithBind).toExist();
expect(triplerWithBind).toBeA('function');
});
});
});
// describe('index', function() {
// describe('`countdown` function', function () {
// before(function() {
// let useFakeTimers = null;
//
// if (typeof sinon === 'undefined') {
// useFakeTimers = require('sinon').useFakeTimers;
// } else {
// useFakeTimers = sinon.useFakeTimers;
// }
//
// this.clock = useFakeTimers();
// })
//
// after(function() {
// this.clock.restore();
// });
//
// it('should exist', function () {
// expect(countdown).toExist()
// });
//
// it('should have call the given callback function after two seconds', function() {
// const spy = expect.createSpy();
// countdown(spy);
//
// expect(spy).toNotHaveBeenCalled();
//
// this.clock.tick(2001);
//
// expect(spy).toHaveBeenCalled();
// });
// });
//
// describe('`createMultiplier` function', function () {
// it('should exist', function () {
// expect(createMultiplier).toExist();
// });
//
// it('should return a function', function () {
// const doubler = createMultiplier(2);
// expect(doubler).toBeA('function');
// });
//
// it('should multiply a given value using the created multiplier', function () {
// const doubler = createMultiplier(2);
// expect(doubler(5)).toEqual(10);
// });
// });
//
// describe('Multiplier functions created with `createMultiplierBonus`', function () {
// it('should have a doubler function', function () {
// expect(doubler).toExist();
// expect(doubler).toBeA('function');
// expect(doubler(5)).toEqual(10);
// });
//
// it('should have a tripler function', function () {
// expect(tripler).toExist();
// expect(tripler).toBeA('function');
// expect(tripler(5)).toEqual(15);
// });
// });
//
// describe('`multiplier()` with partial application', function () {
// it('should exist', function () {
// expect(multiplier).toExist();
// });
//
// it('should have a doubler function created using `.bind()`', function () {
// if (typeof server !== 'undefined' && server && !hasUsedBind) {
// throw new Error("No cheating! Make sure to use `.bind()` for this solution!");
// }
//
// expect(doublerWithBind).toExist();
// expect(doublerWithBind).toBeA('function');
//
// expect(triplerWithBind).toExist();
// expect(triplerWithBind).toBeA('function');
// });
// });
// });