/
fast-array-string.ts
52 lines (41 loc) · 1.42 KB
/
fast-array-string.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { FastStringArray, put } from '../../src/fast-string-array';
describe('FastStringArray', () => {
describe('put()', () => {
test('puts string in if not present', () => {
const array = FastStringArray();
put(array, 'test');
expect(array.array).toEqual(['test']);
put(array, 'test');
expect(array.array).toEqual(['test']);
put(array, 'foo');
expect(array.array).toEqual(['test', 'foo']);
put(array, 'bar');
expect(array.array).toEqual(['test', 'foo', 'bar']);
put(array, 'bar');
expect(array.array).toEqual(['test', 'foo', 'bar']);
put(array, 'foo');
expect(array.array).toEqual(['test', 'foo', 'bar']);
});
test('returns index of string in array', () => {
const array = FastStringArray();
expect(put(array, 'test')).toBe(0);
expect(put(array, 'foo')).toBe(1);
expect(put(array, 'bar')).toBe(2);
});
test('returns original index of string in array', () => {
const array = FastStringArray();
put(array, 'test');
put(array, 'foo');
put(array, 'bar');
expect(put(array, 'test')).toBe(0);
expect(put(array, 'foo')).toBe(1);
expect(put(array, 'bar')).toBe(2);
});
test('handles empty string', () => {
const array = FastStringArray();
expect(put(array, '')).toBe(0);
expect(put(array, '')).toBe(0);
expect(array.array).toEqual(['']);
});
});
});