69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
import { limitedArray } from './limitedArray';
|
|
|
|
test('should initialize an empty array', function () {
|
|
let lArray = new limitedArray();
|
|
|
|
expect(lArray.length()).toEqual(0);
|
|
});
|
|
|
|
test('Add an item to the array', function () {
|
|
let lArray = new limitedArray();
|
|
|
|
lArray.push('bob');
|
|
|
|
expect(lArray.length()).toEqual(1);
|
|
});
|
|
|
|
test('Add items to the array', function () {
|
|
let lArray = new limitedArray();
|
|
|
|
lArray.add([1, 2, 3, 4, 5]);
|
|
|
|
expect(lArray.length()).toEqual(5);
|
|
});
|
|
|
|
test('Add too many items', function () {
|
|
let lArray = new limitedArray(5);
|
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
|
|
expect(lArray.length()).toEqual(5);
|
|
});
|
|
|
|
test('Change limit', function () {
|
|
let lArray = new limitedArray();
|
|
|
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
lArray.limit(5);
|
|
|
|
expect(lArray.length()).toEqual(5);
|
|
});
|
|
|
|
test('Get items', function () {
|
|
let lArray = new limitedArray();
|
|
|
|
lArray.push('bob');
|
|
expect(lArray.get()).toEqual(['bob']);
|
|
});
|
|
|
|
test('Add too many items and get the results', function () {
|
|
let lArray = new limitedArray(5);
|
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
|
|
expect(lArray.get()).toEqual([6, 7, 8, 9, 10]);
|
|
});
|
|
|
|
test('Add one more', function () {
|
|
let lArray = new limitedArray(5);
|
|
lArray.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
lArray.push(11);
|
|
|
|
expect(lArray.get()).toEqual([7, 8, 9, 10, 11]);
|
|
});
|
|
|
|
|
|
/*test('Push many', function () {
|
|
let lArray = new limitedArray(5);
|
|
lArray.push(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
|
expect(lArray.get()).toEqual([6, 7, 8, 9, 10]);
|
|
});*/
|