forked from freewayz/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.common.idDispenser.test.ts
More file actions
50 lines (43 loc) · 1.7 KB
/
Copy pathextension.common.idDispenser.test.ts
File metadata and controls
50 lines (43 loc) · 1.7 KB
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
//
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.
//
// Place this right on top
import { initialize } from './initialize';
// The module 'assert' provides assertion methods from node
import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import { IdDispenser } from '../client/common/idDispenser';
// Defines a Mocha test suite to group tests of similar kind together
suite('IdDispenser', () => {
test('Sequential generation', done => {
const idDispenser = new IdDispenser();
Array.from(new Array(50).keys()).forEach(i => {
let id = idDispenser.Allocate();
assert.equal(i, id, `Allocated Id is not ${id}`);
});
done();
});
test('Test reuse and new generation', done => {
const idDispenser = new IdDispenser();
Array.from(new Array(50).keys()).forEach(i => {
idDispenser.Allocate();
});
// Free up the numbers 25 to 29
// The new numbers allocated must be 25,26,27,28,29,50,51,52,53,54,55, etc
const idsToFree = [25, 26, 27, 28, 29];
idsToFree.forEach(id => idDispenser.Free(id));
// Now generate again
Array.from(new Array(10).keys()).forEach(i => {
let id = idDispenser.Allocate();
if (i < 5) {
assert.notEqual(idsToFree.indexOf(id), -1, 'Freed id not regenerated');
}
else {
assert.equal(id, 50 + i - idsToFree.length, 'Generated id not following expected pattern');
}
});
done();
});
});