-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from d3m3vilurr/last-changes
Sync up last changes
- Loading branch information
Showing
15 changed files
with
205 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: node_js | ||
|
||
os: | ||
- linux | ||
- osx | ||
|
||
addons: | ||
apt: | ||
packages: | ||
- valgrind | ||
|
||
script: | ||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then npm run valgrind; fi | ||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm test; fi | ||
|
||
node_js: | ||
- 8 | ||
- 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const assert = require('chai').assert; | ||
const LRUCache = require('../index.js'); | ||
|
||
describe('basics', () => { | ||
describe('a cache with default settings', () => { | ||
let cache = undefined; | ||
beforeEach(() => { | ||
cache = new LRUCache(); | ||
}); | ||
|
||
it('should be able to set and retrieve primitive values', () => { | ||
cache.set('foo', 42); | ||
const value = cache.get('foo'); | ||
assert.equal(value, 42); | ||
}); | ||
|
||
it('should be able to set and retrieve string values', () => { | ||
cache.set('foo', 'bar'); | ||
const value = cache.get('foo'); | ||
assert.equal(value, 'bar'); | ||
}); | ||
|
||
it('should be able to set and retrieve object values', () => { | ||
const obj = {example: 42} | ||
cache.set('foo', obj); | ||
const value = cache.get('foo'); | ||
//assert(value === obj, 'an unexpected item was returned'); | ||
}); | ||
|
||
describe('when remove() is called', () => { | ||
it('should remove the specified item', () => { | ||
cache.set('foo', 42); | ||
assert.equal(cache.get('foo'), 42); | ||
cache.remove('foo'); | ||
const value = cache.get('foo'); | ||
assert(value === undefined, `expected result to be undefined, was #{value}`); | ||
}); | ||
}); | ||
|
||
describe('when size() is called', () => { | ||
it('should return the correct size', () => { | ||
assert.equal(cache.size(), 0); | ||
cache.set('foo', 42); | ||
assert.equal(cache.size(), 1); | ||
}); | ||
}); | ||
|
||
describe('when clear() is called', () => { | ||
it('should remove all items in the cache', () => { | ||
cache.set('foo', 42); | ||
cache.set('bar', 21); | ||
cache.clear(); | ||
assert(cache.get('foo') === undefined); | ||
assert(cache.get('bar') === undefined) | ||
}); | ||
}); | ||
|
||
describe('when stats() is called', () => { | ||
it('should return fun statistics', () => { | ||
cache.set('foo', 42); | ||
const stats = cache.stats(); | ||
assert(stats.size == 1, `expected stats.size to be 1, was #{stats.size}`); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const assert = require('chai').assert; | ||
const LRUCache = require('..'); | ||
|
||
describe('exceptions', () => { | ||
describe('a cache with default settings', () => { | ||
let cache = undefined; | ||
beforeEach(() => { | ||
cache = new LRUCache(); | ||
}); | ||
|
||
describe('when get() is called with no arguments', () => { | ||
it('should throw a RangeError', () => { | ||
assert.throw(() => cache.get(), RangeError); | ||
}); | ||
}); | ||
|
||
describe('when get() is called with two arguments', () => { | ||
it('should throw a RangeError', () => { | ||
assert.throw(() => cache.get('foo', 'bar'), RangeError); | ||
}); | ||
}); | ||
|
||
describe('when set() is called with no arguments', () => { | ||
it('should throw a RangeError', () => { | ||
assert.throw(() => cache.set(), RangeError); | ||
}); | ||
}); | ||
|
||
describe('when set() is called with one argument', () => { | ||
it('should throw a RangeError', () => { | ||
assert.throw(() => cache.set('foo'), RangeError); | ||
}); | ||
}); | ||
|
||
describe('when set() is called with three arguments', () => { | ||
it('should throw a RangeError', () => { | ||
assert.throw(() => cache.set('foo', 'bar', 'baz'), RangeError); | ||
}); | ||
}); | ||
|
||
describe('when remove() is called with no arguments', () => { | ||
it('should throw a RangeError', () => { | ||
assert.throw(() => cache.remove(), RangeError); | ||
}); | ||
}); | ||
|
||
describe('when remove() is called with two arguments', () => { | ||
it('should throw a RangeError', () => { | ||
assert.throw(()=> cache.remove('foo', 'bar'), RangeError); | ||
}); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const assert = require('chai').assert; | ||
const LRUCache = require('..'); | ||
|
||
describe('maxAge', () => { | ||
describe('a cache with a maxAge of 100ms', () => { | ||
let cache = undefined; | ||
beforeEach(() => { | ||
cache = new LRUCache({maxAge: 100}); | ||
}); | ||
|
||
describe('when a value is requested less than 100ms after it is added', () => { | ||
it('should return the value', () => { | ||
cache.set('foo', 42); | ||
value = cache.get('foo'); | ||
assert.equal(value, 42); | ||
}); | ||
}); | ||
|
||
describe('when the value is requested more than 100ms after it is added', () => { | ||
it('should return undefined', (done) => { | ||
cache.set('foo', 42); | ||
setTimeout(() => { | ||
value = cache.get('foo'); | ||
assert(value === undefined, `value was #{value}, expected undefined`); | ||
done(); | ||
}, 200); | ||
}); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.