# How to use withSolution method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

luDisplay.js

Source:luDisplay.js

1import {printEquations} from '../displaySolutions/generalFunctions.js';2import { printFinalAnswer } from "./generalFunctions.js";3import { numberOfEquations } from "../app.js"4import { parameters } from "./find.js";5const solutionArea = document.getElementById("solution");6//cholesky7function printCholeskySolutionStatus(solution){8 const isSymmetricMatrix = solution.symmetric;9 const isPositiveDefinite = solution.canBeSolved;10 const isCholeskyPossible = isSymmetricMatrix && isPositiveDefinite;11 const symmetricStr = isSymmetricMatrix ? 'symmetric': 'not symmetric';12 const posDefStr = isPositiveDefinite ? 'positive definite': 'not positive definite';13 const possibleStr = isCholeskyPossible ? 'possible': 'not possible';14 const solutionStatusContainer = document.createElement('div');15 solutionStatusContainer.className = "answers-dispaly";16 const info = document.createElement('div');17 info.className = "single-step";18 info.innerHTML = $$\\text{Cholesky decomposition :} A=Lâ L^T, 19 \\text{Every symmetric positive definite matrix A can be decomposed into a product of a unique lower triangular matrix L and its transpose.}$$;20 solutionStatusContainer.appendChild(info);21 const solutionStatus = document.createElement('div');22 solutionStatus.className = "single-step";23 solutionStatus.style.display = "flex";24 solutionStatus.style.justifyContent = "flex-start";25 26 solutionStatus.innerHTML = $$\\text{Here A is {symmetricStr} and {posDefStr} so Cholesky decomposition is {possibleStr}}$$;27 solutionStatusContainer.appendChild(solutionStatus);28 solutionArea.appendChild(solutionStatusContainer);29 return isCholeskyPossible;30}31function printCholeskyEquations(solution){32 const stepsLabel = document.createElement('div');33 stepsLabel.className = "solutions-label";34 stepsLabel.innerHTML = "$$\\underline{Steps:}$$";35 solutionArea.appendChild(stepsLabel);36 const steps = solution.steps;37 const numberOfSteps = steps.length;38 const allStepsContainer = document.createElement('div');39 allStepsContainer.className = "steps-display";40 for(let step = 0; step < numberOfSteps; step++){41 const currentStep = steps[step];42 const discreption = currentStep.discreption;43 const matrix = currentStep.L;44 const stepContaineer = document.createElement('div');45 stepContaineer.className = "step-container";46 const discreptionContainer = document.createElement('div');47 discreptionContainer.innerHTML = ${discreption};48 discreptionContainer.className = "single-step";49 stepContaineer.appendChild(discreptionContainer);50 allStepsContainer.appendChild(stepContaineer);51 }52 solutionArea.appendChild(allStepsContainer);53}54function printMatrix(solution){55 const container = document.createElement('div');56 container.className = "steps-display";57 58 const lMatrix = solution.LU.l_matrix;59 const lMatrixContainer = document.createElement('div');60 lMatrixContainer.className = "single-step";61 lMatrixContainer.innerHTML = $$\\text{then } L=\\begin{bmatrix};62 for(let i = 0; i < numberOfEquations; i++){63 const matrixRow = lMatrix[i];64 for(let j = 0; j < numberOfEquations -1; j++){65 lMatrixContainer.innerHTML += {matrixRow[j]} &;66 }67 lMatrixContainer.innerHTML += {matrixRow[numberOfEquations-1]} \\\\;68 }69 lMatrixContainer.innerHTML += \\end{bmatrix}$$;70 container.appendChild(lMatrixContainer);71 const lTranspose = solution.LU.u_matrix;72 const lTransposeContaier = document.createElement('div');73 lTransposeContaier.className = "single-step";74 lTransposeContaier.innerHTML = $$\\text{then } L^T=\\begin{bmatrix};75 for(let i = 0; i < numberOfEquations; i++){76 const matrixRow = lTranspose[i];77 for(let j = 0; j < numberOfEquations -1; j++){78 lTransposeContaier.innerHTML += {matrixRow[j]} &;79 }80 lTransposeContaier.innerHTML += {matrixRow[numberOfEquations-1]} \\\\;81 }82 lTransposeContaier.innerHTML += \\end{bmatrix}$$;83 container.appendChild(lTransposeContaier);84 const combined = document.createElement('div');85 combined.className = "single-step";86 combined.innerHTML = $$\\text{then } A = \\begin{bmatrix};87 for(let i = 0; i < numberOfEquations; i++){88 const matrixRow = lMatrix[i];89 for(let j = 0; j < numberOfEquations -1; j++){90 combined.innerHTML += {matrixRow[j]} &;91 }92 combined.innerHTML += {matrixRow[numberOfEquations-1]} \\\\;93 }94 combined.innerHTML += \\end{bmatrix}.;95 combined.innerHTML += \\begin{bmatrix};96 for(let i = 0; i < numberOfEquations; i++){97 const matrixRow = lTranspose[i];98 for(let j = 0; j < numberOfEquations -1; j++){99 combined.innerHTML += {matrixRow[j]} &;100 }101 combined.innerHTML += {matrixRow[numberOfEquations-1]} \\\\;102 }103 combined.innerHTML += \\end{bmatrix}$$;104 container.append(combined);105 const discreption = document.createElement('div');106 discreption.className = "single-step";107 discreption.innerHTML = $$\\text{as } Ax = b \\text{then, }$$;108 container.appendChild(discreption);109 const withSolution = document.createElement('div');110 withSolution.className = "single-step";111 withSolution.innerHTML = $$\\begin{bmatrix};112 for(let i = 0; i < numberOfEquations; i++){113 const matrixRow = lMatrix[i];114 for(let j = 0; j < numberOfEquations -1; j++){115 withSolution.innerHTML += {matrixRow[j]} &;116 }117 withSolution.innerHTML += {matrixRow[numberOfEquations-1]} \\\\;118 }119 withSolution.innerHTML += \\end{bmatrix}.;120 withSolution.innerHTML += \\begin{bmatrix};121 for(let i = 0; i < numberOfEquations; i++){122 const matrixRow = lTranspose[i];123 for(let j = 0; j < numberOfEquations -1; j++){124 withSolution.innerHTML += {matrixRow[j]} &;125 }126 withSolution.innerHTML += {matrixRow[numberOfEquations-1]} \\\\;127 }128 withSolution.innerHTML += \\end{bmatrix}.\\begin{bmatrix};129 for(let i = 1; i < numberOfEquations; i++){130 withSolution.innerHTML += x_{i}\\\\;131 }132 withSolution.innerHTML += x_{numberOfEquations}\\end{bmatrix} = \\begin{bmatrix};133 for(let i = 0; i < numberOfEquations-1; i++){134 withSolution.innerHTML += {parameters.matrix[i][numberOfEquations]}\\\\;135 }136 withSolution.innerHTML += {parameters.matrix[numberOfEquations-1][numberOfEquations]}\\end{bmatrix}$$137 container.appendChild(withSolution);138 solutionArea.appendChild(container); 139}140function printForwardHeader(solution, cholesky){141 const label = document.createElement('div');142 label.className = "solutions-label";143 label.innerHTML = "$$\\underline{\\text{Forward elemination:}}$$";144 solutionArea.appendChild(label);145 const container = document.createElement('div');146 container.className = "steps-display";147 let lMatrix = cholesky ? solution.LU.l_matrix: solution.finalAnswer.l_matrix;148 container.innerHTML = $$\\begin{bmatrix};149 for(let i = 0; i < numberOfEquations; i++){150 const matrixRow = lMatrix[i];151 for(let j = 0; j < numberOfEquations -1; j++){152 container.innerHTML += {matrixRow[j]} &;153 }154 container.innerHTML += {matrixRow[numberOfEquations-1]} \\\\;155 }156 container.innerHTML += \\end{bmatrix}\\begin{bmatrix};157 for(let i = 1; i < numberOfEquations; i++){158 container.innerHTML += y_{i}\\\\;159 }160 container.innerHTML += y_{numberOfEquations}\\end{bmatrix} = \\begin{bmatrix};161 for(let i = 0; i < numberOfEquations-1; i++){162 container.innerHTML += {parameters.matrix[i][numberOfEquations]}\\\\;163 }164 container.innerHTML += {parameters.matrix[numberOfEquations-1][numberOfEquations]}\\end{bmatrix}$$165 solutionArea.appendChild(container);166}167function printForwardElem(solution){168 const container = document.createElement('div');169 container.className = "answers-display";170 const forwardSteps = solution.forwardSub;171 const finalAnswer = solution.forwardRsults.reverse();172 for(let i = 0; i < numberOfEquations; i++){173 const currVarIndex = i+1;174 const step = forwardSteps[i];175 const formula = step.formula;176 const subValues = step.subValues;177 let stepStr = $$y_{currVarIndex}=\\frac;178 let numerator = {formula[0]};179 let denominator = {formula[formula.length -1]}180 let varIndex = 1;181 for(let j = 1; j < formula.length -1; j++){182 if(varIndex === currVarIndex) varIndex++;183 const coof = formula[j];184 if(coof == 0) continue;185 else if(coof > 0) numerator += +{coof} y_{varIndex++};186 else numerator += {coof}y_{varIndex++};187 }188 stepStr += {{numerator}}{{denominator}} = \\frac189 numerator = {formula[0]};190 for(let j = 1; j < formula.length -1; j++){191 const coof = formula[j];192 if(coof == 0) continue;193 else if(coof > 0) numerator += +{coof}({subValues[j-1]});194 else numerator += {coof}({subValues[j-1]});195 }196 stepStr += {{numerator}}{{denominator}} = {finalAnswer[numberOfEquations-i-1]}$$;197 const stepContainer = document.createElement('div');198 stepContainer.className = "single-step";199 stepContainer.innerHTML = stepStr;200 container.appendChild(stepContainer);201 }202 solutionArea.appendChild(container);203}204function printBackwardSubHeader(solution, cholesky){205 const label = document.createElement('div');206 label.className = "solutions-label";207 label.innerHTML = "$$\\underline{\\text{Backward substitution:}}$$";208 solutionArea.appendChild(label);209 const container = document.createElement('div');210 container.className = "steps-display";211 const uMatrix = cholesky ? solution.LU.u_matrix: solution.finalAnswer.u_matrix;212 const answers = solution.forwardRsults.reverse();213 container.innerHTML = $$\\begin{bmatrix};214 for(let i = 0; i < numberOfEquations; i++){215 const matrixRow = uMatrix[i];216 for(let j = 0; j < numberOfEquations -1; j++){217 container.innerHTML += {matrixRow[j]} &;218 }219 container.innerHTML += {matrixRow[numberOfEquations-1]} \\\\;220 }221 container.innerHTML += \\end{bmatrix}\\begin{bmatrix};222 for(let i = 1; i < numberOfEquations; i++){223 container.innerHTML += x_{i}\\\\;224 }225 container.innerHTML += x_{numberOfEquations}\\end{bmatrix} = \\begin{bmatrix};226 for(let i = 0; i < numberOfEquations-1; i++){227 container.innerHTML += {answers[i]}\\\\;228 }229 container.innerHTML += {answers[numberOfEquations-1]}\\end{bmatrix}$$230 solutionArea.appendChild(container);231}232function printBackwardSub(solution, cholesky){233 const backwardSubContainer = document.createElement('div');234 backwardSubContainer.className = "answers-display";235 const backSubSteps = solution.backwardSub;236 const finalAnswer = cholesky ? solution.finalAnswer: solution.finalAnswer.answer;237 for(let i = 0; i < numberOfEquations; i++){238 const currVarIndex = numberOfEquations-i;239 const step = backSubSteps[i];240 const formula = step.formula;241 const subValues = step.subValues;242 let stepStr = $$x_{currVarIndex}=\\frac;243 let numerator = {formula[0]};244 let denominator = {formula[formula.length -1]}245 let varIndex = currVarIndex;246 for(let j = 1; j < formula.length -1; j++){247 if(varIndex === currVarIndex) varIndex++;248 const coof = formula[j];249 if(coof == 0) continue;250 else if(coof > 0) numerator += +{coof} x_{varIndex++};251 else numerator += {coof}x_{varIndex++};252 }253 stepStr += {{numerator}}{{denominator}} = \\frac254 numerator = {formula[0]};255 for(let j = 1; j < formula.length -1; j++){256 const coof = formula[j];257 if(coof == 0) continue;258 else if(coof > 0) numerator += +{coof}({subValues[j-1]});259 else numerator += {coof}({subValues[j-1]});260 }261 stepStr += {{numerator}}{{denominator}} = {finalAnswer[numberOfEquations-i-1]}$$;262 const stepContainer = document.createElement('div');263 stepContainer.className = "single-step";264 stepContainer.innerHTML = stepStr;265 backwardSubContainer.appendChild(stepContainer);266 }267 if(backSubSteps.length > numberOfEquations){268 const stepContainer = document.createElement('div');269 stepContainer.className = "single-step";270 stepContainer.innerHTML = $${backSubSteps[backSubSteps.length -1]};271 backwardSubContainer.appendChild(stepContainer);272 }273 solutionArea.appendChild(backwardSubContainer);274}275//lu dolittle276function printLuCanBeFound(solution){277 const luCanBeFound = solution.luCanBeFound;278 const solutionStatus = document.createElement('div');279 solutionStatus.className = "single-step";280 solutionStatus.style.display = "flex";281 solutionStatus.style.justifyContent = "flex-start";282 283 if(!luCanBeFound) solutionStatus.innerHTML = $$\\text{The LU decomposition of A cannot be found}$$;284 else solutionStatus.innerHTML = $$\\text{The LU decomposition of A can be found}$$;285 solutionArea.appendChild(solutionStatus);286 console.log("in")287 return luCanBeFound;288}289function printLuFinalAnswer(solution){290 const finalAnswerLabel = document.createElement('div');291 finalAnswerLabel.className = "solutions-label";292 finalAnswerLabel.innerHTML = "$$\\underline{\\text{Final answer:}}$$";293 solutionArea.appendChild(finalAnswerLabel);294 const finalAnswer = solution.finalAnswer.answer;295 const finalAnswerContainer = document.createElement('div');296 finalAnswerContainer.className = "answers-display";297 for(let i = 0; i < numberOfEquations; i++){298 const singleAnswer = document.createElement('div');299 singleAnswer.innerHTML = $$x_${i+1}=${finalAnswer[i]}$$;300 singleAnswer.className = "single-step";301 finalAnswerContainer.appendChild(singleAnswer);302 }303 solutionArea.appendChild(finalAnswerContainer);304}305function printLUSteps(solution, crout){306 const label = document.createElement('div');307 label.className = "solutions-label";308 label.innerHTML = "$$\\underline{Steps:}$$";309 solutionArea.appendChild(label);310 const steps = solution.steps;311 const numberOfSteps = steps.length;312 const allStepsContainer = document.createElement('div');313 allStepsContainer.className = "steps-display";314 let lMatrix = [];315 let uMatrix = [];316 for(let step = 0; step < numberOfSteps; step++){317 const currentStep = steps[step];318 319 const discreption = currentStep.descripton;320 if(!crout){321 lMatrix = currentStep.l_matrix;322 uMatrix = currentStep.u_matrix;323 }324 else{325 lMatrix = currentStep.u_matrix;326 uMatrix = currentStep.l_matrix;327 }328 const stepContaineer = document.createElement('div');329 stepContaineer.className = "step-container";330 const discreptionContainer = document.createElement('div');331 discreptionContainer.innerHTML = $${discreption}$;332 discreptionContainer.className = "single-step";333 stepContaineer.appendChild(discreptionContainer);334 const uMatrixContainer = document.createElement('div');335 uMatrixContainer.className = "single-step";336 337 if(!crout) uMatrixContainer.innerHTML = $$U = \\begin{bmatrix};338 else uMatrixContainer.innerHTML = $$L = \\begin{bmatrix};339 for(let i = 0; i < numberOfEquations; i++){340 const matrixRow = uMatrix[i];341 for(let j = 0; j < numberOfEquations -1; j++){342 uMatrixContainer.innerHTML += ${matrixRow[j]} &;343 }344 uMatrixContainer.innerHTML += ${matrixRow[numberOfEquations -1]} \\\\;345 }346 uMatrixContainer.innerHTML += \\end{bmatrix}$$;347 stepContaineer.appendChild(uMatrixContainer);348 if(lMatrix.length === 3){349 const lMatrixContainer = document.createElement('div');350 lMatrixContainer.className = "single-step";351 if(!crout) lMatrixContainer.innerHTML = $$l_{${lMatrix[0]}${lMatrix[1]}} = ${lMatrix[2]}$$;352 else lMatrixContainer.innerHTML = $$u_{${lMatrix[0]}${lMatrix[1]}} =${lMatrix[2]}$$;353 stepContaineer.appendChild(lMatrixContainer);354 allStepsContainer.appendChild(stepContaineer);355 }356 allStepsContainer.appendChild(stepContaineer);357 }358 solutionArea.appendChild(allStepsContainer);359}360function printLUMatrix(solution){361 const container = document.createElement('div');362 container.className = "steps-display";363 364 const lMatrix = solution.finalAnswer.l_matrix;365 const lMatrixContainer = document.createElement('div');366 lMatrixContainer.className = "single-step";367 lMatrixContainer.innerHTML = $$\\text{then } L=\\begin{bmatrix};368 for(let i = 0; i < numberOfEquations; i++){369 const matrixRow = lMatrix[i];370 for(let j = 0; j < numberOfEquations -1; j++){371 lMatrixContainer.innerHTML += ${matrixRow[j]} &;372 }373 lMatrixContainer.innerHTML += ${matrixRow[numberOfEquations-1]} \\\\;374 }375 lMatrixContainer.innerHTML += \\end{bmatrix}$$;376 container.appendChild(lMatrixContainer);377 const uMatrix = solution.finalAnswer.u_matrix;378 const uMatrixContainer = document.createElement('div');379 uMatrixContainer.className = "single-step";380 uMatrixContainer.innerHTML = $$\\text{then } U=\\begin{bmatrix};381 for(let i = 0; i < numberOfEquations; i++){382 const matrixRow = uMatrix[i];383 for(let j = 0; j < numberOfEquations -1; j++){384 uMatrixContainer.innerHTML += ${matrixRow[j]} &;385 }386 uMatrixContainer.innerHTML += ${matrixRow[numberOfEquations-1]} \\\\;387 }388 uMatrixContainer.innerHTML += \\end{bmatrix}$$;389 container.appendChild(uMatrixContainer);390 const combined = document.createElement('div');391 combined.className = "single-step";392 combined.innerHTML = $$\\text{then } A = L.U = \\begin{bmatrix};393 for(let i = 0; i < numberOfEquations; i++){394 const matrixRow = lMatrix[i];395 for(let j = 0; j < numberOfEquations -1; j++){396 combined.innerHTML += ${matrixRow[j]} &;397 }398 combined.innerHTML += ${matrixRow[numberOfEquations-1]} \\\\;399 }400 combined.innerHTML += \\end{bmatrix}.;401 combined.innerHTML += \\begin{bmatrix};402 for(let i = 0; i < numberOfEquations; i++){403 const matrixRow = uMatrix[i];404 for(let j = 0; j < numberOfEquations -1; j++){405 combined.innerHTML += ${matrixRow[j]} &;406 }407 combined.innerHTML += ${matrixRow[numberOfEquations-1]} \\\\;408 }409 combined.innerHTML += \\end{bmatrix}$$;410 container.append(combined);411 const discreption = document.createElement('div');412 discreption.className = "single-step";413 discreption.innerHTML = $$\\text{as } Ax = b \\text{then, }$$;414 container.appendChild(discreption);415 const withSolution = document.createElement('div');416 withSolution.className = "single-step";417 withSolution.innerHTML = $$\\begin{bmatrix};418 for(let i = 0; i < numberOfEquations; i++){419 const matrixRow = lMatrix[i];420 for(let j = 0; j < numberOfEquations -1; j++){421 withSolution.innerHTML += ${matrixRow[j]} &;422 }423 withSolution.innerHTML += ${matrixRow[numberOfEquations-1]} \\\\;424 }425 withSolution.innerHTML += \\end{bmatrix}.;426 withSolution.innerHTML += \\begin{bmatrix};427 for(let i = 0; i < numberOfEquations; i++){428 const matrixRow = uMatrix[i];429 for(let j = 0; j < numberOfEquations -1; j++){430 withSolution.innerHTML += ${matrixRow[j]} &;431 }432 withSolution.innerHTML += ${matrixRow[numberOfEquations-1]} \\\\;433 }434 withSolution.innerHTML += \\end{bmatrix}.\\begin{bmatrix};435 for(let i = 1; i < numberOfEquations; i++){436 withSolution.innerHTML += x_${i}\\\\;437 }438 withSolution.innerHTML += x_${numberOfEquations}\\end{bmatrix} = \\begin{bmatrix};439 for(let i = 0; i < numberOfEquations-1; i++){440 withSolution.innerHTML += ${parameters.matrix[i][numberOfEquations]}\\\\;441 }442 withSolution.innerHTML += ${parameters.matrix[numberOfEquations-1][numberOfEquations]}\\end{bmatrix}$$443 container.appendChild(withSolution);444 solutionArea.appendChild(container); 445}446function printNonSolvableMsg(){447 const message = document.createElement('div');448 message.innerHTML = "$$\\text{this System of linear equations cannot be solved}"449 solutionArea.appendChild(message);450}451export function displayLUSolution(solution, luType){452 printEquations();453 if(luType == 3) {454 printCholesky(solution);455 }456 else if(luType == 1){457 printDolittle(solution);458 }459 else if(luType == 2){460 printCrout(solution);461 }462 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);463}464function printCholesky(solution){465 const showSteps = printCholeskySolutionStatus(solution);466 if(!showSteps) return;467 printFinalAnswer(solution);468 printCholeskyEquations(solution);469 printMatrix(solution);470 printForwardHeader(solution, true);471 printForwardElem(solution);472 printBackwardSubHeader(solution, true);473 printBackwardSub(solution, true);474}475function printDolittle(solution){476 const luCanBeFound = printLuCanBeFound(solution);477 if(!luCanBeFound) return;478 printLuFinalAnswer(solution);479 printLUSteps(solution, false);480 printLUMatrix(solution);481 if(!solution.systemSolvable) {482 printNonSolvableMsg();483 return484 }485 printForwardHeader(solution, false);486 printForwardElem(solution);487 printBackwardSubHeader(solution, false);488 printBackwardSub(solution, false);489}490function printCrout(solution){491 const luCanBeFound = printLuCanBeFound(solution);492 if(!luCanBeFound) return;493 printLuFinalAnswer(solution);494 printLUSteps(solution, true);495 printLUMatrix(solution);496 if(!solution.systemSolvable) {497 printNonSolvableMsg();498 return499 }500 printForwardHeader(solution, false);501 printForwardElem(solution);502 printBackwardSubHeader(solution, false);503 printBackwardSub(solution, false);...

