| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>A simple unit testing for audio-test-utils.js and testharness.js</title
> |
| 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit.js"></script> |
| 8 </head> |
| 9 <body> |
| 10 <script> |
| 11 var audit = Audit.createTaskRunner(); |
| 12 |
| 13 // Basic assertion testing. |
| 14 audit.define('basic', function (task, should) { |
| 15 task.describe('Simple unit tests for basic assertions.'); |
| 16 |
| 17 should(OfflineAudioContext, 'OfflineAudioContext').exist(); |
| 18 |
| 19 should(function () { var foo = 0; }, 'Setting foo to 0').notThrow(); |
| 20 should(function () { var foo = bar; }).throw('ReferenceError'); |
| 21 |
| 22 should(3 < 5, '3 < 5').beTrue(); |
| 23 should(false).beFalse(); |
| 24 |
| 25 should(1).beEqualTo(1) |
| 26 should(1).notBeEqualTo(2) |
| 27 should(typeof AudioContext.prototype).beEqualTo('object'); |
| 28 |
| 29 should(2).beGreaterThan(1); |
| 30 should(2).beGreaterThanOrEqualTo(2); |
| 31 |
| 32 should(1).beLessThan(2); |
| 33 should(1).beLessThanOrEqualTo(1); |
| 34 |
| 35 let oac = new OfflineAudioContext(1, 128, 44100); |
| 36 |
| 37 Promise.all([ |
| 38 should(oac.startRendering(), 'Start OAC rendering').beResolved(), |
| 39 should(oac.decodeAudioData()).beRejected() |
| 40 ]).then(function () { |
| 41 task.done(); |
| 42 }); |
| 43 }); |
| 44 |
| 45 |
| 46 // Advanced, mostly array-based numerical testing. Note that some codes |
| 47 // are commented out to avoid the trybot failure. These failures are |
| 48 // intentional, to demonstrate how the detailed failure report works. |
| 49 audit.define('numerical', function (task, should) { |
| 50 task.describe('Numerical assertion unit test.'); |
| 51 |
| 52 should(2.3).beCloseTo(2, { threshold: 0.3 }); |
| 53 |
| 54 should([1, 1, 1]).beConstantValueOf(1); |
| 55 // should([1, 8, 11, 18, 6, 5, 5, 5, 123, 49]).beConstantValueOf(5); |
| 56 |
| 57 should([1, 1, 1]).beEqualToArray([1, 1, 1]); |
| 58 // should([1, 8, 11, 18, 6, 5, 5, 5, 123, 49]) |
| 59 // .beEqualToArray([1, 8, 10, 18, 6, 5, 6, 5, 123, 48]); |
| 60 |
| 61 should([1, 1, 1, 1, 2, 2, 3, 3, 3]) |
| 62 .containValues([1, 2, 3], 'one, two, three'); |
| 63 // should([1, 1, 1, 1, 2, 2, 3, 3, 3]).containValues([1, 3, 2]); |
| 64 |
| 65 should([0.5, 0.5, 0.55, 0.5, 0.45, 0.5]).notGlitch(0.06); |
| 66 // should([0.5, 0.5, 0.55, 0.5, 0.45, 0.5]).notGlitch(0.04); |
| 67 |
| 68 // should([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9]) |
| 69 // .beCloseToArray([0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1], { |
| 70 // absoluteThreshold: 0.02, |
| 71 // relativeThreshold: 0.1 |
| 72 // }); |
| 73 |
| 74 task.done(); |
| 75 }); |
| 76 |
| 77 |
| 78 audit.run(); |
| 79 </script> |
| 80 </body> |
| 81 </html> |
| OLD | NEW |