UNPKG

ds-algo-study

Version:

Just experimenting with publishing a package

51 lines (40 loc) 1.02 kB
const circular = require('./index'); const L = require('./linkedlist'); const List = L.LinkedList; const Node = L.Node; test('circular function is defined', () => { expect(typeof circular).toEqual('function'); }); test('circular detects circular linked lists', () => { const l = new List(); const a = new Node('a'); const b = new Node('b'); const c = new Node('c'); l.head = a; a.next = b; b.next = c; c.next = b; expect(circular(l)).toEqual(true); }); test('circular detects circular linked lists linked at the head', () => { const l = new List(); const a = new Node('a'); const b = new Node('b'); const c = new Node('c'); l.head = a; a.next = b; b.next = c; c.next = a; expect(circular(l)).toEqual(true); }); test('circular detects non-circular linked lists', () => { const l = new List(); const a = new Node('a'); const b = new Node('b'); const c = new Node('c'); l.head = a; a.next = b; b.next = c; c.next = null; expect(circular(l)).toEqual(false); });