Skip to content

Commit

Permalink
test: refactor test-timers-linked-list.js
Browse files Browse the repository at this point in the history
* check that empty linked lists have identical properties
* `assert.equal()` -> `assert.strictEqual()`
* `var` -> `const`

PR-URL: #8193
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information
Trott committed Aug 23, 2016
1 parent 9cee8b1 commit 1aa47d8
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions test/parallel/test-timers-linked-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const internalL = require('internal/linkedlist');

assert.strictEqual(L, internalL);

var list = { name: 'list' };
var A = { name: 'A' };
var B = { name: 'B' };
var C = { name: 'C' };
var D = { name: 'D' };
const list = { name: 'list' };
const A = { name: 'A' };
const B = { name: 'B' };
const C = { name: 'C' };
const D = { name: 'D' };


L.init(list);
Expand All @@ -23,63 +23,61 @@ L.init(C);
L.init(D);

assert.ok(L.isEmpty(list));
assert.equal(null, L.peek(list));
assert.strictEqual(null, L.peek(list));

L.append(list, A);
// list -> A
assert.equal(A, L.peek(list));
assert.strictEqual(A, L.peek(list));

L.append(list, B);
// list -> A -> B
assert.equal(A, L.peek(list));
assert.strictEqual(A, L.peek(list));

L.append(list, C);
// list -> A -> B -> C
assert.equal(A, L.peek(list));
assert.strictEqual(A, L.peek(list));

L.append(list, D);
// list -> A -> B -> C -> D
assert.equal(A, L.peek(list));
assert.strictEqual(A, L.peek(list));

var x = L.shift(list);
assert.equal(A, x);
assert.strictEqual(A, L.shift(list));
// list -> B -> C -> D
assert.equal(B, L.peek(list));
assert.strictEqual(B, L.peek(list));

x = L.shift(list);
assert.equal(B, x);
assert.strictEqual(B, L.shift(list));
// list -> C -> D
assert.equal(C, L.peek(list));
assert.strictEqual(C, L.peek(list));

// B is already removed, so removing it again shouldn't hurt.
L.remove(B);
// list -> C -> D
assert.equal(C, L.peek(list));
assert.strictEqual(C, L.peek(list));

// Put B back on the list
L.append(list, B);
// list -> C -> D -> B
assert.equal(C, L.peek(list));
assert.strictEqual(C, L.peek(list));

L.remove(C);
// list -> D -> B
assert.equal(D, L.peek(list));
assert.strictEqual(D, L.peek(list));

L.remove(B);
// list -> D
assert.equal(D, L.peek(list));
assert.strictEqual(D, L.peek(list));

L.remove(D);
// list
assert.equal(null, L.peek(list));
assert.strictEqual(null, L.peek(list));


assert.ok(L.isEmpty(list));


L.append(list, D);
// list -> D
assert.equal(D, L.peek(list));
assert.strictEqual(D, L.peek(list));

L.append(list, C);
L.append(list, B);
Expand All @@ -90,21 +88,24 @@ L.append(list, A);
L.append(list, C);

// list -> D -> B -> A -> C
assert.equal(D, L.shift(list));
assert.strictEqual(D, L.shift(list));
// list -> B -> A -> C
assert.equal(B, L.peek(list));
assert.equal(B, L.shift(list));
assert.strictEqual(B, L.peek(list));
assert.strictEqual(B, L.shift(list));
// list -> A -> C
assert.equal(A, L.peek(list));
assert.equal(A, L.shift(list));
assert.strictEqual(A, L.peek(list));
assert.strictEqual(A, L.shift(list));
// list -> C
assert.equal(C, L.peek(list));
assert.equal(C, L.shift(list));
assert.strictEqual(C, L.peek(list));
assert.strictEqual(C, L.shift(list));
// list
assert.ok(L.isEmpty(list));

const list2 = L.create();
const list3 = L.create();
assert.ok(L.isEmpty(list2));
assert.ok(L.isEmpty(list3));
assert.ok(list2 != list3);

// Objects should have identical keys/properties, but be different objects.
assert.deepStrictEqual(list2, list3);
assert.notStrictEqual(list2, list3);

0 comments on commit 1aa47d8

Please sign in to comment.