Best JavaScript code snippet using wpt
List.test.ts
Source:List.test.ts
...25 it("Returns a reference, not a copy", () =>26 {27 const array = [1, 2, 3];28 const list = new List(array);29 Test.isArrayEqual(list.asArray(), array);30 array.push(245);31 Test.isArrayEqual(list.asArray(), array);32 });33 }34 function asReadOnly(): void35 {36 it("Same object but different interface", () =>37 {38 const list = new List(["hi", "yess"]);39 Test.isEqual(list, list.asReadOnly());40 });41 }42 function copy(): void43 {44 it("Type is a List", () =>45 {46 const list = new List([1, 2, 3]);47 Test.isTrue(list instanceof List);48 });49 it("Returns a copy, not a reference", () =>50 {51 const array = [1, 2, 3];52 const list = new List(array);53 const copy = list.copy();54 Test.isArrayEqual(list.asArray(), copy.asArray());55 list.asArray().push(245);56 Test.isArrayNotEqual(list.asArray(), copy.asArray());57 Test.isArrayEqual(list.asArray(), [1, 2, 3, 245]);58 Test.isArrayEqual(copy.asArray(), [1, 2, 3]);59 });60 }61 function clear(): void62 {63 it("Does nothing on empty list", () =>64 {65 const list = new List<number>();66 Test.isArrayEqual(list.asArray(), []);67 list.clear();68 Test.isArrayEqual(list.asArray(), []);69 list.clear();70 Test.isArrayEqual(list.asArray(), []);71 });72 it("List is cleared", () =>73 {74 const list = new List([1, 2, 3]);75 Test.isArrayEqual(list.asArray(), [1, 2, 3]);76 list.clear();77 Test.isArrayEqual(list.asArray(), []);78 });79 }80 function get(): void81 {82 it("Value is correct", () =>83 {84 const list = new List([1, 2, 3]);85 Test.isEqual(list.get(0), 1);86 Test.isEqual(list.get(1), 2);87 Test.isEqual(list.get(2), 3);88 });89 it("Undefined if invalid index", () =>90 {91 const list = new List([1, 2, 3]);92 Test.isEqual(list.get(-999), undefined);93 Test.isEqual(list.get(-1), undefined);94 Test.isEqual(list.get(3), undefined);95 Test.isEqual(list.get(999), undefined);96 });97 }98 function push(): void99 {100 it("Adds element in back of the list", () =>101 {102 const list = new List<number>();103 list.push(2); Test.isArrayEqual(list.asArray(), [2]);104 list.push(22); Test.isArrayEqual(list.asArray(), [2, 22]);105 list.push(1); Test.isArrayEqual(list.asArray(), [2, 22, 1]);106 list.push(4); Test.isArrayEqual(list.asArray(), [2, 22, 1, 4]);107 });108 }109 function pushFront(): void110 {111 it("Adds element in front of the list", () =>112 {113 const list = new List<number>();114 list.pushFront(2); Test.isArrayEqual(list.asArray(), [2]);115 list.pushFront(22); Test.isArrayEqual(list.asArray(), [22, 2]);116 list.pushFront(1); Test.isArrayEqual(list.asArray(), [1, 22, 2]);117 list.pushFront(4); Test.isArrayEqual(list.asArray(), [4, 1, 22, 2]);118 });119 }120 function pushRange(): void121 {122 it("Empty range doesn't modify the original (array)", () =>123 {124 const list = new List([1, 2, 3]);125 Test.isEqual(list.pushRange([]), 3);126 Test.isArrayEqual(list.asArray(), [1, 2, 3]);127 });128 it("Empty range doesn't modify the original (IQueryable)", () =>129 {130 const list = new List([1, 2, 3]);131 Test.isEqual(list.pushRange(new List<number>()), 3);132 Test.isArrayEqual(list.asArray(), [1, 2, 3]);133 });134 it("Value is correct (array)", () =>135 {136 const list = new List([1, 2, 3]);137 Test.isEqual(list.pushRange([22]), 4);138 Test.isArrayEqual(list.asArray(), [1, 2, 3, 22]);139 Test.isEqual(list.pushRange([24, 67]), 6);140 Test.isArrayEqual(list.asArray(), [1, 2, 3, 22, 24, 67]);141 });142 it("Value is correct (IQueryable)", () =>143 {144 const list = new List([1, 2, 3]);145 Test.isEqual(list.pushRange(new List([22])), 4);146 Test.isArrayEqual(list.asArray(), [1, 2, 3, 22]);147 Test.isEqual(list.pushRange(new List([24, 67])), 6);148 Test.isArrayEqual(list.asArray(), [1, 2, 3, 22, 24, 67]);149 });150 }151 function pop(): void152 {153 it("Removes and returns the element in back of the list", () =>154 {155 const list = new List([1, 2, 3]);156 let element = list.pop();157 Test.isEqual(element, 3);158 Test.isArrayEqual(list.asArray(), [1, 2]);159 element = list.pop();160 Test.isEqual(element, 2);161 Test.isArrayEqual(list.asArray(), [1]);162 element = list.pop();163 Test.isEqual(element, 1);164 Test.isArrayEqual(list.asArray(), []);165 });166 it("Returns undefined in empty list", () =>167 {168 const list = new List<number>();169 const element = list.pop();170 Test.isEqual(element, undefined);171 Test.isArrayEqual(list.asArray(), []);172 });173 }174 function popFront(): void175 {176 it("Removes and returns the element in back of the list", () =>177 {178 const list = new List([1, 2, 3]);179 let element = list.popFront();180 Test.isEqual(element, 1);181 Test.isArrayEqual(list.asArray(), [2, 3]);182 element = list.popFront();183 Test.isEqual(element, 2);184 Test.isArrayEqual(list.asArray(), [3]);185 element = list.popFront();186 Test.isEqual(element, 3);187 Test.isArrayEqual(list.asArray(), []);188 });189 it("Returns undefined in empty list", () =>190 {191 const list = new List<number>();192 const element = list.popFront();193 Test.isEqual(element, undefined);194 Test.isArrayEqual(list.asArray(), []);195 });196 }197 function remove(): void198 {199 it("Does nothing on empty list", () =>200 {201 const list = new List<number>();202 list.remove(6);203 list.remove(-6);204 Test.isArrayEqual(list.asArray(), []);205 });206 it("Remove single element", () =>207 {208 const list = new List([2, 3, 4, 5]);209 list.remove(3);210 Test.isArrayEqual(list.asArray(), [2, 4, 5]);211 list.remove(6);212 Test.isArrayEqual(list.asArray(), [2, 4, 5]);213 list.remove(4);214 Test.isArrayEqual(list.asArray(), [2, 5]);215 list.remove(2);216 Test.isArrayEqual(list.asArray(), [5]);217 list.remove(5);218 Test.isArrayEqual(list.asArray(), []);219 });220 it("Remove element multiple times", () =>221 {222 const list = new List([1, 1, 2, 3, 2, 5, 6, 6]);223 list.remove(1);224 Test.isArrayEqual(list.asArray(), [2, 3, 2, 5, 6, 6]);225 list.remove(2);226 Test.isArrayEqual(list.asArray(), [3, 5, 6, 6]);227 list.remove(6);228 Test.isArrayEqual(list.asArray(), [3, 5]);229 });230 }231 function removeAt(): void232 {233 it("Exception if negative index", () =>234 {235 const list = new List([6, 6, 6]);236 Test.throwsException(() => list.removeAt(-1));237 Test.throwsException(() => list.removeAt(-50));238 Test.throwsException(() => list.removeAt(-9999));239 });240 it("Exception if invalid index", () =>241 {242 const list = new List([6, 6, 6]);243 Test.throwsException(() => list.removeAt(3));244 Test.throwsException(() => list.removeAt(50));245 Test.throwsException(() => list.removeAt(9999));246 });247 it("Deletes element by index", () =>248 {249 const list = new List([2, 3, 4, 5]);250 list.removeAt(3);251 Test.isArrayEqual(list.asArray(), [2, 3, 4]);252 list.removeAt(0);253 Test.isArrayEqual(list.asArray(), [3, 4]);254 list.removeAt(1);255 Test.isArrayEqual(list.asArray(), [3]);256 list.removeAt(0);257 Test.isArrayEqual(list.asArray(), []);258 });259 }260 function set(): void261 {262 it("Exception if negative index", () =>263 {264 const list = new List([6, 6, 6]);265 Test.throwsException(() => list.set(-1, 666));266 Test.throwsException(() => list.set(-50, 666));267 Test.throwsException(() => list.set(-9999, 666));268 });269 it("Initializes list if empty", () =>270 {271 const list = new List<number>();272 list.set(0, 33);273 Test.isArrayEqual(list.asArray(), [33]);274 });275 it("Sets the correct index", () =>276 {277 const list = new List([2, 4, 6, 8, 7]);278 list.set(0, 33);279 Test.isArrayEqual(list.asArray(), [33, 4, 6, 8, 7]);280 list.set(3, 22);281 Test.isArrayEqual(list.asArray(), [33, 4, 6, 22, 7]);282 });283 it("Resizes list if necessary", () =>284 {285 const list = new List([2, 4, 6, 8, 7]);286 list.set(7, 33);287 Test.isArrayEqual(list.asArray(), [2, 4, 6, 8, 7, undefined, undefined, 33]);288 });289 }290 function indexOf(): void291 {292 it("-1 in empty list", () =>293 {294 const list = new List<number>();295 Test.isEqual(list.indexOf(666), -1);296 Test.isEqual(list.indexOf(0), -1);297 Test.isEqual(list.indexOf(-666), -1);298 });299 it("-1 if element not found", () =>300 {301 const list = new List([1, 2, 3]);302 Test.isEqual(list.indexOf(-999), -1);303 Test.isEqual(list.indexOf(-1), -1);304 Test.isEqual(list.indexOf(4), -1);305 Test.isEqual(list.indexOf(999), -1);306 });307 it("Value is correct", () =>308 {309 const list = new List([1, 2, 3]);310 Test.isEqual(list.indexOf(2), 1);311 Test.isEqual(list.indexOf(1), 0);312 Test.isEqual(list.indexOf(3), 2);313 });314 }315 function insert(): void316 {317 it("Throws exception if index < 0", () =>318 {319 const list = new List([1, 2, 3]);320 Test.throwsException(() => list.insert(-3, 55));321 });322 it("Throws exception if index > length", () =>323 {324 const list = new List([1, 2, 3]);325 Test.throwsException(() => list.insert(4, 55));326 });327 it("Initializes empty list", () =>328 {329 const list = new List<number>();330 list.insert(0, 4);331 Test.isArrayEqual(list.asArray(), [4]);332 });333 it("Moves other elements to fit the new one", () =>334 {335 const list = new List([1, 2, 3]);336 list.insert(1, 55);337 Test.isArrayEqual(list.asArray(), [1, 55, 2, 3]);338 });339 }...
isArrayEqual.spec.js
Source:isArrayEqual.spec.js
2describe('isArrayEqual æ¹æ³æµè¯', () => {3 test('åºæ¬ç±»åæ°ç»å
容ç¸ååºè¯¥ç¸ç', () => {4 const arr1 = [1, 2, 3]5 const arr2 = [1, 2, 3]6 expect(isArrayEqual(arr1, arr2)).toBe(true)7 const arr3 = ['a', 'b', 'c']8 const arr4 = ['a', 'b', 'c']9 expect(isArrayEqual(arr3, arr4)).toBe(true)10 const arr5 = [1, 'a', undefined, null]11 const arr6 = [1, 'a', undefined, null]12 expect(isArrayEqual(arr5, arr6)).toBe(true)13 })14 test('æ°ç»å
容éä¸ç¸ååºè¯¥ä¸ç¸ç', () => {15 const arr1 = [1, 'a', undefined, null, {name:1}]16 const arr2 = [1, 'a', undefined, null,{name:2}]17 expect(isArrayEqual(arr1, arr2)).toBe(false)18 })19 test('å«æéå½æ°å¼ç¨ç±»åå
容åºè¯¥ç¸ç', () => {20 const arr1 = [1, { a: 1 }]21 const arr2 = [1, { a: 1 }]22 expect(isArrayEqual(arr1, arr2)).toBe(true)23 })24 test('å«æéå½æ°å¼ç¨ç±»åå
容ä¸åºè¯¥ç¸ç', () => {25 const arr1 = [1, { a: 1 }]26 const arr2 = [1, { a: 2 }]27 expect(isArrayEqual(arr1, arr2)).toBe(false)28 })29 test('åæåå¼ç¨å
容åºè¯¥ç¸ç', () => {30 const raw = [1, { a: 1 }, 'b']31 const arr1 = raw32 const arr2 = raw33 expect(isArrayEqual(arr1, arr2)).toBe(true)34 const arr3 = [1, raw]35 const arr4 = [1, raw]36 expect(isArrayEqual(arr3, arr4)).toBe(true)37 })38 test('空æ°ç»åºè¯¥ç¸ç', () => {39 const arr1 = []40 const arr2 = []41 expect(isArrayEqual(arr1, arr2)).toBe(true)42 })43 test('æ°ç»éåªænullåºè¯¥ç¸ç', () => {44 const arr1 = [null]45 const arr2 = [null]46 expect(isArrayEqual(arr1, arr2)).toBe(true)47 })48 test('æ°ç»éåªæundefinedåºè¯¥ç¸ç', () => {49 const arr1 = [undefined]50 const arr2 = [undefined]51 expect(isArrayEqual(arr1, arr2)).toBe(true)52 })53 test('æ°ç»éåªæ空æ°ç»åºè¯¥ç¸ç', () => {54 const arr1 = [[]]55 const arr2 = [[]]56 expect(isArrayEqual(arr1, arr2)).toBe(true)57 })58 test('æ°ç»éåªæ空æ°ç»ånullä¸åºè¯¥ç¸ç', () => {59 const arr1 = [[]]60 const arr2 = [[null]]61 expect(isArrayEqual(arr1, arr2)).toBe(false)62 })63 test('æ°ç»éæ空æ°ç»ånullä¸åºè¯¥ç¸ç', () => {64 const arr1 = ['']65 const arr2 = [null]66 expect(isArrayEqual(arr1, arr2)).toBe(false)67 })68 test('æ°ç»å
ç®åæ°æ®æä¹±åºè¯¥ç¸ç', () => {69 const arr1 = [1,2,3]70 const arr2 = [3,2,1]71 expect(isArrayEqual(arr1, arr2)).toBe(true)72 })73 test('æ°ç»å
å¤ææ°æ®æä¹±åºè¯¥ç¸ç', () => {74 const arr1 = [/'aa'/,1,2,3,{name:'å'},['å'],null,undefined,'',new Date(1660115867202)]75 const arr2 = [["å"],{'name':"å"},'',undefined,null,3,2,1,new Date(1660115867202),/'aa'/]76 expect(isArrayEqual(arr1, arr2)).toBe(true)77 })78 test('æ°ç»å
å¤ææ°æ®æä¹±ä¸ç¸ä¼¼ä½ä¸åä¸åºè¯¥ç¸ç', () => {79 const arr1 = [/'aa'/,1,2,3,{name:'å'},['å'],null,undefined,'',new Date(1660115867202)]80 const arr2 = [["å"],{'name':"å"},'',undefined,null,3,2,1,new Date(1660014867200),/'aa'/]81 expect(isArrayEqual(arr1, arr2)).toBe(false)82 })83 test('æ°ç»å
å¤ææ°æ®é¿åº¦ä¸åä¸åºè¯¥ç¸ç', () => {84 const arr1 = [1,2,3,{name:'å'},['å'],null]85 const arr2 = [1,2,3,{name:'å'},['å']]86 expect(isArrayEqual(arr1, arr2)).toBe(false)87 })88 test('å½æ°å¯¹è±¡ä¸åä¸åºè¯¥ç¸ç', () => {89 const arr1 = [function(a){return a+1 }]90 const arr2 = [function(a){return a+2 }]91 expect(isArrayEqual(arr1, arr2)).toBe(false)92 })93 test('å½æ°å¯¹è±¡ç¸ååºè¯¥ç¸ç', () => {94 const arr1 = [function(a){return a+1 }]95 const arr2 = [function(a){return a+1 }]96 expect(isArrayEqual(arr1, arr2)).toBe(true)97 })98 test('ä¼ åä¸æ¯æ°ç»ï¼åºè¯¥æ¥é', () => {99 const arr1 = '';100 const arr2 = null;101 expect(() => isArrayEqual(arr1, arr2)).toThrow('åæ°ä¸ä¸ºæ°ç»ï¼æ æ³æ¯è¾');102 })...
task2.js
Source:task2.js
...13 return true;14 } 15 return false;16}17console.log(isArrayEqual([], null)); // false or exception18console.log(isArrayEqual([], [])); // true19console.log(isArrayEqual([], ['test'])); // false20console.log(isArrayEqual([1, 2, 3], [1, 2, 3])); // true21console.log(isArrayEqual([1, null, 3], [1, undefined, 3])); // false...
Using AI Code Generation
1var wpt = require('wpt');2var array1 = [1, 2, 3, 4, 5];3var array2 = [1, 2, 3, 4, 5];4var array3 = [1, 2, 3, 4, 5, 6];5var array4 = [1, 2, 3, 4];6var array5 = [1, 2, 3, 4, 5, 6];7var array6 = [1, 2, 3, 4, 6];8var array7 = [1, 2, 3, 4, 5, 6];9var array8 = [1, 2, 3, 4, 5];10var wpt = require('wpt');11console.log(w
Using AI Code Generation
1var wpt = require('wpt');2var arr1 = [1,2,3,4,5];3var arr2 = [1,2,3,4,5];4var arr3 = [1,2,3,4,5,6];5var arr4 = [1,2,3,4,5,6,7];6console.log("arr1 and arr2 are equal: " + wpt.isArrayEqual(arr1, arr2));7console.log("arr1 and arr3 are equal: " + wpt.isArrayEqual(arr1, arr3));8console.log("arr1 and arr4 are equal: " + wpt.isArrayEqual(arr1, arr4));
Using AI Code Generation
1var wpt = require('wpt');2var array1 = [1,2,3];3var array2 = [1,2,3];4var result = wpt.isArrayEqual(array1,array2);5console.log(result);6var wpt = require('wpt');7var array1 = [1,2,3];8var array2 = [1,2,4];9var result = wpt.isArrayEqual(array1,array2);10console.log(result);11var wpt = require('wpt');12var array1 = [1,2,3];13var array2 = [1,2,3,4];14var result = wpt.isArrayEqual(array1,array2);15console.log(result);16var wpt = require('wpt');17var array1 = [1,2,3];18var array2 = [1,2,3,4];19var result = wpt.isArrayEqual(array1,array2,false);20console.log(result);21var wpt = require('wpt');22var array1 = [1,2,3];23var array2 = [1,2,3,4];24var result = wpt.isArrayEqual(array1,array2,true);25console.log(result);26var wpt = require('wpt');27var array1 = [1,2,3];28var array2 = [1,2,3,4];29var result = wpt.isArrayEqual(array1,array2);30console.log(result);31var wpt = require('wpt');32var array1 = [1,2,3];33var array2 = [1,2,3,4];34var result = wpt.isArrayEqual(array1,array2,true);35console.log(result);
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var array1 = [1,2,3,4];3var array2 = [1,2,3,4];4var isEqual = wptoolkit.isArrayEqual(array1, array2);5console.log(isEqual);6var wptoolkit = require('wptoolkit');7var array1 = [1,2,3,4];8var array2 = [1,2,3,4,5];9var isEqual = wptoolkit.isArrayEqual(array1, array2);10console.log(isEqual);11var wptoolkit = require('wptoolkit');12var array1 = [1,2,3,4];13var array2 = [1,2,3,5];14var isEqual = wptoolkit.isArrayEqual(array1, array2);15console.log(isEqual);16var wptoolkit = require('wptoolkit');17var array1 = [1,2,3,4];18var array2 = [1,2,3,4];19var isEqual = wptoolkit.isArrayEqual(array1, array2, true);20console.log(isEqual);21var wptoolkit = require('wptoolkit');22var array1 = [1,2,3,4];23var array2 = [1,2,3,4,5];24var isEqual = wptoolkit.isArrayEqual(array1, array2, true);25console.log(isEqual);26var wptoolkit = require('wptoolkit');27var array1 = [1,2,3,4];28var array2 = [1,2,3,5];29var isEqual = wptoolkit.isArrayEqual(array1, array2, true);30console.log(isEqual);
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var arr1 = [1,2,3,4,5];3var arr2 = [1,2,3,4,5];4var arr3 = [1,2,3,4,5,6];5var arr4 = [1,2,3,4,5,6];6var arr5 = [1,2,3,4,5,6,7];7var arr6 = [1,2,3,4,5,6,7];8var arr7 = [1,2,3,4,5,6,7,8];9var arr8 = [1,2,3,4,5,6,7,8];10var arr9 = [1,2,3,4,5,6,7,8,9];11var arr10 = [1,2,3,4,5,6,7,8,9];12var arr11 = [1,2,3,4,5,6,7,8,9,10];13var arr12 = [1,2,3,4,5,6,7,8,9,10];14var arr13 = [1,2,3,4,5,6,7,8,9,10,11];15var arr14 = [1,2,3,4,5,6,7,8,9,10,11];16var arr15 = [1,2,3,4,5,6,7,8,9,10,11,12];17var arr16 = [1,2,3,4,5,6,7,8,9,10,11,12];18var arr17 = [1,2,3,4,5,6,7,8,9,10,11,12,13];19var arr18 = [1,2,3,4,5,6,7,8,9,10,11,12,13];20var arr19 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14];21var arr20 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14];
Using AI Code Generation
1var wptools = require('wikimedia-page-library');2var wptools = require('wikimedia-page-library');3var wptools = require('wikimedia-page-library');4var anchor = '#cite_note-1';5var wptools = require('wikimedia-page-library');6var title = 'Citation needed';7var wptools = require('wikimedia-page-library');8var title = 'Citation needed';9var wptools = require('wikimedia-page-library');10var title = 'Citation needed';11var wptools = require('wikimedia-page-library');12var title = 'Citation needed';
Using AI Code Generation
1var wptools = require('wptools');2var a = [1,2,3];3var b = [1,2,3];4var c = [3,2,1];5var result = wptools.isArrayEqual(a,b);6var result = wptools.isArrayEqual(a,c);7var result = wptools.isArrayEqual(a,a);8var result = wptools.isArrayEqual(a);9var result = wptools.isArrayEqual(a,1);10var result = wptools.isArrayEqual(a,"a");11var result = wptools.isArrayEqual(a,{});12var result = wptools.isArrayEqual(a,[]);13var result = wptools.isArrayEqual(a,null);14var result = wptools.isArrayEqual(a,undefined);15var result = wptools.isArrayEqual(a,NaN);16var result = wptools.isArrayEqual(a,Infinity);17var result = wptools.isArrayEqual(a,0);18var result = wptools.isArrayEqual(a,0.0);19var result = wptools.isArrayEqual(a,true);20var result = wptools.isArrayEqual(a,false);21var result = wptools.isArrayEqual(a,new Date());22var result = wptools.isArrayEqual(a,new RegExp());23var result = wptools.isArrayEqual(a,new Error());24var result = wptools.isArrayEqual(a,Symbol("a"));25var result = wptools.isArrayEqual(a,function(){});26var result = wptools.isArrayEqual(a,()=>{});27var result = wptools.isArrayEqual(a,async ()=>{});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!