How to use inserts method in argos

Best JavaScript code snippet using argos

RBTree.test.ts

Source:RBTree.test.ts Github

copy

Full Screen

1import * as _ from 'lodash';2import {load, buildTree, getInserts, newTree} from './loaderUtil';3import {RBTree} from '../src/RBTree';4const SAMPLE_FILE = __dirname + '/samples/10k';5describe('Test RBTree API', () => {6 test('clear()', () => {7 const inserts = getInserts(load(SAMPLE_FILE));8 const tree = buildTree(RBTree, inserts);9 tree.clear();10 inserts.forEach(function(data) {11 expect(tree.find(data)).toBe(null);12 });13 });14 test('dup', () => {15 const tree = newTree(RBTree);16 expect(tree.insert(100)).toBe(true);17 expect(tree.insert(101)).toBe(true);18 expect(tree.insert(101)).toBe(false);19 expect(tree.insert(100)).toBe(false);20 tree.remove(100);21 expect(tree.insert(100)).toBe(true);22 expect(tree.insert(100)).toBe(false);23 });24 test('nonexist()', () => {25 const tree = newTree(RBTree);26 expect(tree.remove(100)).toBe(false);27 tree.insert(100);28 expect(tree.remove(101)).toBe(false);29 expect(tree.remove(100)).toBe(true);30 });31 test('min()', () => {32 let tree = newTree(RBTree);33 expect(tree.min()).toEqual(null);34 const inserts = getInserts(load(SAMPLE_FILE));35 tree = buildTree(RBTree, inserts);36 expect(tree.min()).toEqual(_.min(inserts));37 });38 test('max()', () => {39 let tree = newTree(RBTree);40 expect(tree.max()).toEqual(null);41 const inserts = getInserts(load(SAMPLE_FILE));42 tree = buildTree(RBTree, inserts);43 expect(tree.max()).toEqual(_.max(inserts));44 });45 test('forwardIt()', () => {46 const inserts = getInserts(load(SAMPLE_FILE));47 const tree = buildTree(RBTree, inserts);48 let items = [];49 const it = tree.iterator();50 let data;51 while ((data = it.next()) !== null) {52 items.push(data);53 }54 inserts.sort(function(a, b) {55 return a - b;56 });57 expect(items).toEqual(inserts);58 items = [];59 tree.each(function(data) {60 items.push(data);61 });62 expect(items).toEqual(inserts);63 });64 test('forwardItBreak()', () => {65 const inserts = getInserts(load(SAMPLE_FILE));66 const tree = buildTree(RBTree, inserts);67 let items = [];68 const it = tree.iterator();69 let data;70 while ((data = it.next()) !== null) {71 items.push(data);72 }73 inserts.sort(function(a, b) {74 return a - b;75 });76 expect(items).toEqual(inserts);77 items = [];78 let i = 0;79 tree.each(function(data) {80 items.push(data);81 if (i === 3) {82 return false;83 }84 i++;85 });86 expect(items.length).toBe(4);87 });88 test('reverseIt()', () => {89 const inserts = getInserts(load(SAMPLE_FILE));90 const tree = buildTree(RBTree, inserts);91 let items = [];92 const it = tree.iterator();93 let data;94 while ((data = it.prev()) !== null) {95 items.push(data);96 }97 inserts.sort(function(a, b) {98 return b - a;99 });100 expect(items).toEqual(inserts);101 items = [];102 tree.reach(function(data) {103 items.push(data);104 });105 expect(items).toEqual(inserts);106 });107 test('reverseItBreak()', () => {108 const inserts = getInserts(load(SAMPLE_FILE));109 const tree = buildTree(RBTree, inserts);110 let items = [];111 const it = tree.iterator();112 let data;113 while ((data = it.prev()) !== null) {114 items.push(data);115 }116 inserts.sort(function(a, b) {117 return b - a;118 });119 expect(items).toEqual(inserts);120 items = [];121 let i = 0;122 tree.reach(function(data) {123 items.push(data);124 if (i === 3) {125 return false;126 }127 i++;128 });129 expect(items.length).toBe(4);130 });131 test('switchIt()', () => {132 const inserts = getInserts(load(SAMPLE_FILE));133 const tree = buildTree(RBTree, inserts);134 inserts.sort(function(a, b) {135 return a - b;136 });137 function doSwitch(after) {138 const items = [];139 const it = tree.iterator();140 for (let i = 0; i < after; i++) {141 items.push(it.next());142 }143 let data;144 while ((data = it.prev()) !== null) {145 items.push(data);146 }147 const forward = inserts.slice(0, after);148 const reverse = inserts.slice(0, after - 1).reverse();149 const all = forward.concat(reverse);150 expect(items).toEqual(all);151 }152 doSwitch(1);153 doSwitch(10);154 // doSwitch(1000);155 // doSwitch(9000);156 });157 test('emptyIt()', () => {158 const tree = newTree(RBTree);159 let it = tree.iterator();160 expect(it.next()).toBe(null);161 it = tree.iterator();162 expect(it.prev()).toBe(null);163 });164 test('lowerBound()', () => {165 const inserts = getInserts(load(SAMPLE_FILE));166 const tree = buildTree(RBTree, inserts);167 inserts.sort(function(a, b) {168 return a - b;169 });170 for (let i = 1; i < inserts.length - 1; ++i) {171 const item = inserts[i];172 const iter = tree.lowerBound(item);173 expect(iter.data()).toEqual(item);174 expect(iter.prev()).toEqual(inserts[i - 1]);175 iter.next();176 expect(iter.next()).toEqual(inserts[i + 1]);177 const prev = tree.lowerBound(item - 0.1);178 expect(prev.data()).toEqual(inserts[i]);179 const next = tree.lowerBound(item + 0.1);180 expect(next.data()).toEqual(inserts[i + 1]);181 }182 // test edges183 let iter = tree.lowerBound(-1);184 expect(iter.data()).toEqual(inserts[0]);185 const last = inserts[inserts.length - 1];186 iter = tree.lowerBound(last);187 expect(iter.data()).toEqual(last);188 iter = tree.lowerBound(last + 1);189 expect(iter.data()).toEqual(null);190 });191 test('upperBound()', () => {192 const inserts = getInserts(load(SAMPLE_FILE));193 const tree = buildTree(RBTree, inserts);194 inserts.sort(function(a, b) {195 return a - b;196 });197 for (let i = 0; i < inserts.length - 2; ++i) {198 const item = inserts[i];199 const iter = tree.upperBound(item);200 expect(iter.data()).toEqual(inserts[i + 1]);201 expect(iter.prev()).toEqual(inserts[i]);202 iter.next();203 expect(iter.next()).toEqual(inserts[i + 2]);204 const prev = tree.upperBound(item - 0.1);205 expect(prev.data()).toEqual(inserts[i]);206 const next = tree.upperBound(item + 0.1);207 expect(next.data()).toEqual(inserts[i + 1]);208 }209 // test edges210 let iter = tree.upperBound(-1);211 expect(iter.data()).toEqual(inserts[0]);212 const last = inserts[inserts.length - 1];213 iter = tree.upperBound(last);214 expect(iter.data()).toEqual(null);215 iter = tree.upperBound(last + 1);216 expect(iter.data()).toEqual(null);217 // test empty218 const empty = new RBTree(function(a, b) {219 return a.val - b.val;220 });221 iter = empty.upperBound({val: 0});222 expect(iter.data()).toEqual(null);223 });224 test('find', () => {225 const inserts = getInserts(load(SAMPLE_FILE));226 const tree = buildTree(RBTree, inserts);227 for (let i = 1; i < inserts.length - 1; ++i) {228 const item = inserts[i];229 expect(tree.find(item)).toEqual(item);230 expect(tree.find(item + 0.1)).toEqual(null);231 }232 });233 test('findIter()', () => {234 const inserts = getInserts(load(SAMPLE_FILE));235 const tree = buildTree(RBTree, inserts);236 inserts.sort(function(a, b) {237 return a - b;238 });239 for (let i = 1; i < inserts.length - 1; ++i) {240 const item = inserts[i];241 const iter = tree.findIter(item);242 expect(iter.data()).toEqual(item);243 expect(iter.prev()).toEqual(inserts[i - 1]);244 iter.next();245 expect(iter.next()).toEqual(inserts[i + 1]);246 expect(tree.findIter(item + 0.1)).toEqual(null);247 }248 });249});250describe('Test RBTree Correctness', () => {251 test('Correctness Validation', () => {252 const tree = newTree(RBTree);253 const tests = load(SAMPLE_FILE);254 let elems = 0;255 tests.forEach(function(n) {256 if (n > 0) {257 // insert258 expect(tree.insert(n)).toBe(true);259 expect(tree.find(n)).toBe(n);260 elems++;261 } else {262 // remove263 n = -n;264 expect(tree.remove(n)).toBe(true);265 expect(tree.find(n)).toBe(null);266 elems--;267 }268 expect(tree.size).toEqual(elems);269 expect(rbAssert(tree._root, tree._comparator));270 });271 });272});273function isRed(node) {274 return node !== null && node.red;275}276function rbAssert(root, comparator) {277 if (root === null) {278 return 1;279 } else {280 const ln = root.left;281 const rn = root.right;282 // red violation283 if (isRed(root)) {284 expect(isRed(ln) || isRed(rn)).toBe(false);285 }286 const lh = rbAssert(ln, comparator);287 const rh = rbAssert(rn, comparator);288 // invalid binary search tree289 expect((ln !== null && comparator(ln.data, root.data) >= 0) ||290 (rn !== null && comparator(rn.data, root.data) <= 0)).toBe(false);291 // black height mismatch292 expect(lh !== 0 && rh !== 0 && lh !== rh).toBe(false);293 // count black links294 if (lh !== 0 && rh !== 0) {295 return isRed(root) ? lh : lh + 1;296 } else {297 return 0;298 }299 }...

Full Screen

Full Screen

all.js

Source:all.js Github

copy

Full Screen

1export function runCommonTests(getUtil) {2 test("list tables should work", async() => {3 await getUtil().listTableTests()4 })5 test("column tests", async() => {6 await getUtil().tableColumnsTests()7 })8 test("table view tests", async () => {9 await getUtil().tableViewTests()10 })11 test("stream tests", async () => {12 if (getUtil().dbType === 'cockroachdb') {13 return14 }15 await getUtil().streamTests()16 })17 test("query tests", async () => {18 await getUtil().queryTests()19 })20 test("table filter tests", async () => {21 await getUtil().filterTests()22 })23 test("table triggers", async () => {24 await getUtil().triggerTests()25 })26 test("primary key tests", async () => {27 await getUtil().primaryKeyTests()28 })29 describe("Alter Table Tests", () => {30 beforeEach(async() => {31 await prepareTestTable(getUtil())32 })33 test("should past alter table tests", async () => {34 await getUtil().alterTableTests()35 })36 test("should alter indexes", async () => {37 await getUtil().indexTests()38 })39 })40 describe("Table Structure", () => {41 test("should fetch table properties", async() => {42 await getUtil().tablePropertiesTests()43 })44 })45 describe("Data modification", () => {46 beforeEach(async () => {47 await prepareTestTable(getUtil())48 })49 50 test("should insert good data", async () => {51 await itShouldInsertGoodData(getUtil())52 })53 test("should not insert bad data", async () => {54 await itShouldNotInsertBadData(getUtil())55 })56 test("should apply all types of changes", async () => {57 await itShouldApplyAllTypesOfChanges(getUtil())58 })59 test("should not commit on change error", async () => {60 await itShouldNotCommitOnChangeError(getUtil())61 })62 })63}64// test functions below65const prepareTestTable = async function(util) {66 await util.knex.schema.dropTableIfExists("test_inserts")67 await util.knex.schema.createTable("test_inserts", (table) => {68 table.integer("id").primary().notNullable()69 table.specificType("firstName", "varchar(255)")70 table.specificType("lastName", "varchar(255)")71 })72}73export const itShouldInsertGoodData = async function(util) {74 const inserts = [75 {76 table: 'test_inserts',77 schema: util.options.defaultSchema,78 data: [{79 id: 1,80 firstName: 'Terry',81 lastName: 'Tester'82 }]83 },84 {85 table: 'test_inserts',86 schema: util.options.defaultSchema,87 data: [{88 id: 2,89 firstName: 'John',90 lastName: 'Doe'91 }]92 }93 ]94 await util.connection.applyChanges({ inserts: inserts })95 const results = await util.knex.select().table('test_inserts')96 expect(results.length).toBe(2)97}98export const itShouldNotInsertBadData = async function(util) {99 const inserts = [100 {101 table: 'test_inserts',102 schema: util.options.defaultSchema,103 data: [{104 id: 1,105 firstName: 'Terry',106 lastName: 'Tester'107 }]108 },109 {110 table: 'test_inserts',111 schema: util.options.defaultSchema,112 data: [{113 id: 1,114 firstName: 'John',115 lastName: 'Doe'116 }]117 }118 ]119 await expect(util.connection.applyChanges({ inserts: inserts })).rejects.toThrow()120 const results = await util.knex.select().table('test_inserts')121 expect(results.length).toBe(0)122}123export const itShouldApplyAllTypesOfChanges = async function(util) {124 const changes = {125 inserts: [126 {127 table: 'test_inserts',128 schema: util.options.defaultSchema,129 data: [{130 id: 1,131 firstName: 'Tom',132 lastName: 'Tester'133 }]134 },135 {136 table: 'test_inserts',137 schema: util.options.defaultSchema,138 data: [{139 id: 2,140 firstName: 'Jane',141 lastName: 'Doe'142 }]143 }144 ],145 updates: [146 {147 table: 'test_inserts',148 schema: util.options.defaultSchema,149 pkColumn: 'id',150 primaryKey: 1,151 column: 'firstName',152 value: 'Testy'153 }154 ],155 deletes: [156 {157 table: 'test_inserts',158 schema: util.options.defaultSchema,159 pkColumn: 'id',160 primaryKey: 2,161 }162 ]163 }164 await util.connection.applyChanges(changes)165 const results = await util.knex.select().table('test_inserts')166 expect(results.length).toBe(1)167 const firstResult = { ...results[0] }168 // hack for cockroachdb169 firstResult.id = Number(firstResult.id)170 expect(firstResult).toStrictEqual({171 id: 1,172 firstName: 'Testy',173 lastName: 'Tester'174 })175}176export const itShouldNotCommitOnChangeError = async function(util) {177 const inserts = [178 {179 table: 'test_inserts',180 schema: util.options.defaultSchema,181 data: [{182 id: 1,183 firstName: 'Terry',184 lastName: 'Tester'185 }]186 }187 ]188 await util.connection.applyChanges({ inserts: inserts })189 const changes = {190 inserts: [191 {192 table: 'test_inserts',193 schema: util.options.defaultSchema,194 data: [{195 id: 2,196 firstName: 'Tom',197 lastName: 'Tester'198 }]199 },200 {201 table: 'test_inserts',202 schema: util.options.defaultSchema,203 data: [{204 id: 3,205 firstName: 'Jane',206 lastName: 'Doe'207 }]208 }209 ],210 updates: [211 {212 table: 'test_inserts',213 schema: util.options.defaultSchema,214 pkColumn: 'id',215 primaryKey: 1,216 column: 'id',217 value: 2218 }219 ],220 deletes: [221 {222 table: 'test_inserts',223 schema: util.options.defaultSchema,224 pkColumn: 'id',225 primaryKey: 1,226 }227 ]228 }229 await expect(util.connection.applyChanges(changes)).rejects.toThrow()230 const results = await util.knex.select().table('test_inserts')231 expect(results.length).toBe(1)232 const firstResult = { ...results[0]}233 // hack for cockroachdb234 firstResult.id = Number(firstResult.id)235 expect(firstResult).toStrictEqual({236 id: 1,237 firstName: 'Terry',238 lastName: 'Tester'239 })...

Full Screen

Full Screen

start.js

Source:start.js Github

copy

Full Screen

1import {2 listBroadcast,3 listStream,4 insertStream,5 bindBroadcast,6 insertBroadcast,7} from '../youtube';8const fetch = require('node-fetch');9const findBroadcast = async () => {10 const broadcasts = await listBroadcast();11 let broadcast = false;12 console.log(broadcasts);13 broadcasts.forEach((item) => {14 if (item.snippet.title === process.env.BROADCAST_TITLE) {15 broadcast = item;16 }17 });18 return broadcast;19}20const getStreamKey = async (streamId) => {21 const stream = await listStream(streamId);22 return stream.cdn.ingestionInfo.streamName;23}24const getInserts = async (session) => {25 // first, let's see if the inserts are stored in the session26 let inserts = session.inserts;27 if (inserts) {28 console.log('Found broadcast in session...');29 return session.inserts;30 }31 // if not in session, try user created broadcasts32 inserts = {};33 const existingBroadcast = await findBroadcast();34 if (existingBroadcast) {35 console.log('Found existing broadcast by name...');36 inserts.broadcast = existingBroadcast.id;37 const boundStream = existingBroadcast.contentDetails.boundStreamId;38 // broadcast already has bound stream, use it39 if (boundStream) {40 console.log('Found existing bound stream...');41 inserts.stream = boundStream;42 session.inserts = inserts;43 return inserts;44 }45 // broadcast doesn't have a bound stream yet, create one and bind it46 else {47 console.log('Creating and binding new stream...');48 const newStreamId = await insertStream();49 inserts.stream = newStreamId;50 await bindBroadcast(inserts);51 session.inserts = inserts;52 return inserts;53 }54 }55 // no broadcast exists with our name56 else {57 console.log('Creating new broadcast and stream...');58 const newBroadcastId = await insertBroadcast();59 const newStreamId = await insertStream();60 inserts = {61 broadcast: newBroadcastId,62 stream: newStreamId,63 };64 await bindBroadcast(inserts);65 session.inserts = inserts;66 return inserts;67 }68}69const stream = async (session) => {70 console.log(`Attempting to stream...`);71 const inserts = await getInserts(session);72 const streamKey = await getStreamKey(inserts.stream);73 fetch(`http://localhost:${process.env.OBS_HTTP_PORT}/start`, {74 method: 'POST',75 headers: {76 Accept: 'application/json',77 'Content-Type': 'application/json',78 },79 body: JSON.stringify({80 streamKey,81 }),82 });83 return inserts;84};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var pipeline = require('argosy-pipeline')3var inserts = require('argosy-pipeline').inserts4var service = argosy()5service.pipe(inserts(function (msg) {6})).pipe(process.stdout)7service.accept({test: 'hello world'})8var argosy = require('argosy')9var pipeline = require('argosy-pipeline')10var service = argosy()11service.pipe(filter(function (msg) {12})).pipe(process.stdout)13service.accept({test: 'hello world'})14var argosy = require('argosy')15var pipeline = require('argosy-pipeline')16var service = argosy()17service.pipe(map(function (msg) {18})).pipe(process.stdout)19service.accept({test: 'hello world'})20var argosy = require('argosy')21var pipeline = require('argosy-pipeline')22var service = argosy()23service.pipe(merge()).pipe(process.stdout)24service.accept({test: 'hello world'})25var argosy = require('argosy')26var pipeline = require('argosy-pipeline')27var service = argosy()28service.pipe(reduce(function (acc, msg) {29}, '')).pipe(process.stdout)30service.accept({test: 'hello'})31service.accept({test: ' world'})

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var pattern = argosyPattern()4var argosyPattern = require('argosy-pattern')5var pattern = argosyPattern()6var argosy = require('argosy')7var service = argosy()8 .use('role:math,cmd:sum', function (msg, cb) {9 cb(null, { answer: msg.left + msg.right })10 })11 .use('role:math,cmd:sum', function (msg, cb) {12 cb(null, { answer: msg.left + msg.right })13 })14 .listen({ port: 8000 })15var client = argosy()16 .use(function (msg, cb) {17 cb(null, { left: 1, right: 2 })18 })19 .use(pattern({20 answer: insert('sum')21 }))22 .use(function (msg, cb) {23 cb()24 })25 .connect(8000)26### pattern(pattern, [options])27var pattern = require('argosy-pattern')28var msg = {29}30var matcher = pattern({31})32var matcher = pattern({33})34var matcher = pattern({35 quux: insert('quux')36})

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var pattern = require('argosy-pattern')3var service = argosy()4service.pipe(argosy.acceptor({port: 8000}))5service.accept({hello: insert('name')}, function (msg, respond) {6 respond(null, {hello: msg.name})7})

Full Screen

Using AI Code Generation

copy

Full Screen

1var pattern = require('argosy-pattern')2var insertsPattern = inserts({ name: String })3### `matches(pattern, data)`4var pattern = require('argosy-pattern')5var matchesPattern = matches({ name: String })6### `matchesAny(pattern, data)`7var pattern = require('argosy-pattern')8var matchesAnyPattern = matchesAny([{ name: String }])9### `matchesAll(pattern, data)`10var pattern = require('argosy-pattern')11var matchesAllPattern = matchesAll([{ name: String }])12### `matchesSome(pattern, data)`13var pattern = require('argosy-pattern')

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var pattern = require('argosy-pattern')3var service = argosy()4service.accept({5 insert: insert({6 })7})8service.pipe(argosy.pattern({9 insert: insert({10 })11})).pipe(service)12service.on('insert', function (request, cb) {13 console.log('insert request', request)14 cb(null, { inserted: true })15})16service.insert({17}, function (err, response) {18 console.log('inserted', response)19})

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 argos 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