Skip to content

Instantly share code, notes, and snippets.

@reneviering
Last active August 31, 2016 18:39
Show Gist options
  • Select an option

  • Save reneviering/490a8feac983fcd21b51d422a3c079d3 to your computer and use it in GitHub Desktop.

Select an option

Save reneviering/490a8feac983fcd21b51d422a3c079d3 to your computer and use it in GitHub Desktop.
// 64: Set - delete
// To do: make all tests pass, leave the assert lines unchanged!
describe('`set.delete()` deletes an element from a set', function(){
let set;
beforeEach(() => set = new Set());
describe('use `delete(<value>)` to delete an element', function() {
beforeEach(function() {
set.add('one').add('two').add('three');
});
it('`delete()` returns `true` when the element was found', function() {
const returns = set.delete('one');
assert.strictEqual(returns, true);
});
it('and the size decreases', function() {
set.delete('one');
assert.equal(set.size, 2);
});
});
describe('if nothing was deleted (no element with the given value was found)', function() {
it('returns `false`', function() {
const returns = set.delete('one');
assert.equal(returns, false);
});
});
describe('`undefined` is a valid value in a set', function() {
it('deleting it, when it is not in the set, returns `false` too', function() {
const whatToDelete = undefined;
assert.equal(set.delete(whatToDelete), false);
});
it('`delete()` removes it, when its in the set', function() {
set.add(undefined);
assert.equal(set.delete(), true);
});
});
describe('the value does NOT get casted', function() {
it('number 1 is different to string "1"', function() {
set.add(1);
assert.equal(set.delete('1'), false);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment