Best JavaScript code snippet using wpt
subset.test.js
Source:subset.test.js
1import * as scran from "../js/index.js";2import * as simulate from "./simulate.js";3import * as compare from "./compare.js";4beforeAll(async () => { await scran.initialize({ localFile: true }) });5afterAll(async () => { await scran.terminate() });6test("column subset works", () => {7 var mat = simulate.simulateDenseMatrix(20, 10);8 var subset = scran.subsetColumns(mat, [1,5,7]);9 expect(subset.numberOfRows()).toBe(20);10 expect(subset.numberOfColumns()).toBe(3);11 expect(compare.equalArrays(mat.column(0), subset.column(0))).toBe(false);12 expect(compare.equalArrays(mat.column(1), subset.column(0))).toBe(true);13 expect(compare.equalArrays(mat.column(5), subset.column(1))).toBe(true);14 expect(compare.equalArrays(mat.column(7), subset.column(2))).toBe(true);15 // Throws the right errors.16 expect(() => scran.subsetColumns(mat, [-1])).toThrow("non-negative");17 expect(() => scran.subsetColumns(mat, [10])).toThrow("number of columns");18 // Freeing all the bits and pieces.19 subset.free();20 mat.free();21});22test("row subset works", () => {23 var mat = simulate.simulateDenseMatrix(20, 10);24 let keep = [1, 5, 7];25 var subset = scran.subsetRows(mat, keep);26 expect(subset.numberOfRows()).toBe(3);27 expect(subset.numberOfColumns()).toBe(10);28 expect(compare.equalArrays(mat.row(0), subset.row(0))).toBe(false);29 expect(compare.equalArrays(mat.row(1), subset.row(0))).toBe(true);30 expect(compare.equalArrays(mat.row(5), subset.row(1))).toBe(true);31 expect(compare.equalArrays(mat.row(7), subset.row(2))).toBe(true);32 // Throws the right errors.33 expect(() => scran.subsetRows(mat, [-1])).toThrow("non-negative");34 expect(() => scran.subsetRows(mat, [20])).toThrow("number of rows");35 // Freeing all the bits and pieces.36 mat.free();37 subset.free();38})39test("subsetting works in place", () => {40 var mat = simulate.simulateDenseMatrix(20, 10);41 let ref7 = mat.row(7);42 let keep = [1, 5, 7];43 scran.subsetRows(mat, keep, { inPlace: true });44 expect(mat.numberOfRows()).toEqual(3);45 expect(mat.row(2)).toEqual(ref7);46 let ref4 = mat.column(4);47 let keep2 = [2, 4];48 scran.subsetColumns(mat, keep2, { inPlace: true });49 expect(mat.numberOfColumns()).toEqual(2);50 expect(mat.column(1)).toEqual(ref4);51})52test("splitRows works as expected", () => {53 var factor = ["A", "B", "C", "A", "C", "B", "D"];54 let split = scran.splitByFactor(factor);55 expect(split.A).toEqual([0, 3]);56 expect(split.B).toEqual([1, 5]);57 expect(split.C).toEqual([2, 4]);58 expect(split.D).toEqual([6]);59 var mat = simulate.simulateDenseMatrix(7, 10);60 let splitmats = scran.splitRows(mat, split);61 expect(splitmats.A.numberOfRows()).toBe(2);62 expect(splitmats.A.row(0)).toEqual(mat.row(0));63 expect(splitmats.A.row(1)).toEqual(mat.row(3));64 expect(splitmats.D.numberOfRows()).toBe(1);65 expect(splitmats.D.row(0)).toEqual(mat.row(6));66 // Works correctly if there's only one level.67 let solo_factor = new Array(factor.length);68 solo_factor.fill("X");69 let solo_split = scran.splitByFactor(solo_factor);70 expect(scran.splitRows(mat, solo_split, { singleNull: true })).toBeNull();71 let solomats = scran.splitRows(mat, solo_split);72 expect(solomats.X.numberOfRows()).toBe(mat.numberOfRows());73 expect(solomats.X.row(6)).toEqual(mat.row(6));74 // It's a clone, so it should be in a different address space.75 let new_ptr = solomats.X.matrix.$$.ptr;76 expect(new_ptr >= 0).toBe(true);77 let old_ptr = mat.matrix.$$.ptr;78 expect(old_ptr >= 0).toBe(true);79 expect(new_ptr).not.toBe(old_ptr);80 for (const v of Object.values(splitmats)) {81 v.free();82 }83 for (const v of Object.values(solomats)) {84 v.free();85 }86 // Works when returning a MultiMatrix.87 let split2 = scran.splitRows(mat, split, { createMultiMatrix: true });88 expect(split2.available().sort()).toEqual(["A", "B", "C", "D"]);89 split2.free();90 mat.free();...
test.js
Source:test.js
1import test from 'tape-catch';2import isSubset from './module';3test('Detects shallow subsets.', (is) => {4 is.ok(isSubset(5 {},6 {}7 ), 'with empty objects'8 );9 is.ok(isSubset(10 {a: 1},11 {}12 ), 'with an empty subset'13 );14 is.ok(isSubset(15 {a: 1, b: 2},16 {a: 1, b: 2}17 ), 'with deep-equal objects'18 );19 is.ok(isSubset(20 {a: 1, b: true, c: null, d: 'D', e: undefined, 'F-': 'anything'},21 {a: 1, b: true, c: null, d: 'D', e: undefined, 'F-': 'anything'}22 ), 'with deep-equal objects of different kinds of values'23 );24 is.ok(isSubset(25 {a: 1, b: 2},26 {a: 1}27 ), 'with simple subsets'28 );29 is.end();30});31test('Detects shallow non-subsets.', (is) => {32 is.notOk(isSubset(33 {},34 {a: 1}35 ), 'with an empty superset'36 );37 is.notOk(isSubset(38 {a: 1},39 {a: 2}40 ), 'with differences in values'41 );42 is.notOk(isSubset(43 {a: 1},44 {b: 1}45 ), 'with differences in keys'46 );47 is.notOk(isSubset(48 {a: 1},49 {a: 1, b: 2}50 ), 'with different sizes'51 );52 is.notOk(isSubset(53 {a: 0},54 {a: false}55 ), 'seeing the difference between falsey values'56 );57 is.notOk(isSubset(58 {a: null},59 {a: undefined}60 ), 'seeing the difference between null and undefined'61 );62 is.notOk(isSubset(63 {a: 1},64 {a: 1, b: undefined}65 ), 'seeing the difference between undefined reference and undefined value'66 );67 is.end();68});69test('Detects deep subsets.', (is) => {70 is.ok(isSubset(71 {a: {}},72 {a: {}}73 ), 'with nested empty objects'74 );75 is.ok(isSubset(76 {a: {}},77 {}78 ), 'with an empty subset'79 );80 is.ok(isSubset(81 {a: {b: 2}},82 {a: {}}83 ), 'with a nested empty subset'84 );85 is.ok(isSubset(86 {a: {b: 2}},87 {a: {b: 2}}88 ), 'with deep-equal objects'89 );90 is.ok(isSubset(91 {a: 1, b: true, c: null, d: 'D', e: undefined, 'F-': 'anything'},92 {a: 1, b: true, c: null, d: 'D', e: undefined, 'F-': 'anything'}93 ), 'with deep-equal objects of different kinds of values'94 );95 is.ok(isSubset(96 {a: 1, b: {c: 3, d: 4}, e: {f: {g: 7, h: {i: 9}}}},97 {a: 1, b: {d: 4}, e: {f: {g: 7}}}98 ), 'with multiple levels of nesting'99 );100 is.end();101});102test('Detects deep non-subsets.', (is) => {103 is.notOk(isSubset(104 {a: {}},105 {a: {b: 1}}106 ), 'with an empty object in the superset'107 );108 is.notOk(isSubset(109 {a: {b: 2}},110 {a: {b: 3}}111 ), 'with differences in values in a nested object'112 );113 is.notOk(isSubset(114 {z: {a: 1}},115 {z: {b: 1}}116 ), 'with differences in keys in a nested object'117 );118 is.notOk(isSubset(119 {z: {a: 1}},120 {z: {a: 1, b: 2}}121 ), 'with different sizes of a nested object'122 );123 is.end();124});125test('Works with array values.', (is) => {126 is.ok(isSubset(127 {a: []},128 {a: []}129 ), 'treating empty arrays as equal'130 );131 is.ok(isSubset(132 {a: [1]},133 {a: [1]}134 ), 'treating equal arrays as equal'135 );136 is.notOk(isSubset(137 {a: [1]},138 {a: [1, 2]}139 ), 'detecting differences in length'140 );141 is.notOk(isSubset(142 {a: [1]},143 {a: [2]}144 ), 'detecting differences in values'145 );146 is.ok(isSubset(147 {a: [1, 2, 3]},148 {a: [1, 2]}149 ), 'treating array subsets as subsets'150 );151 is.notOk(isSubset(152 {a: [1, 2, 3]},153 {a: [1, 3]}154 ), 'â only if the order is identical'155 );156 is.end();157});158test('Returns false for non-object âobjectsâ.', (is) => {159 is.notOk(isSubset(160 'a',161 {}162 ), 'for the superset'163 );164 is.notOk(isSubset(165 {},166 'a'167 ), 'for the subset'168 );169 is.end();...
index.js
Source:index.js
1'use strict';2Object.defineProperty(exports, '__esModule', {3 value: true4});5/**6 * Check if an object is contained within another object.7 *8 * Returns `true` if:9 * - all enumerable keys of *subset* are also enumerable in *superset*, and10 * - every value assigned to an enumerable key of *subset* strictly equals11 * the value assigned to the same key of *superset* â or is a subset of it.12 *13 * @param {Object} superset14 * @param {Object} subset15 *16 * @returns {Boolean}17 *18 * @module is-subset19 * @function default20 * @alias isSubset21 */22var isSubset = (function (_isSubset) {23 function isSubset(_x, _x2) {24 return _isSubset.apply(this, arguments);25 }26 isSubset.toString = function () {27 return _isSubset.toString();28 };29 return isSubset;30})(function (superset, subset) {31 if (typeof superset !== 'object' || superset === null || (typeof subset !== 'object' || subset === null)) return false;32 return Object.keys(subset).every(function (key) {33 if (!superset.propertyIsEnumerable(key)) return false;34 var subsetItem = subset[key];35 var supersetItem = superset[key];36 if (typeof subsetItem === 'object' && subsetItem !== null ? !isSubset(supersetItem, subsetItem) : supersetItem !== subsetItem) return false;37 return true;38 });39});40exports['default'] = isSubset;...
Using AI Code Generation
1var wptools = require('wptools');2var options = {3};4var page = wptools.page('Albert Einstein', options);5page.get(function(err, resp) {6 if (!err) {7 console.log(resp);8 }9});10var wptools = require('wptools');11var options = {12};13var page = wptools.page('Albert Einstein', options);14page.get(function(err, resp) {15 if (!err) {16 console.log(resp);17 }18});19var wptools = require('wptools');20var options = {21};22var page = wptools.page('Albert Einstein', options);23page.get(function(err, resp) {24 if (!err) {25 console.log(resp);26 }27});28var wptools = require('wptools');29var options = {30};31var page = wptools.page('Albert Einstein', options);32page.get(function(err, resp) {33 if (!err) {34 console.log(resp);35 }36});37var wptools = require('wptools');38var options = {39};40var page = wptools.page('Albert Einstein', options);41page.get(function(err, resp) {42 if (!err) {43 console.log(resp);44 }45});46var wptools = require('wptools');47var options = {48};49var page = wptools.page('Albert Einstein', options);50page.get(function(err, resp) {51 if (!err) {52 console.log(resp);53 }54});55var wptools = require('wptools');56var options = {
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const file = fs.createWriteStream('output.txt');4file.on('error', function(err) { /* error handling */ });5 .page('Albert Einstein')6 .get()7 .then(function(page) {8 file.write(page.infobox().subset(['name', 'birth_date']).data);9 file.end();10 })11 .catch(function(err) {12 console.log(err);13 });
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools.page('Barack Obama');3wiki.get(function(err, resp) {4 if (err) {5 console.log(err);6 } else {7 console.log(resp);8 }9});
Using AI Code Generation
1var wpt = require('wpt.js');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3var params = {4 lighthouseConfig: {5 "settings": {6 }7 }8};9wpt.runTest(url, params, function(err, data) {10 if (err) return console.log(err);11 wpt.getTestResults(data.data.testId, function(err, data) {12 if (err) return console.log(err);13 console.log(data.data.median.firstView);14 });15});16var wpt = require('wpt.js');17var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');18var params = {19 lighthouseConfig: {20 "settings": {21 }22 }23};24wpt.runTest(url, params, function(err, data) {25 if (err) return console.log(err);26 wpt.getTestResults(data.data.testId, function(err, data) {27 if (err) return console.log(err);28 console.log(data.data.median.firstView);29 });30});31var wpt = require('wpt.js');32var wpt = new WebPageTest('
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5});6var page = wptools.page('Barack Obama');7page.get(function(err, resp) {8 console.log(resp);9});10page.get(function(err, resp) {11 console.log(resp);12});13page.get(function(err, resp) {14 console.log(resp);15});16page.get(function(err, resp) {17 console.log(resp);18});19page.get(function(err, resp) {20 console.log(resp);21});22page.get(function(err, resp) {23 console.log(resp);24});25page.get(function(err, resp) {26 console.log(resp);27});28page.get(function(err, resp) {29 console.log(resp);30});
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var data = fs.readFileSync('data.json');4var json = JSON.parse(data);5var page = json[0];6var title = page.title;7var url = page.url;8var wiki = wptools.page(title);9wiki.get(function(err, resp) {10 if (err) {11 console.log(err);12 } else {13 var data = resp.data;14 var subset = data.subset(['image', 'abstract']);15 console.log(subset);16 }17});18 {19 },20 {21 },22 {23 }24 {25 },26 {27 },28 {29 }30var wptools = require('wptools');31var fs = require('fs');32var data = fs.readFileSync('data.json');33var json = JSON.parse(data);34var page = json[0];35var title = page.title;36var url = page.url;37var wiki = wptools.page(title);38wiki.get(function(err, resp) {39 if (err) {40 console.log(err);41 } else {42 var data = resp.data;43 var subset = data.subset(['image', 'abstract']);44 console.log(subset);45 }46});47 {48 },49 {
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.subset('general').get(function(err, data) {4 if (err) {5 console.log(err);6 }7 console.log(data);8 page.saveJSON(data, 'barackobama.json');9});10### wptools.page()11- lang: The language of the wikipedia page (default is 'en')12var page = wptools.page('Barack Obama');13### page.get()14page.get(function(err, data) {15 if (err) {16 console.log(err);17 }18 console.log(data);19});20### page.subset()21page.subset('general').get(function(err, data) {22 if (err) {23 console.log(err);24 }25 console.log(data);26});27### page.saveJSON()28page.saveJSON(data, 'barackobama.json');
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var _ = require('lodash');4var async = require('async');5var request = require('request');6var cheerio = require('cheerio');7var csv = require('fast-csv');8var stream = fs.createReadStream("microsoft.csv");9var csvStream = csv.createWriteStream({headers: true}),10 writableStream = fs.createWriteStream("microsoft1.csv");11writableStream.on("finish", function(){12 console.log("DONE!");13});14csvStream.pipe(writableStream);15var count = 0;16var count1 = 0;17var count2 = 0;18var count3 = 0;19var count4 = 0;20var count5 = 0;21var count6 = 0;22var count7 = 0;23var count8 = 0;24var count9 = 0;25var count10 = 0;26var count11 = 0;27var count12 = 0;28var count13 = 0;29var count14 = 0;30var count15 = 0;31var count16 = 0;32var count17 = 0;33var count18 = 0;34var count19 = 0;35var count20 = 0;36var count21 = 0;37var count22 = 0;38var count23 = 0;39var count24 = 0;40var count25 = 0;41var count26 = 0;42var count27 = 0;43var count28 = 0;44var count29 = 0;45var count30 = 0;46var count31 = 0;47var count32 = 0;48var count33 = 0;49var count34 = 0;50var count35 = 0;51var count36 = 0;52var count37 = 0;53var count38 = 0;54var count39 = 0;55var count40 = 0;56var count41 = 0;57var count42 = 0;58var count43 = 0;59var count44 = 0;60var count45 = 0;61var count46 = 0;
Using AI Code Generation
1const wptools = require('wptools')2wptools.list('en.wikipedia.org', 'allpages', { apnamespace: 0, aplimit: 3 })3 .then(function (res) {4 console.log(res)5 })6 .catch(function (err) {7 console.log(err)8 })9wptools.list('en.wikipedia.org', 'categorymembers', { cmtitle: 'Category:Physics', cmlimit: 3 })10 .then(function (res) {11 console.log(res)12 })13 .catch(function (err) {14 console.log(err)15 })16wptools.list('en.wikipedia.org', 'categorymembers', { cmtitle: 'Category:Physics', cmlimit: 3 })17 .then(function (res) {18 console.log(res)19 })20 .catch(function (err) {21 console.log(err)22 })23wptools.list('en.wikipedia.org', 'categorymembers', { cmtitle: 'Category:Physics', cmlimit: 3 })24 .then(function (res) {25 console.log(res)26 })27 .catch(function (err) {28 console.log(err)29 })30wptools.list('en.wikipedia.org', 'categorymembers', { cmtitle: 'Category:Physics', cmlimit: 3 })31 .then(function (res) {32 console.log(res)33 })34 .catch(function (err) {35 console.log(err)36 })37wptools.list('en.wikipedia.org', 'categorymembers', { cmtitle: 'Category:Physics', cmlimit: 3 })38 .then(function (res) {39 console.log(res)40 })41 .catch(function (err) {42 console.log(err)43 })44wptools.list('en
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!!