66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
const LimitedArray = require('../'),
|
|
expect = require('expect.js');
|
|
|
|
|
|
describe('limitedArray', () => {
|
|
let lArray;
|
|
|
|
beforeEach(() => {
|
|
lArray = new LimitedArray();
|
|
});
|
|
|
|
it('() should initialize an empty array', () => {
|
|
let lArray = new LimitedArray();
|
|
|
|
expect(lArray.length()).to.be(0);
|
|
});
|
|
|
|
it('Add an item to the array', () => {
|
|
let lArray = new LimitedArray();
|
|
lArray.push('bob');
|
|
|
|
expect(lArray.length()).to.be(1);
|
|
});
|
|
|
|
it('Add items to the array', () => {
|
|
let lArray = new LimitedArray();
|
|
lArray.add([1, 2, 3, 4, 5]);
|
|
expect(lArray.length()).to.be(5);
|
|
});
|
|
|
|
it('Add too many items', () => {
|
|
let lArray = new LimitedArray(5);
|
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
expect(lArray.length()).to.be(5);
|
|
});
|
|
|
|
it('Change limit', () => {
|
|
let lArray = new LimitedArray();
|
|
|
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
lArray.limit(5);
|
|
|
|
expect(lArray.length()).to.be(5);
|
|
});
|
|
|
|
it('Get items', () => {
|
|
let lArray = new LimitedArray();
|
|
lArray.push('bob');
|
|
expect(lArray.get()).to.eql(['bob']);
|
|
});
|
|
|
|
it('Add too many items and get the results', () => {
|
|
let lArray = new LimitedArray(5);
|
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
expect(lArray.get()).to.eql([6, 7, 8, 9, 10]);
|
|
});
|
|
|
|
it('Add one more', () => {
|
|
let lArray = new LimitedArray(5);
|
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
lArray.push(11);
|
|
expect(lArray.get()).to.eql([7, 8, 9, 10, 11]);
|
|
});
|
|
|
|
});
|