generator.service.ts

Source:generator.service.ts

1import { Injectable } from "@angular/core";2import { IExam } from "../components/exam-builder/exam-builder.component";3import { Document, AlignmentType, HeadingLevel, Paragraph, TextRun, UnderlineType } from 'docx';4import { Subject } from 'rxjs';5import { DomService } from './dom.service';6const studentInfoSize = 60;7const fullPageSize = 150;8const SPACE = " ";9@Injectable({10 providedIn: "root"11})12export class ExamGeneratorService {13 constructor(private readonly domService: DomService) { }14 public downloadExam({ questions, documentName }: IExam): Subject<{ done: boolean, message: string }> {15 const result$= new Subject<{ done: boolean, message: string }>();16 Promise.all([17 this.domService.downloadWordFile(${documentName}.docx, this.generateExam(questions, false)),18 this.domService.downloadWordFile(${documentName}:solved.docx, this.generateExam(questions, true))19 ])20 .then(() => {21 result$.next({ done: true, message: "Examen generado" });22 })23 .catch(error => {24 result$.error({ done: false, message: error.message });25 })26 .finally(() => {27 result$.complete();28 });29 return result;30 }31 private generateExam(questions, withSolution): Document {32 let sectionChildrens = []33 questions.forEach((question, index) => this.generateQuestion(sectionChildrens, question, index, withSolution));34 let doc = new Document()35 doc.addSection({36 children: [37 this.generateHeadingLine("Apellido : "),38 this.generateHeadingLine("Nombre : "),39 this.generateHeadingLine("Clase : "),40 this.generateHeadingLine("Fecha : "),41 new Paragraph({42 text: "Prototipo Examen EspaÃ±ol",43 alignment: AlignmentType.CENTER,44 heading: HeadingLevel.HEADING_145 }),46 ...sectionChildrens47 ]48 })49 return doc;50 }51 private generateQuestionTitle(question, questionNumber): Paragraph {52 let children = [53 new TextRun({54 text: {questionNumber}) ${question.title.title}55 }),56 ]57 if (question.title.showScore) {58 children.push(new TextRun({59 text: ${question.title.score} puntos,60 size: 20,61 italics: true62 }))63 }64 return new Paragraph({65 heading: HeadingLevel.HEADING_2,66 children67 })68 }69 private generateHeadingLine(label): Paragraph {70 return new Paragraph({71 alignment: AlignmentType.LEFT,72 children: [73 new TextRun({74 text: label75 }),76 new TextRun({77 text: SPACE.repeat(studentInfoSize),78 underline: {79 type: UnderlineType.SINGLE,80 color: "990011"81 }82 })83 ]84 })85 }86 private generateQuestion(sectionChildrens, question, index, withSolution): void {87 sectionChildrens.push(this.generateQuestionTitle(question, index + 1))88 const { answer } = question;89 if (answer.type === 1) {90 this.generateAnswerSingleLine(sectionChildrens, answer, withSolution);91 } else if (answer.type === 2) {92 this.generateAnswerMultiChoice(sectionChildrens, answer, withSolution);93 } else if (answer.type === 3) {94 this.generateAnswerMultiLine(sectionChildrens, answer, withSolution);95 }96 }97 private generateAnswerSingleLine(sectionChildrens, answer, withSolution): void {98 const { content } = answer;99 const contentLength = withSolution ? fullPageSize - content.length : fullPageSize;100 const responseContent = (withSolution ? content : '') + SPACE.repeat(contentLength);101 sectionChildrens.push(new Paragraph({102 alignment: AlignmentType.LEFT,103 children: [104 new TextRun({105 text: responseContent,106 underline: {107 type: UnderlineType.SINGLE,108 color: "990011"109 }110 })111 ]112 }))113 }114 private generateAnswerMultiLine(sectionChildrens, answer, withSolution): void {115 const { content } = answer;116 const contentLength = withSolution ? fullPageSize - content.length : fullPageSize;117 const responseContent = (withSolution ? content : '') + SPACE.repeat(contentLength);118 sectionChildrens.push(new Paragraph({119 alignment: AlignmentType.LEFT,120 children: [121 new TextRun({122 text: responseContent,123 underline: {124 type: UnderlineType.SINGLE,125 color: "990011"126 }127 })128 ]129 }))130 }131 private generateAnswerMultiChoice(sectionChildrens, answer, withSolution): void {132 answer.choices.forEach((choice, i) => {133 sectionChildrens.push(new Paragraph({134 children: [135 new TextRun({136 text: choice.content,137 bold: withSolution,138 })139 ],140 bullet: {141 level: 0142 }143 }))144 })145 }146 // const downloader: HTMLAnchorElement = document.createElement('a');147 // // downloader.setAttribute('hidden', 'true');148 // downloader.hidden = true;149 // downloader.href = this.sanitizer.sanitize(SecurityContext.RESOURCE_URL,150 // this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob)));151 // downloader.download = 'pruebas.txt';152 // window.document.body.append(downloader);153 // // downloader.onclick =154 // downloader.click();...

challenge-view.component.ts

Source:challenge-view.component.ts

1import { Component, OnInit, Input, ViewChild, AfterViewInit, OnChanges } from '@angular/core'2import { BaseComponent } from '../base.component'3import { ROUTER_DIRECTIVES } from '@angular/router'4import { Challenge, User, Reply, Solution } from '../services/data'5import { LikeViewComponent } from '../like-view'6import { CodeEditorComponent } from '../code-editor'7import { ErrorComponent } from '../error'8import { ChallengeService } from '../services/challenge.service'9import { GlobalService } from '../services/global.service'10import { MarkUpPipe } from '../pipes/mark-up.pipe'11import { DateTimePipe } from '../pipes/date-time.pipe'12@Component({13 moduleId: module.id,14 selector: 'app-challenge-view',15 templateUrl: 'challenge-view.component.html',16 directives: [LikeViewComponent, CodeEditorComponent, ErrorComponent, ROUTER_DIRECTIVES],17 pipes: [ MarkUpPipe, DateTimePipe ]18})19export class ChallengeViewComponent extends BaseComponent implements OnInit {20 // the challege to display21 @Input() challenge: Challenge22 // reply with solution23 withSolution = false24 solutionLength = 025 deleted = false26 // cache value27 values: string[] = []28 // the reply29 reply: Solution30 // code editor view child31 @ViewChild("editor") codeEditor: CodeEditorComponent32 // the constructor33 constructor(private challengeService: ChallengeService,34 globalService: GlobalService) {35 super(globalService)36 }37 ngOnInit() { 38 39 }40 // after the view is initialized41 ngAfterViewInit() {42 if (this.challenge) {43 this.updateCodeEditor()44 }45 }46 // on code change47 codeChanged(code: string) {48 this.solutionLength = code.replace(/\s/g, '').length49 }50 // update the code editor51 updateCodeEditor() {52 if (this.withSolution) {53 this.codeEditor.setMode("swift")54 var segments = (this.challenge.code || "").split(*/)55 var code = segments[segments.length - 1]56 this.codeEditor.setCode(this.values[this.withSolution?1:0] || code)57 } else {58 this.codeEditor.setMode("markdown")59 this.codeEditor.setCode(this.values[this.withSolution?1:0] || "")60 }61 }62 deleteChallenge() {63 this.challengeService.deleteChallenge(this.challenge)64 .subscribe(() =>{65 this.deleted = true66 })67 }68 // delete the reply69 deleteReply(reply: Reply) {70 this.challengeService.deleteReply(reply)71 .subscribe(() =>{72 reply["deleted"] = true73 })74 }75 // attach the solution76 attachSolutionChanged() {77 // save old values78 var value = this.codeEditor.getCode()79 this.values[this.withSolution?1:0] = value80 this.withSolution = !this.withSolution81 this.updateCodeEditor()82 }83 84 // on reply clicked85 replyClicked(submit: boolean = false) {86 var content = this.codeEditor.getCode()87 this.loading = true88 89 if (!this.withSolution) { 90 var reply: Reply = {}91 reply.content = content92 this.challengeService.addReply(this.challenge, reply)93 .subscribe((response) => {94 this.challenge.replies.push(response.json())95 this.loading = false96 this.codeEditor.setCode("")97 },98 () => {99 this.error = "Unable to post reply"100 this.loading = false101 })102 103 } else {104 var solution: Solution = {}105 solution.code = content106 this.challengeService.testSolution(this.challenge, solution, submit)107 .subscribe((response) => {108 this.reply = response.json()109 if (submit110 && this.reply111 && this.reply.result 112 && this.reply.result.tests113 && this.reply.result.tests.length > 0114 && this.reply.result.tests.every(i => i)115 && this.reply.result.hiddenTests.every(i => i)) {116 this.challenge.replies.push(this.reply)117 this.attachSolutionChanged()118 this.globalService.channel("gift-dialog")119 .emit({120 'title': "Congratulation",121 'message': this.reply.reward ? 'You have earned ' + this.reply.reward + ' points!'122 : 'You have successfully submit a solution!'123 })124 } else {125 this.error = this.reply.result.error126 }127 this.reply.result.passedTests = this.reply.result.tests.filter(i => i).length128 this.reply.result.passedHiddenTests = this.reply.result.hiddenTests.filter(i => i).length129 this.loading = false130 },131 () => {132 this.error = "Unable to post solution"133 this.loading = false134 })135 }136 }...

Using AI Code Generation

1const fc = require("fast-check");2const { withSolution } = require("fast-check-monorepo");3fc.assert(4 withSolution(5 fc.property(fc.integer(), fc.integer(), (a, b) => {6 return a * b === b * a;7 })8);9const fc = require("fast-check");10const { withSolution } = require("fast-check-monorepo");11fc.assert(12 withSolution(13 fc.property(fc.integer(), fc.integer(), (a, b) => {14 return a * b === b * a;15 })16);17const fc = require("fast-check");18const { withSolution } = require("fast-check-monorepo");19fc.assert(20 withSolution(21 fc.property(fc.integer(), fc.integer(), (a, b) => {22 return a * b === b * a;23 })24);25const fc = require("fast-check");26const { withSolution } = require("fast-check-monorepo");27fc.assert(28 withSolution(29 fc.property(fc.integer(), fc.integer(), (a, b) => {30 return a * b === b * a;31 })32);33const fc = require("fast-check");34const { withSolution } = require("fast-check-monorepo");35fc.assert(36 withSolution(37 fc.property(fc.integer(), fc.integer(), (a, b) => {38 return a * b === b * a;39 })40);41const fc = require("fast-check");42const { withSolution } = require("fast-check-monorepo");43fc.assert(44 withSolution(45 fc.property(fc.integer(), fc.integer(), (a, b) => {46 return a * b === b * a;47 })48);49const fc = require("fast-check");50const { withSolution

Using AI Code Generation

1const fc = require('fast-check');2const { withSolution } = require('fast-check-monorepo');3const isOdd = (n) => n % 2 === 1;4const isEven = (n) => n % 2 === 0;5const isOddOrEven = (n) => isOdd(n) || isEven(n);6const isOddAndEven = (n) => isOdd(n) && isEven(n);7const isOddAndOdd = (n) => isOdd(n) && isOdd(n + 1);8const isEvenAndEven = (n) => isEven(n) && isEven(n + 1);9const isOddOrEvenAndEven = (n) => isOddOrEven(n) && isEven(n + 1);10const isOddOrEvenAndOdd = (n) => isOddOrEven(n) && isOdd(n + 1);11const isOddAndOddOrEven = (n) => isOdd(n) && isOddOrEven(n + 1);12const isEvenAndOddOrEven = (n) => isEven(n) && isOddOrEven(n + 1);13const isOddOrEvenAndOddOrEven = (n) => isOddOrEven(n) && isOddOrEven(n + 1);14const isOddAndOddAndEven = (n) => isOdd(n) && isOdd(n + 1) && isEven(n + 2);15const isEvenAndEvenAndOdd = (n) => isEven(n) && isEven(n + 1) && isOdd(n + 2);16const isOddAndOddOrEvenAndOdd = (n) => isOdd(n) && isOddOrEven(n + 1) && isOdd(n + 2);17const isOddAndOddOrEvenAndEven = (n) => isOdd(n) && isOddOrEven(n + 1) && isEven(n + 2);18const isEvenAndOddOrEvenAndOdd = (n) => isEven(n) && isOddOrEven(n + 1) && isOdd(n + 2);19const isEvenAndOddOrEvenAndEven = (n) => isEven(n) && isOddOrEven(n + 1) && isEven(n + 2);20const isOddOrEvenAndOddAndEven = (n) => isOddOrEven(n)

Using AI Code Generation

1import fc from 'fast-check';2import { withSolution } from 'fast-check-monorepo';3import { test3 } from '../src/test3';4describe('test3', () => {5 it('should return true', () => {6 withSolution(() => {7 fc.assert(8 fc.property(fc.integer(), (x) => {9 expect(test3(x)).toEqual(true);10 })11 );12 });13 });14});15import fc from 'fast-check';16import { withSolution } from 'fast-check-monorepo';17import { test3 } from '../src/test3';18describe('test3', () => {19 it('should return true', () => {20 withSolution(() => {21 fc.assert(22 fc.property(fc.integer(), (x) => {23 expect(test3(x)).toEqual(true);24 })25 );26 });27 });28});29import fc from 'fast-check';30import { withSolution } from 'fast-check-monorepo';31import { test3 } from '../src/test3';32describe('test3', () => {33 it('should return true', () => {34 withSolution(() => {35 fc.assert(36 fc.property(fc.integer(), (x) => {37 expect(test3(x)).toEqual(true);38 })39 );40 });41 });42});43import fc from 'fast-check';44import { withSolution } from 'fast-check-monorepo';45import { test3 } from '../src/test3';46describe('test3', () => {47 it('should return true', () => {48 withSolution(() => {49 fc.assert(50 fc.property(fc.integer(), (x) => {51 expect(test3(x)).toEqual(true);52 })53 );54 });55 });56});57import fc from 'fast-check';58import { withSolution } from 'fast-check-monorepo';59import { test3 } from '../src/test3';60describe('test3', () => {61 it('should return true', () => {62 withSolution(() => {63 fc.assert(

Using AI Code Generation

1const fc = require("fast-check");2const { withSolution } = require("fast-check-monorepo");3const myArb = fc.array(fc.integer());4const myProp = (arr) => {5 return arr.length === 3;6};7withSolution(myArb, myProp, (solution) => {8 console.log(solution);9});10const fc = require("fast-check");11const { withSolution } = require("fast-check-monorepo");12const myArb = fc.array(fc.integer());13const myProp = (arr) => {14 return arr.length === 4;15};16withSolution(myArb, myProp, (solution) => {17 console.log(solution);18});19const fc = require("fast-check");20const { withSolution } = require("fast-check-monorepo");21const myArb = fc.array(fc.integer());22const myProp = (arr) => {23 return arr.length === 5;24};25withSolution(myArb, myProp, (solution) => {26 console.log(solution);27});28const fc = require("fast-check");29const { withSolution } = require("fast-check-monorepo");30const myArb = fc.array(fc.integer());31const myProp = (arr) => {32 return arr.length === 6;33};34withSolution(myArb, myProp, (solution) => {35 console.log(solution);36});37const fc = require("fast-check");38const { withSolution } = require("fast-check-monorepo");39const myArb = fc.array(fc.integer());40const myProp = (arr) => {41 return arr.length === 7;42};43withSolution(myArb, myProp, (solution) => {44 console.log(solution);45});46const fc = require("fast-check");47const { withSolution } = require("fast-check-monorepo");48const myArb = fc.array(fc.integer());49const myProp = (arr) => {

Using AI Code Generation

1const { withSolution } = require("fast-check");2const { solution } = require("../src/solution");3describe("solution", () => {4 withSolution(solution, (solution) => {5 it("should return the correct value", () => {6 expect(solution(1, 2, 3)).toEqual(6);7 expect(solution(1, 2, 4)).toEqual(7);8 expect(solution(1, 3, 3)).toEqual(7);9 expect(solution(1, 3, 6)).toEqual(10);10 expect(solution(1, 4, 5)).toEqual(10);11 expect(solution(1, 4, 6)).toEqual(11);12 expect(solution(1, 5, 6)).toEqual(12);13 expect(solution(1, 5, 10)).toEqual(16);14 expect(solution(1, 6, 10)).toEqual(17);15 expect(solution(1, 6, 12)).toEqual(19);16 expect(solution(1, 7, 12)).toEqual(20);17 expect(solution(1, 7, 13)).toEqual(21);18 expect(solution(1, 8, 12)).toEqual(21);19 expect(solution(1, 8, 13)).toEqual(22);20 expect(solution(1, 8, 14)).toEqual(23);21 expect(solution(1, 9, 12)).toEqual(22);22 expect(solution(1, 9, 13)).toEqual(23);23 expect(solution(1, 9, 14)).toEqual(24);24 expect(solution(1, 9, 15)).toEqual(25);25 expect(solution(1, 10, 12)).toEqual(23);26 expect(solution(1, 10, 13)).toEqual(24);27 expect(solution(1, 10, 14)).toEqual(25);28 expect(solution(1, 10, 15)).toEqual(26);29 expect(solution(1, 10, 16)).toEqual(27);30 expect(solution(1, 11, 12)).toEqual(24);31 expect(solution(1, 11, 13)).toEqual(25);32 expect(solution(1, 11, 14)).toEqual(26);33 expect(solution(1, 11, 15)).toEqual(27

Using AI Code Generation

1import { withSolution } from "../src/index";2import { suite, test } from "mocha-typescript";3import { expect } from "chai";4import { suite as suite2 } from "mocha-typescript";5import { suite as suite3 } from "mocha-typescript";6class Test3 {7 "test1"() {8 expect(1).to.equal(1);9 }10 "test2"() {11 expect(2).to.equal(2);12 }13 "test3"() {14 expect(3).to.equal(3);15 }16}17class Test4 {18 "test4"() {19 expect(4).to.equal(4);20 }21 "test5"() {22 expect(5).to.equal(5);23 }24 "test6"() {25 expect(6).to.equal(6);26 }27}28class Test5 {29 "test7"() {30 expect(7).to.equal(7);31 }32 "test8"() {33 expect(8).to.equal(8);34 }35 "test9"() {36 expect(9).to.equal(9);37 }38}39class Test6 {40 "test10"() {41 expect(10).to.equal(10);42 }43 "test11"() {44 expect(11).to.equal(11);45 }46 "test12"() {47 expect(12).to.equal(12);48 }49}50class Test7 {51 "test13"() {52 expect(13).to.equal(13);53 }54 "test14"() {55 expect(14).to.equal(14);56 }57 "test15"() {58 expect(15).to.equal(15);59 }60}61class Test8 {62 "test16"() {63 expect(16).to.equal(16);64 }65 "test17"() {66 expect(17).to.equal(17);67 }

Using AI Code Generation

1const { withSolution } = require('../src/fast-check');2const { expect } = require('chai');3const testMe = (a, b) => {4 if (a < b) {5 return a;6 } else {7 return b;8 }9};10describe('Test fast-check withSolution', function () {11 it('should return a', function () {12 withSolution((a, b) => {13 expect(testMe(a, b)).to.equal(a);14 }, [fc.nat(), fc.nat()]);15 });16});

Using AI Code Generation

1import { withSolution, withSolutionAsync } from "fast-check";2import { Solution, SolutionAsync } from "fast-check";3const check = withSolution(4 new Solution(),5 fc.property(fc.integer(), (i) => i % 2 === 0)6);7const checkAsync = withSolutionAsync(8 new SolutionAsync(),9 fc.asyncProperty(fc.integer(), async (i) => {10 const p = new Promise((resolve) => {11 setTimeout(() => {12 resolve(i % 2 === 0);13 }, 1000);14 });15 return p;16 })17);18check.run();19checkAsync.run();

Using AI Code Generation

1const fc = require('fast-check');2const addFirstLast = (arr1, arr2) => {3 if (arr1.length === 0 || arr2.length === 0) {4 throw new Error('empty array');5 }6 if (arr1.length !== arr2.length) {7 throw new Error('arrays are not the same length');8 }9 return [arr1[0] + arr2[arr2.length - 1]];10};11fc.assert(12 fc.property(13 fc.array(fc.integer(), 2, 10),14 fc.array(fc.integer(), 2, 10),15 (arr1, arr2) => {16 const result = addFirstLast(arr1, arr2);17 return result.length === 1;18 }19);20fc.assert(21 fc.property(22 fc.array(fc.integer(), 2, 10),23 fc.array(fc.integer(), 2, 10),24 (arr1, arr2) => {25 const result = addFirstLast(arr1, arr2);26 return result[0] === arr1[0] + arr2[arr2.length - 1];27 }28);29fc.assert(30 fc.property(31 fc.array(fc.integer(), 2, 10),32 fc.array(fc.integer(), 2, 10),33 (arr1, arr2) => {34 const result = addFirstLast(arr1, arr2);35 return result[0] === arr2[arr2.length - 1] + arr1[0];36 }37);38fc.assert(39 fc.property(40 fc.array(fc.integer(), 2, 10),41 fc.array(fc.integer(), 2, 10),42 (arr1, arr2) => {43 const result = addFirstLast(arr1, arr2);44 return result[0] === arr1[arr1.length - 1] + arr2[0];45 }46);

## 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.