How to use comparePartialSignals method in wpt

Best JavaScript code snippet using wpt

audioparam-testing.js

Source:audioparam-testing.js Github

copy

Full Screen

...178 function valueUpdate(timeIntervalIndex) {179 return -startingValueDelta;180 }181 // Compare a section of the rendered data against our expected signal.182 function comparePartialSignals(183 should, rendered, expectedFunction, startTime, endTime, valueInfo,184 sampleRate, errorMetric) {185 let startSample = timeToSampleFrame(startTime, sampleRate);186 let expected = expectedFunction(187 startTime, endTime, valueInfo.startValue, valueInfo.endValue,188 sampleRate, timeConstant);189 let n = expected.length;190 let maxError = -1;191 let maxErrorIndex = -1;192 for (let k = 0; k < n; ++k) {193 // Make sure we don't pass these tests because a NaN has been generated in194 // either the195 // rendered data or the reference data.196 if (!isValidNumber(rendered[startSample + k])) {197 maxError = Infinity;198 maxErrorIndex = startSample + k;199 should(200 isValidNumber(rendered[startSample + k]),201 'NaN or infinity for rendered data at ' + maxErrorIndex)202 .beTrue();203 break;204 }205 if (!isValidNumber(expected[k])) {206 maxError = Infinity;207 maxErrorIndex = startSample + k;208 should(209 isValidNumber(expected[k]),210 'NaN or infinity for rendered data at ' + maxErrorIndex)211 .beTrue();212 break;213 }214 let error = Math.abs(errorMetric(rendered[startSample + k], expected[k]));215 if (error > maxError) {216 maxError = error;217 maxErrorIndex = k;218 }219 }220 return {maxError: maxError, index: maxErrorIndex, expected: expected};221 }222 // Find the discontinuities in the data and compare the locations of the223 // discontinuities with the times that define the time intervals. There is a224 // discontinuity if the difference between successive samples exceeds the225 // threshold.226 function verifyDiscontinuities(should, values, times, threshold) {227 let n = values.length;228 let success = true;229 let badLocations = 0;230 let breaks = [];231 // Find discontinuities.232 for (let k = 1; k < n; ++k) {233 if (Math.abs(values[k] - values[k - 1]) > threshold) {234 breaks.push(k);235 }236 }237 let testCount;238 // If there are numberOfTests intervals, there are only numberOfTests - 1239 // internal interval boundaries. Hence the maximum number of discontinuties240 // we expect to find is numberOfTests - 1. If we find more than that, we241 // have no reference to compare against. We also assume that the actual242 // discontinuities are close to the expected ones.243 //244 // This is just a sanity check when something goes really wrong. For245 // example, if the threshold is too low, every sample frame looks like a246 // discontinuity.247 if (breaks.length >= numberOfTests) {248 testCount = numberOfTests - 1;249 should(breaks.length, 'Number of discontinuities')250 .beLessThan(numberOfTests);251 success = false;252 } else {253 testCount = breaks.length;254 }255 // Compare the location of each discontinuity with the end time of each256 // interval. (There is no discontinuity at the start of the signal.)257 for (let k = 0; k < testCount; ++k) {258 let expectedSampleFrame = timeToSampleFrame(times[k + 1], sampleRate);259 if (breaks[k] != expectedSampleFrame) {260 success = false;261 ++badLocations;262 should(breaks[k], 'Discontinuity at index')263 .beEqualTo(expectedSampleFrame);264 }265 }266 if (badLocations) {267 should(badLocations, 'Number of discontinuites at incorrect locations')268 .beEqualTo(0);269 success = false;270 } else {271 should(272 breaks.length + 1,273 'Number of tests started and ended at the correct time')274 .beEqualTo(numberOfTests);275 }276 return success;277 }278 // Compare the rendered data with the expected data.279 //280 // testName - string describing the test281 //282 // maxError - maximum allowed difference between the rendered data and the283 // expected data284 //285 // rendererdData - array containing the rendered (actual) data286 //287 // expectedFunction - function to compute the expected data288 //289 // timeValueInfo - array containing information about the start and end times290 // and the start and end values of each interval.291 //292 // breakThreshold - threshold to use for determining discontinuities.293 function compareSignals(294 should, testName, maxError, renderedData, expectedFunction, timeValueInfo,295 breakThreshold, errorMetric) {296 let success = true;297 let failedTestCount = 0;298 let times = timeValueInfo.times;299 let values = timeValueInfo.values;300 let n = values.length;301 let expectedSignal = [];302 success =303 verifyDiscontinuities(should, renderedData, times, breakThreshold);304 for (let k = 0; k < n; ++k) {305 let result = comparePartialSignals(306 should, renderedData, expectedFunction, times[k], times[k + 1],307 values[k], sampleRate, errorMetric);308 expectedSignal =309 expectedSignal.concat(Array.prototype.slice.call(result.expected));310 should(311 result.maxError,312 'Max error for test ' + k + ' at offset ' +313 (result.index + timeToSampleFrame(times[k], sampleRate)))314 .beLessThanOrEqualTo(maxError);315 }316 should(317 failedTestCount,318 'Number of failed tests with an acceptable relative tolerance of ' +319 maxError)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var signal1 = [1,2,3,4,5];3var signal2 = [2,3,4,5,6];4var signal3 = [1,2,3,4,5,6];5var signal4 = [1,2,3,4,5,6,7];6var signal5 = [1,2,3,4,5,6,7,8];7var signal6 = [1,2,3,4,5,6,7,8,9];8var signal7 = [1,2,3,4,5,6,7,8,9,10];9var signals = [signal1, signal2, signal3, signal4, signal5, signal6, signal7];10var signalLength = signals.length;11var window1 = [1,2,3];12var window2 = [1,2,3,4];13var window3 = [1,2,3,4,5];14var window4 = [1,2,3,4,5,6];15var window5 = [1,2,3,4,5,6,7];16var window6 = [1,2,3,4,5,6,7,8];17var window7 = [1,2,3,4,5,6,7,8,9];18var window8 = [1,2,3,4,5,6,7,8,9,10];19var windows = [window1, window2, window3, window4, window5, window6, window7, window8];20var windowLength = windows.length;21var threshold = 0.5;22var windowSize = 3;23for (var i = 0; i < signalLength; i++) {24 for (var j = 0; j < windowLength; j++) {25 var result = wpt.comparePartialSignals(signals[i], windows[j], threshold, windowSize);26 console.log(result);27 }28}29[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require("wpt");2const wptClient = new wpt("API_KEY");3const test = async () => {4 const testId = "TEST_ID";5 const options = {6 };7 const result = await wptClient.comparePartialSignals(testId, options);8 console.log(result);9};10test();

Full Screen

Using AI Code Generation

copy

Full Screen

1var Wpt = require('./wpt.js');2var wpt = new Wpt();3var signal1 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];4var signal2 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];5var signal3 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];6var signal4 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];7var signal5 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];8var signal6 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];9var signal7 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];10var signal8 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];11var signal9 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];12var signal10 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];13var signal11 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];14var signal12 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];

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