How to use evalFn method in stryker-parent

Best JavaScript code snippet using stryker-parent

join_predicate_test.ts

Source:join_predicate_test.ts Github

copy

Full Screen

1/**2 * Copyright 2018 The Lovefield Project Authors. All Rights Reserved.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16import * as chai from 'chai';17import {EvalType} from '../../lib/base/eval';18import {Row, PayloadType} from '../../lib/base/row';19import {JoinPredicate} from '../../lib/pred/join_predicate';20import {Predicate} from '../../lib/pred/predicate';21import {Relation} from '../../lib/proc/relation';22import {RelationEntry} from '../../lib/proc/relation_entry';23import {Column} from '../../lib/schema/column';24import {DatabaseSchema} from '../../lib/schema/database_schema';25import {BaseTable} from '../../lib/schema/base_table';26import {Table} from '../../lib/schema/table';27import {getHrDbSchemaBuilder} from '../../testing/hr_schema/hr_schema_builder';28import {HRSchemaSampleData} from '../../testing/hr_schema/hr_schema_sample_data';29import {NullableDataGenerator} from '../../testing/nullable_data_generator';30const assert = chai.assert;31interface SampleDataType {32 departments: Row[];33 employees: Row[];34 jobs: Row[];35}36describe('JoinPredicate', () => {37 let db: DatabaseSchema;38 let d: Table;39 let e: BaseTable;40 let j: BaseTable;41 let schemaWithNullable: DatabaseSchema;42 let nullableGenerator: NullableDataGenerator;43 before(() => {44 db = getHrDbSchemaBuilder().getSchema();45 d = db.table('Department');46 e = db.table('Employee') as BaseTable;47 j = db.table('Job') as BaseTable;48 // For the tests involving nullable columns, a different schema49 // is created. The tables in hr schema do not handle nullable column.50 nullableGenerator = new NullableDataGenerator();51 schemaWithNullable = nullableGenerator.schema;52 nullableGenerator.generate();53 });54 it('copy', () => {55 const original = e.col('jobId').eq(j.col('id')) as JoinPredicate;56 const copy = original.copy();57 assert.isTrue(original instanceof JoinPredicate);58 assert.isTrue(copy instanceof JoinPredicate);59 assert.notEqual(original, copy);60 assert.equal(original.leftColumn, copy.leftColumn);61 assert.equal(original.rightColumn, copy.rightColumn);62 assert.equal(original.evaluatorType, copy.evaluatorType);63 assert.equal(original.getId(), copy.getId());64 });65 it('getColumns', () => {66 const p: Predicate = e.col('jobId').eq(j.col('id'));67 assert.sameMembers([e.col('jobId'), j.col('id')], p.getColumns());68 // Test case where optional parameter is provided.69 const columns: Column[] = [];70 assert.equal(columns, p.getColumns(columns));71 assert.sameMembers([e.col('jobId'), j.col('id')], columns);72 });73 it('getTables', () => {74 const p: Predicate = e.col('jobId').eq(j.col('id'));75 assert.sameMembers([e, j], Array.from(p.getTables().values()));76 // Test case where optional parameter is provided.77 const tables = new Set<Table>();78 assert.equal(tables, p.getTables(tables));79 assert.sameMembers([e, j], Array.from(tables.values()));80 });81 it('joinPredicate_reverse', () => {82 const predicates = [83 e.col('jobId').lt(j.col('id')),84 e.col('jobId').gt(j.col('id')),85 e.col('jobId').lte(j.col('id')),86 e.col('jobId').gte(j.col('id')),87 e.col('jobId').eq(j.col('id')),88 e.col('jobId').neq(j.col('id')),89 ] as JoinPredicate[];90 const expectedEvalTypes: EvalType[] = [91 EvalType.GT,92 EvalType.LT,93 EvalType.GTE,94 EvalType.LTE,95 EvalType.EQ,96 EvalType.NEQ,97 ];98 checkJoinPredicate_ExplicitReverse(predicates, expectedEvalTypes);99 checkJoinPredicate_NestedLoop_Reverse(predicates, expectedEvalTypes);100 });101 // Tests that JoinPredicate.reverse() works correctly.102 function checkJoinPredicate_ExplicitReverse(103 predicates: JoinPredicate[],104 expectedEvalTypes: EvalType[]105 ): void {106 for (let i = 0; i < predicates.length; i++) {107 const reversePredicate = predicates[i].reverse();108 assert.equal(predicates[i].leftColumn, reversePredicate.rightColumn);109 assert.equal(predicates[i].rightColumn, reversePredicate.leftColumn);110 assert.equal(expectedEvalTypes[i], reversePredicate.evaluatorType);111 }112 }113 // Tests that Nested Loop Join reverses join order and evaluation type when114 // right table is smaller than the left.115 function checkJoinPredicate_NestedLoop_Reverse(116 predicates: JoinPredicate[],117 expectedEvalTypes: EvalType[]118 ): void {119 const sampleRows = getSampleRows();120 const sampleEmployees = sampleRows.employees;121 const sampleJobs = sampleRows.jobs;122 const employeeRelation = Relation.fromRows(sampleEmployees, [123 e.getEffectiveName(),124 ]);125 const jobRelation = Relation.fromRows(sampleJobs, [j.getEffectiveName()]);126 const expectedLeftColumn = predicates[0].leftColumn;127 const expectedRightColumn = predicates[1].rightColumn;128 for (let i = 0; i < predicates.length; i++) {129 predicates[i].evalRelationsNestedLoopJoin(130 employeeRelation,131 jobRelation,132 false133 );134 assert.equal(expectedRightColumn, predicates[i].leftColumn);135 assert.equal(expectedLeftColumn, predicates[i].rightColumn);136 assert.equal(expectedEvalTypes[i], predicates[i].evaluatorType);137 }138 }139 it('joinPredicate_Eval_True', () => {140 const leftEntry = new RelationEntry(141 HRSchemaSampleData.generateSampleEmployeeData(),142 false143 );144 const rightEntry = new RelationEntry(145 HRSchemaSampleData.generateSampleJobData(),146 false147 );148 const combinedEntry = RelationEntry.combineEntries(149 leftEntry,150 [e.getName()],151 rightEntry,152 [j.getName()]153 );154 const relation = new Relation([combinedEntry], [e.getName(), j.getName()]);155 const joinPredicate1 = e.col('jobId').eq(j.col('id'));156 const resultRelation1 = joinPredicate1.eval(relation);157 assert.equal(1, resultRelation1.entries.length);158 const joinPredicate2 = j.col('id').eq(e.col('jobId'));159 const resultRelation2 = joinPredicate2.eval(relation);160 assert.equal(1, resultRelation2.entries.length);161 });162 it('joinPredicate_Eval_False', () => {163 const leftEntry = new RelationEntry(164 HRSchemaSampleData.generateSampleEmployeeData(),165 false166 );167 const rightEntry = new RelationEntry(168 HRSchemaSampleData.generateSampleJobData(),169 false170 );171 const combinedEntry = RelationEntry.combineEntries(172 leftEntry,173 [e.getName()],174 rightEntry,175 [j.getName()]176 );177 const relation = new Relation([combinedEntry], [e.getName(), j.getName()]);178 const joinPredicate = e.col('firstName').eq(j.col('id'));179 const resultRelation = joinPredicate.eval(relation);180 assert.equal(0, resultRelation.entries.length);181 });182 // Tests that evalRelations() will detect which input relation should be used183 // as "left" and which as "right" independently of the input order.184 // |evalFn| is the join implementation method, should be either185 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.186 function checkJoinPredicate_RelationsInputOrder(187 employeeSchema: BaseTable,188 jobSchema: BaseTable,189 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation190 ): void {191 const sampleEmployee = HRSchemaSampleData.generateSampleEmployeeData();192 const sampleJob = HRSchemaSampleData.generateSampleJobData();193 const employeeRelation = Relation.fromRows(194 [sampleEmployee],195 [employeeSchema.getEffectiveName()]196 );197 const jobRelation = Relation.fromRows(198 [sampleJob],199 [jobSchema.getEffectiveName()]200 );201 const joinPredicate = employeeSchema.col('jobId').eq(jobSchema.col('id'));202 const result1 = evalFn.call(203 joinPredicate,204 employeeRelation,205 jobRelation,206 false207 );208 const result2 = evalFn.call(209 joinPredicate,210 jobRelation,211 employeeRelation,212 false213 );214 assert.equal(1, result1.entries.length);215 assert.equal(1, result2.entries.length);216 assert.equal(217 sampleEmployee.payload()['id'],218 result1.entries[0].getField(employeeSchema.col('id'))219 );220 assert.equal(221 sampleEmployee.payload()['id'],222 result2.entries[0].getField(employeeSchema.col('id'))223 );224 assert.equal(225 sampleJob.payload()['id'],226 result1.entries[0].getField(jobSchema.col('id'))227 );228 assert.equal(229 sampleJob.payload()['id'],230 result2.entries[0].getField(jobSchema.col('id'))231 );232 }233 it('joinPredicate_RelationsInputOrder', () => {234 checkJoinPredicate_RelationsInputOrder(235 e,236 j,237 JoinPredicate.prototype.evalRelationsNestedLoopJoin238 );239 checkJoinPredicate_RelationsInputOrder(240 e,241 j,242 JoinPredicate.prototype.evalRelationsHashJoin243 );244 });245 it('joinPredicate_RelationOrder_Alias', () => {246 const eAlias = e.as('employeeAlias') as BaseTable;247 const jAlias = j.as('jobAlias') as BaseTable;248 checkJoinPredicate_RelationsInputOrder(249 eAlias,250 jAlias,251 JoinPredicate.prototype.evalRelationsNestedLoopJoin252 );253 checkJoinPredicate_RelationsInputOrder(254 eAlias,255 jAlias,256 JoinPredicate.prototype.evalRelationsHashJoin257 );258 });259 it('joinPredicate_EvalRelations_HashJoin', () => {260 checkEvalRelations_UniqueKeys(261 JoinPredicate.prototype.evalRelationsHashJoin262 );263 checkEvalRelations_NonUniqueKeys(264 JoinPredicate.prototype.evalRelationsHashJoin265 );266 checkEvalRelations_NullableKeys(267 JoinPredicate.prototype.evalRelationsHashJoin268 );269 });270 it('joinPredicate_EvalRelations_NestedLoopJoin', () => {271 checkEvalRelations_UniqueKeys(272 JoinPredicate.prototype.evalRelationsNestedLoopJoin273 );274 checkEvalRelations_NonUniqueKeys(275 JoinPredicate.prototype.evalRelationsNestedLoopJoin276 );277 checkEvalRelations_NullableKeys(278 JoinPredicate.prototype.evalRelationsNestedLoopJoin279 );280 });281 it('joinPredicate_EvalRelations_OuterJoin_HashJoin', () => {282 checkEvalRelations_OuterJoin_UniqueKeys(283 JoinPredicate.prototype.evalRelationsHashJoin284 );285 checkEvalRelations_OuterJoin_NonUniqueKeys(286 JoinPredicate.prototype.evalRelationsHashJoin287 );288 checkEvalRelations_TwoOuterJoins(289 JoinPredicate.prototype.evalRelationsHashJoin290 );291 checkEvalRelations_OuterInnerJoins(292 JoinPredicate.prototype.evalRelationsHashJoin293 );294 checkEvalRelations_OuterJoin_NullableKeys(295 JoinPredicate.prototype.evalRelationsHashJoin296 );297 });298 it('joinPredicate_EvalRelations_OuterJoin_NestedLoopJoin', () => {299 checkEvalRelations_OuterJoin_UniqueKeys(300 JoinPredicate.prototype.evalRelationsNestedLoopJoin301 );302 checkEvalRelations_OuterJoin_NonUniqueKeys(303 JoinPredicate.prototype.evalRelationsNestedLoopJoin304 );305 checkEvalRelations_TwoOuterJoins(306 JoinPredicate.prototype.evalRelationsNestedLoopJoin307 );308 checkEvalRelations_OuterInnerJoins(309 JoinPredicate.prototype.evalRelationsNestedLoopJoin310 );311 checkEvalRelations_OuterJoin_NullableKeys(312 JoinPredicate.prototype.evalRelationsNestedLoopJoin313 );314 });315 it('joinPredicate_EvalRelations_NestedLoopJoin_MultiJoin', () => {316 checkEvalRelations_MultiJoin(317 JoinPredicate.prototype.evalRelationsNestedLoopJoin318 );319 });320 it('joinPredicate_EvalRelations_HashJoin_MultiJoin', () => {321 checkEvalRelations_MultiJoin(JoinPredicate.prototype.evalRelationsHashJoin);322 });323 // Checks that the given join implementation is correct, for the case where324 // the join predicate refers to unique keys.325 // |evalFn| is the join implementation method, should be either326 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.327 function checkEvalRelations_UniqueKeys(328 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation329 ): void {330 const sampleRows = getSampleRows();331 const employeeRelation = Relation.fromRows(sampleRows.employees, [332 e.getName(),333 ]);334 const jobRelation = Relation.fromRows(sampleRows.jobs, [j.getName()]);335 const joinPredicate1 = e.col('jobId').eq(j.col('id'));336 let result: Relation = evalFn.call(337 joinPredicate1,338 employeeRelation,339 jobRelation,340 false341 );342 assert.equal(sampleRows.employees.length, result.entries.length);343 // Expecting only 5 result entries, since there are only 5 employees that344 // have the same ID with a job.345 const joinPredicate2 = e.col('id').eq(j.col('id'));346 result = evalFn.call(joinPredicate2, employeeRelation, jobRelation, false);347 assert.equal(sampleRows.jobs.length, result.entries.length);348 }349 // Checks that the given join implementation is correct, for the case where350 // the join predicate refers to nullable keys.351 // |evalFn| is the join implementation method, should be either352 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.353 function checkEvalRelations_NullableKeys(354 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation355 ): void {356 const tableA = schemaWithNullable.table('TableA') as BaseTable;357 const tableB = schemaWithNullable.table('TableB');358 const tableC = schemaWithNullable.table('TableC') as BaseTable;359 const tableARelation = Relation.fromRows(360 nullableGenerator.sampleTableARows,361 [tableA.getName()]362 );363 const tableBRelation = Relation.fromRows(364 nullableGenerator.sampleTableBRows,365 [tableB.getName()]366 );367 const tableCRelation = Relation.fromRows(368 nullableGenerator.sampleTableCRows,369 [tableC.getName()]370 );371 const joinPredicate1 = tableA.col('id').eq(tableC.col('id'));372 let result: Relation = evalFn.call(373 joinPredicate1,374 tableARelation,375 tableCRelation,376 false377 );378 assert.equal(379 nullableGenerator.sampleTableARows.length -380 nullableGenerator.tableAGroundTruth.numNullable,381 result.entries.length382 );383 result.entries.forEach(entry => {384 assert.isTrue(hasNonNullEntry(entry, tableA.getEffectiveName()));385 assert.isFalse(hasNullEntry(entry, tableC.getEffectiveName()));386 });387 // Join with left table containing only nulls.388 const joinPredicate2 = tableB.col('id').eq(tableC.col('id'));389 result = evalFn.call(joinPredicate2, tableBRelation, tableCRelation, false);390 assert.equal(0, result.entries.length);391 }392 // Checks that the given outer join implementation is correct, for the case393 // where the join predicate refers to nullable keys.394 // |evalFn| is the join implementation method, should be either395 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.396 function checkEvalRelations_OuterJoin_NullableKeys(397 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation398 ): void {399 const tableA = schemaWithNullable.table('TableA') as BaseTable;400 const tableB = schemaWithNullable.table('TableB') as BaseTable;401 const tableC = schemaWithNullable.table('TableC') as BaseTable;402 const tableARelation = Relation.fromRows(403 nullableGenerator.sampleTableARows,404 [tableA.getName()]405 );406 const tableBRelation = Relation.fromRows(407 nullableGenerator.sampleTableBRows,408 [tableB.getName()]409 );410 const tableCRelation = Relation.fromRows(411 nullableGenerator.sampleTableCRows,412 [tableC.getName()]413 );414 const lengthTableA = nullableGenerator.sampleTableARows.length;415 const numNullableTableA = nullableGenerator.tableAGroundTruth.numNullable;416 const joinPredicate1 = tableA.col('id').eq(tableC.col('id'));417 let result: Relation = evalFn.call(418 joinPredicate1,419 tableARelation,420 tableCRelation,421 true422 );423 assert.equal(lengthTableA, result.entries.length);424 result.entries.slice(0, lengthTableA - numNullableTableA).forEach(entry => {425 assert.isTrue(hasNonNullEntry(entry, tableA.getEffectiveName()));426 });427 result.entries.slice(lengthTableA - numNullableTableA).forEach(entry => {428 assert.isTrue(hasNullEntry(entry, tableA.getEffectiveName()));429 });430 let numNullEntries = result.entries.filter(entry => {431 return hasNullEntry(entry, tableC.getEffectiveName());432 }).length;433 assert.equal(numNullableTableA, numNullEntries);434 // Join with left table containing only nulls.435 const joinPredicate2 = tableB.col('id').eq(tableC.col('id'));436 result = evalFn.call(joinPredicate2, tableBRelation, tableCRelation, true);437 assert.equal(438 nullableGenerator.sampleTableBRows.length,439 result.entries.length440 );441 numNullEntries = result.entries.filter(entry => {442 return (443 hasNullEntry(entry, tableC.getEffectiveName()) &&444 hasNullEntry(entry, tableB.getEffectiveName())445 );446 }).length;447 assert.equal(nullableGenerator.sampleTableBRows.length, numNullEntries);448 }449 // Checks that the given combined entry has a null entry for table450 // 'tableName'.451 function hasNullEntry(entry: RelationEntry, tableName: string): boolean {452 const keys = Object.keys(entry.row.payload()[tableName] as object);453 assert.isTrue(keys.length > 0);454 return Object.keys(entry.row.payload()[tableName] as object).every(key => {455 return (entry.row.payload()[tableName] as PayloadType)[key] === null;456 });457 }458 // Checks that the given combined entry has a non-null entry for table459 // 'tableName'.460 function hasNonNullEntry(entry: RelationEntry, tableName: string): boolean {461 const payload = entry.row.payload()[tableName] as PayloadType;462 const keys = Object.keys(payload);463 assert.isTrue(keys.length > 0);464 return Object.keys(payload).every(key => payload[key] !== null);465 }466 // Checks that the given outer join implementation is correct for the case,467 // where the join predicate refers to unique keys.468 // |evalFn| is the join implementation method, should be either469 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.470 function checkEvalRelations_OuterJoin_UniqueKeys(471 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation472 ): void {473 const sampleRows = getSampleRows();474 // Remove the last job row.475 const lessJobs = sampleRows.jobs.slice(0, sampleRows.jobs.length - 1);476 const employeeRelation = Relation.fromRows(sampleRows.employees, [477 e.getName(),478 ]);479 const jobRelation = Relation.fromRows(lessJobs, [j.getName()]);480 // For every Job , there are 10 employees according to getSampleRows().481 const numEmployeesPerJob = 10;482 const joinPredicate1 = e.col('jobId').eq(j.col('id'));483 const result: Relation = evalFn.call(484 joinPredicate1,485 employeeRelation,486 jobRelation,487 true488 );489 assert.equal(sampleRows.employees.length, result.entries.length);490 const numNullEntries = result.entries.filter(entry =>491 hasNullEntry(entry, 'Job')492 ).length;493 assert.equal(numEmployeesPerJob, numNullEntries);494 }495 // Checks that the given outer join implementation is correct for two496 // Outer joins, for the case where the join predicate refers to unique keys.497 // |evalFn| is the join implementation method, should be either498 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.499 function checkEvalRelations_TwoOuterJoins(500 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation501 ): void {502 const sampleRows = getSampleRows();503 const numJobsDeleted = 1;504 const numDepartmentsDeleted = 2;505 // Remove the last job row.506 const lessJobs = sampleRows.jobs.slice(507 0,508 sampleRows.jobs.length - numJobsDeleted509 );510 // Remove the last 2 rows in Departments.511 const lessDepartments = sampleRows.departments.slice(512 0,513 sampleRows.departments.length - numDepartmentsDeleted514 );515 const employeeRelation = Relation.fromRows(sampleRows.employees, [516 e.getName(),517 ]);518 const jobRelation = Relation.fromRows(lessJobs, [j.getName()]);519 const departmentRelation = Relation.fromRows(lessDepartments, [520 d.getName(),521 ]);522 let joinPredicate1 = e.col('jobId').eq(j.col('id'));523 let joinPredicate2 = e.col('departmentId').eq(d.col('id'));524 const numEmployeesPerJob = 10;525 const numEmployeesPerDepartment = 20;526 const expectedResults =527 sampleRows.employees.length - numJobsDeleted * numEmployeesPerJob;528 const expectedResults2 =529 sampleRows.employees.length -530 numDepartmentsDeleted * numEmployeesPerDepartment;531 // Tests inner join followed by outer join.532 let result: Relation = evalFn.call(533 joinPredicate1,534 employeeRelation,535 jobRelation,536 false537 );538 assert.equal(expectedResults, result.entries.length);539 let result2: Relation = evalFn.call(540 joinPredicate2,541 result,542 departmentRelation,543 true544 );545 // Join employee and job with department.546 assert.equal(expectedResults, result2.entries.length);547 // joinPredicate1 is reversed in previous join.548 joinPredicate1 = e.col('jobId').eq(j.col('id'));549 // Tests outer join followed by inner join.550 result = evalFn.call(joinPredicate1, employeeRelation, jobRelation, true);551 assert.equal(sampleRows.employees.length, result.entries.length);552 result2 = evalFn.call(joinPredicate2, result, departmentRelation, false);553 // Join employee and job with department554 assert.equal(expectedResults2, result2.entries.length);555 // joinPredicate2 is reversed in previous join.556 joinPredicate2 = e.col('departmentId').eq(d.col('id'));557 // Tests outer join followed by outer join.558 result = evalFn.call(joinPredicate1, employeeRelation, jobRelation, true);559 assert.equal(sampleRows.employees.length, result.entries.length);560 result2 = evalFn.call(joinPredicate2, result, departmentRelation, true);561 assert.equal(sampleRows.employees.length, result2.entries.length);562 }563 // Checks that the given outer join implementation is correct564 // for two Outer joins, for the case where the join predicate565 // refers to unique keys.566 // |evalFn| is the join implementation method, should be either567 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.568 function checkEvalRelations_OuterInnerJoins(569 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation570 ): void {571 const sampleRows = getSampleRows();572 const lessJobs = sampleRows.jobs.slice(0, sampleRows.jobs.length - 1);573 const lessDepartments = sampleRows.departments.slice(574 0,575 sampleRows.departments.length - 1576 );577 const numJobsDeleted = 1;578 const numDepartmentsDeleted = 1;579 const numEmployeesPerJob = 10;580 const numEmployeesPerDepartment = 20;581 const employeeRelation = Relation.fromRows(sampleRows.employees, [582 e.getName(),583 ]);584 const jobRelation = Relation.fromRows(lessJobs, [j.getName()]);585 const departmentRelation = Relation.fromRows(lessDepartments, [586 d.getName(),587 ]);588 let joinPredicate1 = e.col('jobId').eq(j.col('id'));589 let result: Relation = evalFn.call(590 joinPredicate1,591 employeeRelation,592 jobRelation,593 false594 );595 const expectedResults =596 sampleRows.employees.length - numJobsDeleted * numEmployeesPerJob;597 const expectedResults2 =598 sampleRows.employees.length -599 numDepartmentsDeleted * numEmployeesPerDepartment;600 assert.equal(expectedResults, result.entries.length);601 // joinPredicate1 is reversed in previous join.602 joinPredicate1 = e.col('jobId').eq(j.col('id'));603 result = evalFn.call(joinPredicate1, employeeRelation, jobRelation, true);604 assert.equal(sampleRows.employees.length, result.entries.length);605 // Join employee and job with department.606 const joinPredicate2 = e.col('departmentId').eq(d.col('id'));607 let result2: Relation = evalFn.call(608 joinPredicate2,609 result,610 departmentRelation,611 true612 );613 assert.equal(sampleRows.employees.length, result2.entries.length);614 result2 = evalFn.call(joinPredicate2, result, departmentRelation, false);615 assert.equal(expectedResults2, result2.entries.length);616 }617 // Checks that the given join implementation is correct, for the case where618 // the join predicate refers to non-unique keys.619 // |evalFn| is the join implementation method, should be either620 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.621 function checkEvalRelations_NonUniqueKeys(622 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation623 ): void {624 const sampleRows = getSampleRows();625 const employeeRelation = Relation.fromRows(sampleRows.employees, [626 e.getName(),627 ]);628 const jobRelation = Relation.fromRows(sampleRows.jobs, [j.getName()]);629 const joinPredicate1 = e.col('salary').eq(j.col('minSalary'));630 const result: Relation = evalFn.call(631 joinPredicate1,632 employeeRelation,633 jobRelation,634 false635 );636 assert.equal(637 sampleRows.employees.length * sampleRows.jobs.length,638 result.entries.length639 );640 }641 // Checks that the given join implementation is correct, for the case where642 // the join predicate refers to non-unique keys.643 // |evalFn| is the join implementation method, should be either644 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.645 function checkEvalRelations_OuterJoin_NonUniqueKeys(646 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation647 ): void {648 const sampleRows = getSampleRows();649 const lessJobs = sampleRows.jobs.slice(0, sampleRows.jobs.length - 1);650 sampleRows.employees[sampleRows.employees.length - 1].payload()[651 'salary'652 ] = 1;653 const employeeRelation = Relation.fromRows(sampleRows.employees, [654 e.getName(),655 ]);656 const jobRelation = Relation.fromRows(lessJobs, [j.getName()]);657 const numEmployeesChanged = 1;658 const joinPredicate1 = e.col('salary').eq(j.col('minSalary'));659 const result: Relation = evalFn.call(660 joinPredicate1,661 employeeRelation,662 jobRelation,663 true664 );665 assert.equal(666 (sampleRows.employees.length - numEmployeesChanged) * lessJobs.length +667 numEmployeesChanged,668 result.entries.length669 );670 let numNullEntries = 0;671 result.entries.forEach(entry => {672 if (hasNullEntry(entry, 'Job')) {673 numNullEntries++;674 }675 });676 assert.equal(numEmployeesChanged, numNullEntries);677 }678 // Checks that the given join implementation is correct, for the case where679 // a 3 table natural join is performed.680 // |evalFn| is the join implementation method, should be either681 // evalRelationsNestedLoopJoin or evalRelationsHashJoin.682 function checkEvalRelations_MultiJoin(683 evalFn: (r1: Relation, r2: Relation, outer: boolean) => Relation684 ): void {685 const sampleRows = getSampleRows();686 const employeeRelation = Relation.fromRows(sampleRows.employees, [687 e.getName(),688 ]);689 const jobRelation = Relation.fromRows(sampleRows.jobs, [j.getName()]);690 const departmentRelation = Relation.fromRows(sampleRows.departments, [691 d.getName(),692 ]);693 const joinPredicate1 = e.col('jobId').eq(j.col('id'));694 const joinPredicate2 = e.col('departmentId').eq(d.col('id'));695 const resultEmployeeJob: Relation = evalFn.call(696 joinPredicate1,697 employeeRelation,698 jobRelation,699 false700 );701 const resultEmployeeJobDepartment: Relation = evalFn.call(702 joinPredicate2,703 resultEmployeeJob,704 departmentRelation,705 false706 );707 assert.equal(708 sampleRows.employees.length,709 resultEmployeeJobDepartment.entries.length710 );711 }712 // Generates sample data to be used for tests. Specifically it generates713 // - 60 employees,714 // - 6 jobs,715 // - 3 departments716 // Such that each job contains 10 employees and each department contains 20717 // employees.718 function getSampleRows(): SampleDataType {719 const employeeCount = 60;720 const jobCount = employeeCount / 10;721 const departmentCount = employeeCount / 20;722 const salary = 100000;723 const employees = new Array(employeeCount);724 for (let i = 0; i < employeeCount; i++) {725 const employee = HRSchemaSampleData.generateSampleEmployeeData();726 employee.payload()['id'] = i.toString();727 employee.payload()['jobId'] = String(i % jobCount);728 employee.payload()['departmentId'] = `departmentId${String(729 i % departmentCount730 )}`;731 employee.payload()['salary'] = salary;732 employees[i] = employee;733 }734 const jobs = new Array(jobCount);735 for (let i = 0; i < jobCount; i++) {736 const job = HRSchemaSampleData.generateSampleJobData();737 job.payload()['id'] = i.toString();738 job.payload()['minSalary'] = salary;739 jobs[i] = job;740 }741 const departments = new Array(departmentCount);742 for (let i = 0; i < departmentCount; i++) {743 const department = HRSchemaSampleData.generateSampleDepartmentData();744 department.payload()['id'] = `departmentId${String(i)}`;745 departments[i] = department;746 }747 return {748 departments,749 employees,750 jobs,751 };752 }...

Full Screen

Full Screen

evaluateAstNode.ts

Source:evaluateAstNode.ts Github

copy

Full Screen

...99 throw new Error(100 'evaluateAstNode does not support non-literal values unless an eval function is provided',101 )102 }103 return evalFn(exprNode)...

Full Screen

Full Screen

DoublyLinkedList.ts

Source:DoublyLinkedList.ts Github

copy

Full Screen

...33 }34 find(evalFn: EvalFn<T>): DoublyLinkedListNode<T> | null {35 let node = this.head;36 while(node){37 if(evalFn(node.value)) return node;38 node = node.next;39 }40 return null;41 }42 delete(evalFn: EvalFn<T>): DoublyLinkedListNode<T> | null {43 if(!this.head) return null;44 if(evalFn(this.head.value)){45 const node = this.head;46 if(!this.head.next){47 this.head = null;48 this.tail = null;49 } else {50 this.head = this.head.next;51 this.head.previous = null;52 }53 return node;54 }55 if(this.tail && evalFn(this.tail.value)){56 const node = this.tail;57 this.tail = this.tail.previous;58 if(this.tail) this.tail.next = null;59 return node;60 }61 const node = this.find(evalFn);62 if(!node)return null;63 if(node.previous) node.previous.next = node.next;64 if(node.next) node.next.previous = node.previous;65 return node;66 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const evalFn = require('stryker-parent').evalFn;2evalFn(function () {3 console.log('Hello world');4});5module.exports = function (config) {6 config.set({7 custom: {8 config: {9 }10 }11 });12};13const { NodeTestRunner } = require('stryker-javascript-mutator');14const { NodeMutator } = require('stryker-javascript-mutator');15const { NodeTranspiler } = require('stryker-javascript-mutator');16const { NodeMutatorFacade } = require('stryker-javascript-mutator');17const { NodeTranspilerFacade } = require('stryker-javascript-mutator');18const { NodeMutatorFactory } = require('stryker-javascript-mutator');19const { NodeTranspilerFactory } = require('stryker-javascript-mutator');20const { NodeOptionsEditor } = require('stryker-javascript-mutator');21const { NodeOptionsEditorFactory } = require('stryker-javascript-mutator');22const { NodeOptionsEditorFacade } = require('stryker-javascript-mutator');23const { NodeOptions } = require('stryker-javascript-mutator');24module.exports = class CustomTestRunner extends NodeTestRunner {25 constructor(options) {26 super(options);27 }28 async init() {29 await super.init();30 this.log.info('CustomTestRunner was initialized');31 }32 async run(options) {33 this.log.info('CustomTestRunner was run');34 return await super.run(options);35 }36};

Full Screen

Using AI Code Generation

copy

Full Screen

1var evalFn = require('stryker-parent').evalFn;2var evalFn = require('stryker-parent').evalFn;3var evalFn = require('stryker-parent').evalFn;4var evalFn = require('stryker-parent').evalFn;5var evalFn = require('stryker-parent').evalFn;6var evalFn = require('stryker-parent').evalFn;7var evalFn = require('stryker-parent').evalFn;8var evalFn = require('stryker-parent').evalFn;9var evalFn = require('stryker-parent').evalFn;10var evalFn = require('stryker-parent').evalFn;11var evalFn = require('stryker-parent').evalFn;12evalFn('return 1

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var strykerEval = stryker.evalFn;3var strykerMutant = stryker.mutant;4var strykerMutantId = stryker.mutantId;5var strykerMutantIndex = stryker.mutantIndex;6var strykerMutantCount = stryker.mutantCount;7var strykerMutantFilename = stryker.mutantFilename;8var strykerMutantLine = stryker.mutantLine;9var strykerMutantColumn = stryker.mutantColumn;10var strykerMutantEndLine = stryker.mutantEndLine;11var strykerMutantEndColumn = stryker.mutantEndColumn;12var strykerMutantMutator = stryker.mutantMutator;13var strykerMutantSource = stryker.mutantSource;14var strykerMutantId = stryker.mutantId;15var strykerMutantIndex = stryker.mutantIndex;16var strykerMutantCount = stryker.mutantCount;17var strykerMutantFilename = stryker.mutantFilename;18var strykerMutantLine = stryker.mutantLine;19var strykerMutantColumn = stryker.mutantColumn;20var strykerMutantEndLine = stryker.mutantEndLine;21var strykerMutantEndColumn = stryker.mutantEndColumn;22var strykerMutantMutator = stryker.mutantMutator;23var strykerMutantSource = stryker.mutantSource;24var strykerMutantId = stryker.mutantId;25var strykerMutantIndex = stryker.mutantIndex;26var strykerMutantCount = stryker.mutantCount;27var strykerMutantFilename = stryker.mutantFilename;28var strykerMutantLine = stryker.mutantLine;29var strykerMutantColumn = stryker.mutantColumn;30var strykerMutantEndLine = stryker.mutantEndLine;

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var codeToEvaluate = "var x = 1 + 2; return x;";3strykerParent.evalFn(codeToEvaluate, function (err, result) {4 if (err) {5 console.error(err);6 } else {7 console.log(result);8 }9});10var strykerParent = require('stryker-parent');11var codeToEvaluate = "var x = 1 + 2; return x;";12strykerParent.evalFn(codeToEvaluate, function (err, result) {13 if (err) {14 console.error(err);15 } else {16 console.log(result);17 }18});19### evalFn(codeToEvaluate, callback)

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 stryker-parent 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