How to use createTestTree method in wpt

Best JavaScript code snippet using wpt

NavTree.test.js

Source:NavTree.test.js Github

copy

Full Screen

...37 return tree38}39describe('NavTree', () => {40 it('creates tree structure correctly', () => {41 let tree = createTestTree()42 expect(tree.nodesId).to.be.eql(['a', 'b', 'c'])43 expect(tree.getNode('a').nodesId).to.be.eql(['e', 'f'])44 expect(tree.getNode('a', 'e').nodesId).to.be.eql(['g'])45 expect(tree.getNode('a', 'f').nodesId).to.be.eql(['h'])46 })47 it('requires `resolveFunc` function', () => {48 // todo49 })50 describe('addNode()', () => {51 it('can add nodes', () => {52 let parent = new NavTree()53 let child = parent.addNode()54 expect(child.parent).to.equal(parent)55 expect(Object.keys(parent.nodes).length).to.equal(1)56 expect(parent.nodes[child.id]).to.equal(child)57 let child2 = parent.addNode()58 expect(Object.keys(parent.nodes).length).to.equal(2)59 expect(parent.nodes[child2.id]).to.equal(child2)60 })61 it('ensures `id` is unique among the tree\'s direct nodes', () => {62 // todo63 })64 })65 describe('removeNode()', () => {66 it('can remove nodes', () => {67 let parent = new NavTree()68 let child = parent.addNode()69 parent.removeNode(child.id)70 expect(child.parent).to.be.null71 expect(parent.nodes).to.be.empty72 })73 })74 describe('navigation', () => {75 describe('focus()', () => {76 it('can focus a child node', () => {77 let parent = new NavTree()78 let child = parent.addNode()79 expect(parent.focusedNode).to.be.null80 parent.focus(child.id)81 expect(parent.focusedNode).to.equal(child.id)82 })83 it('can focus descendant node specified by path', () => {84 let tree = createTestTree()85 tree.focus('a', 'e', 'g')86 expect(tree.getFocusedPath()).to.eql(['a', 'e', 'g'])87 })88 describe('when called with empty args', () => {89 it('must keep the node focused and revoke focus from children', () => {90 let tree = createTestTree()91 tree.focus('a', 'e', 'g')92 tree.getNode('a').focus()93 expect(tree.getFocusedPath()).to.eql(['a'])94 })95 })96 it('can be called on a child node', () => {97 let tree = createTestTree()98 let child = tree.getNode('a', 'e', 'g')99 child.focus()100 expect(tree.getFocusedPath()).to.eql(['a', 'e', 'g'])101 })102 })103 describe('`onNav` event', () => {104 it('must call `onNav(false)` on a focused node when it lost focus', () => {105 let parent = new NavTree()106 let child = parent.addNode()107 parent.focus(child.id)108 let childOnNavEvent = chai.spy()109 child.onNavCallback = childOnNavEvent110 parent.focus()111 expect(childOnNavEvent).to.have.been.called.once.with(false)112 })113 it('must not call `onNav` on nodes not affected by navigation', () => {114 let parent = new NavTree()115 let child = parent.addNode()116 let child2 = parent.addNode()117 let childOnNavEvent = chai.spy()118 child.onNavCallback = childOnNavEvent119 parent.focus(child2.id)120 parent.focus()121 expect(childOnNavEvent).to.not.have.been.called()122 })123 it('must call `onNav(path)` on every node in new focused path', () => {124 let onNavSpy = chai.spy()125 let tree = createTestTree(onNavSpy)126 tree.focus('a', 'e', 'g')127 expect(onNavSpy).to.have.been.called.exactly(4)128 expect(onNavSpy).to.have.been.called.with('root', ['a', 'e', 'g'])129 expect(onNavSpy).to.have.been.called.with('a', ['e', 'g'])130 expect(onNavSpy).to.have.been.called.with('e', ['g'])131 expect(onNavSpy).to.have.been.called.with('g', [])132 })133 it('must call `onNav(false)` on every node from previously focused path', () => {134 let onNavSpy135 let onNav = (id, path) => {136 if (onNavSpy) onNavSpy(id, path)137 }138 let tree = createTestTree(onNav)139 tree.focus('a', 'e', 'g')140 onNavSpy = chai.spy()141 tree.focus()142 expect(onNavSpy).to.have.been.called.with('a', false)143 expect(onNavSpy).to.have.been.called.with('e', false)144 expect(onNavSpy).to.have.been.called.with('g', false)145 })146 })147 describe('resolve()', () => {148 it('navigates up & down the tree correctly', () => {149 let tree = createTestTree()150 // Tree:151 // └── a152 // ├── e153 // │ └── g154 // └── f155 // └── h156 tree.focus('a', 'e', 'g')157 let gNavResolve = chai.spy(() => false)158 let eNavResolve = chai.spy(() => false)159 let aNavResolve = chai.spy(() => 'f')160 let fNavResolve = chai.spy(() => 'h')161 let hNavResolve = chai.spy(() => null)162 tree.getNode('a', 'e').resolveFunc = eNavResolve163 tree.getNode('a', 'e', 'g').resolveFunc = gNavResolve164 tree.getNode('a').resolveFunc = aNavResolve165 tree.getNode('a', 'f').resolveFunc = fNavResolve166 tree.getNode('a', 'f', 'h').resolveFunc = hNavResolve167 tree.resolve('anEvent')168 expect(gNavResolve, 'G.resolveFunc').to.have.been.called.once.with('anEvent', tree.getNode('a', 'e', 'g'))169 expect(eNavResolve, 'E.resolveFunc').to.have.been.called.once.with('anEvent', tree.getNode('a', 'e'))170 expect(aNavResolve, 'A.resolveFunc').to.have.been.called.once.with('anEvent', tree.getNode('a'))171 expect(fNavResolve, 'F.resolveFunc').to.have.been.called.once.with('anEvent', tree.getNode('a', 'f'))172 expect(hNavResolve, 'H.resolveFunc').to.have.been.called.once.with('anEvent', tree.getNode('a', 'f', 'h'))173 expect(tree.getFocusedPath()).to.eql(['a', 'f', 'h'])174 })175 describe('if `resolveFunc` returns invalid value at phase 2 of resolving process', () => {176 it('must regard invalid value as NULL', () => {177 let tree = createTestTree()178 // Tree:179 // └── a180 // └── e181 // └── g182 tree.resolveFunc = () => 'a'183 tree.getNode('a').resolveFunc = () => 'e'184 // Possible valid values: 'g' or NULL.185 tree.getNode('a', 'e').resolveFunc = () => false186 tree.resolve('anEvent')187 expect(tree.getFocusedPath(), 'focused path').to.eql(['a', 'e'])188 })189 })190 // TODO191 /* describe('when parent node gets removed at phase 1', () => {192 it('should stop the process', () => {193 let tree = createTestTree()194 // Tree:195 // └── a196 // └── e197 // └── g198 tree.focus('a', 'e', 'g')199 tree.getNode('a', 'e', 'g').resolveFunc = () => {200 tree.getNode('a').removeNode('e')201 return false202 }203 let eResolveFunc = chai.spy()204 tree.getNode('a', 'e').resolveFunc = eResolveFunc205 let aResolveFunc = chai.spy()206 tree.getNode('a').resolveFunc = aResolveFunc207 tree.resolve('anEvent')...

Full Screen

Full Screen

red-black.spec.js

Source:red-black.spec.js Github

copy

Full Screen

1var assert = require('assert');2var RBTree = require('../src/red-black');3var rbt, log;4// --- helpers ---5function createTestTree() {6 [99, 50, 80, 65, 70, 40, 41, 42, 48, 47, 45, 43, 55, 57, 58, 59, 60, 61, 62]7 .forEach(function(i) { rbt.insert({ key: i, value: i }); });8}9function addLog(element) {10 log.push(element);11}12// --- end of helpers ---13describe('red-black module', function() {14 beforeEach(function() { rbt = new RBTree(); log = []; });15 it('should create empty tree', function() {16 assert(rbt.dump(true) === '');17 });18 //19 // insert20 //21 it('insert (ignore invalid input)', function() {22 rbt.insert('hello world!');23 assert(rbt.dump(true) === '');24 });25 it('insert (single object)', function() {26 // single {key: ..., value: ...} object27 rbt.insert({ key: 10, value: 10 });28 assert.strictEqual(rbt.dump(true), '[k:10,c:B,#:1,l:NULL,r:NULL,p:NULL,v:[10]]');29 });30 it('insert (array of objects)', function() {31 // [ { key: ..., value: ... }, ... ] -- array of the above objects32 rbt.insert([{ key: 20, value: 20 }, { key: 10, value: 10 }, { key: 30, value: 30 }]);33 assert.strictEqual(rbt.dump(true), '[k:20,c:B,#:1,l:10,r:30,p:NULL,v:[20]][k:10,c:R,#:1,l:NULL,r:NULL,p:20,v:[10]][k:30,c:R,#:1,l:NULL,r:NULL,p:20,v:[30]]');34 });35 it('insert (single numerical value)', function() {36 // key -- 1 arg, value not provided37 rbt.insert(40);38 assert.strictEqual(rbt.dump(true), '[k:40,c:B,#:1,l:NULL,r:NULL,p:NULL,v:[null]]');39 });40 it('insert (key / value numerical)', function() {41 // key, value -- 2 args42 rbt.insert(50, 50);43 assert.strictEqual(rbt.dump(true), '[k:50,c:B,#:1,l:NULL,r:NULL,p:NULL,v:[50]]');44 });45 it('insert (multiple values fro the same key)', function() {46 // insert value with existing key --> append to existing node47 rbt.insert(40, 40);48 rbt.insert(40, 60);49 assert.strictEqual(rbt.dump(true), '[k:40,c:B,#:2,l:NULL,r:NULL,p:NULL,v:[40,60]]');50 });51 it('insert (traversal code)', function() {52 rbt.insert([{ key: 10, value: 10 }, { key: 15, value: 15 }, { key: 5, value: 5 },53 { key: 1, value: 1 }, { key: 6, value: 6 }, { key: 20, value: 20 }]);54 assert.strictEqual(rbt.dump(true),55 '[k:10,c:B,#:1,l:5,r:15,p:NULL,v:[10]]' +56 '[k:5,c:B,#:1,l:1,r:6,p:10,v:[5]]' +57 '[k:1,c:R,#:1,l:NULL,r:NULL,p:5,v:[1]]' +58 '[k:6,c:R,#:1,l:NULL,r:NULL,p:5,v:[6]]' +59 '[k:15,c:B,#:1,l:NULL,r:20,p:10,v:[15]]' +60 '[k:20,c:R,#:1,l:NULL,r:NULL,p:15,v:[20]]'61 );62 });63 it('insert (balancing)', function() {64 createTestTree();65 assert.strictEqual(rbt.dump(true),66 '[k:55,c:B,#:1,l:45,r:65,p:NULL,v:[55]]' +67 '[k:45,c:R,#:1,l:41,r:48,p:55,v:[45]]' +68 '[k:41,c:B,#:1,l:40,r:42,p:45,v:[41]]' +69 '[k:40,c:B,#:1,l:NULL,r:NULL,p:41,v:[40]]' +70 '[k:42,c:B,#:1,l:NULL,r:43,p:41,v:[42]]' +71 '[k:43,c:R,#:1,l:NULL,r:NULL,p:42,v:[43]]' +72 '[k:48,c:B,#:1,l:47,r:50,p:45,v:[48]]' +73 '[k:47,c:B,#:1,l:NULL,r:NULL,p:48,v:[47]]' +74 '[k:50,c:B,#:1,l:NULL,r:NULL,p:48,v:[50]]' +75 '[k:65,c:R,#:1,l:58,r:80,p:55,v:[65]]' +76 '[k:58,c:B,#:1,l:57,r:60,p:65,v:[58]]' +77 '[k:57,c:B,#:1,l:NULL,r:NULL,p:58,v:[57]]' +78 '[k:60,c:R,#:1,l:59,r:61,p:58,v:[60]]' +79 '[k:59,c:B,#:1,l:NULL,r:NULL,p:60,v:[59]]' +80 '[k:61,c:B,#:1,l:NULL,r:62,p:60,v:[61]]' +81 '[k:62,c:R,#:1,l:NULL,r:NULL,p:61,v:[62]]' +82 '[k:80,c:B,#:1,l:70,r:99,p:65,v:[80]]' +83 '[k:70,c:B,#:1,l:NULL,r:NULL,p:80,v:[70]]' +84 '[k:99,c:B,#:1,l:NULL,r:NULL,p:80,v:[99]]'85 );86 });87 //88 // find89 //90 it('find (on empty tree)', function() {91 assert.strictEqual(rbt.find(45, 59).length, 0);92 });93 it('find (exact match: not found)', function() {94 createTestTree();95 assert.strictEqual(rbt.find(44).length, 0);96 });97 it('find (exact match: found)', function() {98 createTestTree();99 assert.strictEqual(rbt.find(45).length, 1);100 var expect = [45, 'hello'];101 rbt.insert(45, 'hello');102 var res = rbt.find(45).sort();103 assert.strictEqual(res.length, expect.length);104 res.forEach(function(val, idx) { assert.strictEqual(expect[idx], val); });105 });106 it('find (range search: not found)', function() {107 createTestTree();108 assert.strictEqual(rbt.find(12, 20).length, 0);109 });110 it('find (range search: found)', function() {111 createTestTree();112 rbt.insert(45, 'world');113 var expect = [45, 47, 48, 50, 55, 'world'];114 var res = rbt.find(45, 56).sort();115 assert.strictEqual(res.length, expect.length);116 res.forEach(function(val, idx) { assert.strictEqual(expect[idx], val); });117 });118 //119 // forEach120 //121 it('forEach (no callback)', function() {122 createTestTree();123 rbt.forEach();124 assert.strictEqual(log.length, 0);125 });126 it('forEach (on empty tree)', function() {127 rbt.forEach(addLog);128 assert.strictEqual(log.length, 0);129 });130 it('forEach (non-empty tree, valid callback)', function() {131 createTestTree();132 rbt.forEach(addLog);133 var expect = [99, 50, 80, 65, 70, 40, 41, 42, 48, 47, 45, 43, 55, 57, 58, 59, 60, 61, 62];134 expect = expect.sort();135 log = log.sort();136 assert.strictEqual(log.length, expect.length);137 log.forEach(function(val, idx) { assert.strictEqual(expect[idx], val); });138 });...

Full Screen

Full Screen

tree.test.ts

Source:tree.test.ts Github

copy

Full Screen

...9 tree.entry(3).addChild(5);10 return tree;11 };12 it('returns added items from getItems()', () => {13 const tree = createTestTree();14 const items = tree.getAll();15 expect(items).toHaveLength(5);16 expect(items).toEqual(expect.arrayContaining([1, 2, 3, 4, 5]));17 });18 it('only returns roots from getRoots()', () => {19 const tree = createTestTree();20 const roots = tree.getRoots();21 expect(roots).toHaveLength(3);22 expect(roots).toEqual(expect.arrayContaining([1, 2, 3]));23 });24 it('returns children of a specific element', () => {25 const tree = createTestTree();26 const children = tree.getChildren(1);27 expect(children).toHaveLength(1);28 expect(children).toEqual(expect.arrayContaining([4]));29 });30 it('reparents elements', () => {31 const tree = createTestTree();32 tree.moveToParent(3, 1);33 tree.moveToParent(5, 1);34 const childrenOf1 = tree.getChildren(1);35 const childrenOf3 = tree.getChildren(3);36 expect(tree.getParent(3)).toBe(1);37 expect(tree.getParent(5)).toBe(1);38 expect(childrenOf1.length).toBe(3);39 expect(childrenOf1).toEqual(expect.arrayContaining([3, 4, 5]));40 expect(childrenOf3).toEqual([]);41 expect(tree.getRoots()).toHaveLength(2);42 });43 it('removes elements', () => {44 const tree = createTestTree();45 tree.remove(2);46 tree.remove(4);47 const roots = tree.getRoots();48 expect(tree.getAll()).not.toEqual(expect.arrayContaining([2, 4]));49 expect(tree.getParent(2)).toBe(null);50 expect(tree.getParent(4)).toBe(null);51 expect(roots).toHaveLength(2);52 expect(roots).toEqual(expect.arrayContaining([1, 3]));53 expect(tree.getChildren(1)).toEqual([]);54 });55 it('can be cloned', () => {56 const tree = createTestTree();57 const clone = tree.clone();58 tree.add(100);59 clone.add(200);60 tree.entry(1).addChild(1000);61 clone.entry(1).addChild(2000);62 expect(tree.getRoots().sort()).toEqual([1, 2, 3, 100].sort());63 expect(clone.getRoots().sort()).toEqual([1, 2, 3, 200].sort());64 expect(tree.getChildren(1).sort()).toEqual([4, 1000].sort());65 expect(clone.getChildren(1).sort()).toEqual([4, 2000].sort());66 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptree = require('./wptree.js');2var tree = wptree.createTestTree();3console.log(tree);4var wptree = require('./wptree.js');5var tree = wptree.createTestTree();6console.log(tree);7var wptree = require('./wptree.js');8var tree = wptree.createTestTree();9console.log(tree);10var wptree = require('./wptree.js');11var tree = wptree.createTestTree();12console.log(tree);13var wptree = require('./wptree.js');14var tree = wptree.createTestTree();15console.log(tree);16var wptree = require('./wptree.js');17var tree = wptree.createTestTree();18console.log(tree);19var wptree = require('./wptree.js');20var tree = wptree.createTestTree();21console.log(tree);22var wptree = require('./wptree.js');23var tree = wptree.createTestTree();24console.log(tree);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptree = require('wptree');2var tree = wptree.createTestTree();3console.log(tree);4var wptree = require('wptree');5var tree = wptree.createTestTree();6var nodes = wptree.getTreeNodes(tree);7console.log(nodes);8var wptree = require('wptree');9var tree = wptree.createTestTree();10var node = wptree.getTreeNodesById(tree, 'B');11console.log(node);12var wptree = require('wptree');13var tree = wptree.createTestTree();14var node = wptree.getTreeNodesByName(tree, 'C');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptree = require("./wptree.js");2var testTree = new wptree();3testTree.createTestTree();4console.log("Test Tree Created");5testTree.printTree();6console.log("Tree printed");7testTree.printTreeByLevel();8console.log("Tree printed by level");9testTree.printTreeByLevel2();10console.log("Tree printed by level 2");11testTree.printTreeByLevel3();12console.log("Tree printed by level 3");13testTree.printTreeByLevel4();14console.log("Tree printed by level 4");15testTree.printTreeByLevel5();16console.log("Tree printed by level 5");17testTree.printTreeByLevel6();18console.log("Tree printed by level 6");19testTree.printTreeByLevel7();20console.log("Tree printed by level 7");21testTree.printTreeByLevel8();22console.log("Tree printed by level 8");23testTree.printTreeByLevel9();24console.log("Tree printed by level 9");25testTree.printTreeByLevel10();26console.log("Tree printed by level 10");27testTree.printTreeByLevel11();28console.log("Tree printed by level 11");29testTree.printTreeByLevel12();30console.log("Tree printed by level 12");31testTree.printTreeByLevel13();32console.log("Tree printed by level 13");33testTree.printTreeByLevel14();34console.log("Tree printed by level 14");35testTree.printTreeByLevel15();36console.log("Tree printed by level 15");37testTree.printTreeByLevel16();38console.log("Tree printed by level 16");39testTree.printTreeByLevel17();40console.log("Tree printed by level 17");41testTree.printTreeByLevel18();42console.log("Tree printed by level 18");43testTree.printTreeByLevel19();44console.log("Tree printed by level 19");45testTree.printTreeByLevel20();46console.log("Tree printed by level 20");47testTree.printTreeByLevel21();48console.log("Tree printed by level 21");49testTree.printTreeByLevel22();50console.log("Tree printed by level 22");51testTree.printTreeByLevel23();52console.log("Tree printed by level 23");53testTree.printTreeByLevel24();54console.log("Tree printed by level 24");55testTree.printTreeByLevel25();56console.log("Tree printed by level 25");

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptree = require('./wptree.js');2var path = process.argv[2];3wptree.createTestTree(path, function(err, tree){4 if(err) {5 console.log(err);6 } else {7 console.log(tree);8 }9});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful