| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>A simple unit testing for audio-test-utils.js and testharness.js</title
> | 4 <title>audit.js: basic tests</title> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit.js"></script> | 7 <script src="../resources/audit.js"></script> |
| 8 </head> | 8 </head> |
| 9 <body> | 9 <body> |
| 10 <script> | 10 <script> |
| 11 var audit = Audit.createTaskRunner(); | 11 var audit = Audit.createTaskRunner(); |
| 12 | 12 |
| 13 // Basic assertion testing. | 13 // Basic assertion testing. |
| 14 audit.define('basic', function (task, should) { | 14 audit.define('basic', function (task, should) { |
| 15 task.describe('Simple unit tests for basic assertions.'); | 15 task.describe('Simple unit tests for basic assertions.'); |
| 16 | 16 |
| 17 should(OfflineAudioContext, 'OfflineAudioContext').exist(); | 17 should(OfflineAudioContext, 'OfflineAudioContext').exist(); |
| 18 | |
| 19 should(function () { var foo = 0; }, 'Setting foo to 0').notThrow(); | 18 should(function () { var foo = 0; }, 'Setting foo to 0').notThrow(); |
| 20 should(function () { var foo = bar; }).throw('ReferenceError'); | 19 should(function () { var foo = bar; }).throw('ReferenceError'); |
| 21 | |
| 22 should(3 < 5, '3 < 5').beTrue(); | 20 should(3 < 5, '3 < 5').beTrue(); |
| 23 should(false).beFalse(); | 21 should(false).beFalse(); |
| 24 | |
| 25 should(1).beEqualTo(1) | 22 should(1).beEqualTo(1) |
| 26 should(1).notBeEqualTo(2) | 23 should(1).notBeEqualTo(2) |
| 27 should(typeof AudioContext.prototype).beEqualTo('object'); | 24 should(typeof AudioContext.prototype).beEqualTo('object'); |
| 28 | |
| 29 should(2).beGreaterThan(1); | 25 should(2).beGreaterThan(1); |
| 30 should(2).beGreaterThanOrEqualTo(2); | 26 should(2).beGreaterThanOrEqualTo(2); |
| 31 | |
| 32 should(1).beLessThan(2); | 27 should(1).beLessThan(2); |
| 33 should(1).beLessThanOrEqualTo(1); | 28 should(1).beLessThanOrEqualTo(1); |
| 34 | 29 |
| 35 let oac = new OfflineAudioContext(1, 128, 44100); | 30 let oac = new OfflineAudioContext(1, 128, 44100); |
| 36 | |
| 37 Promise.all([ | 31 Promise.all([ |
| 38 should(oac.startRendering(), 'Start OAC rendering').beResolved(), | 32 should(oac.startRendering(), 'Start OAC rendering').beResolved(), |
| 39 should(oac.decodeAudioData()).beRejected() | 33 should(oac.decodeAudioData()).beRejected() |
| 40 ]).then(function () { | 34 ]).then(task.done.bind(task)); |
| 41 task.done(); | |
| 42 }); | |
| 43 }); | 35 }); |
| 44 | 36 |
| 45 | 37 |
| 46 // Advanced, mostly array-based numerical testing. Note that some codes | 38 // Advanced, mostly array-based numerical testing. Note that some codes |
| 47 // are commented out to avoid the trybot failure. These failures are | 39 // are commented out to avoid the trybot failure. These failures are |
| 48 // intentional, to demonstrate how the detailed failure report works. | 40 // intentional, to demonstrate how the detailed failure report works. |
| 49 audit.define('numerical', function (task, should) { | 41 audit.define('numerical', function (task, should) { |
| 50 task.describe('Numerical assertion unit test.'); | 42 task.describe('Numerical assertion unit test.'); |
| 51 | 43 |
| 52 should(2.3).beCloseTo(2, { threshold: 0.3 }); | 44 should(2.3).beCloseTo(2, { threshold: 0.3 }); |
| 53 | |
| 54 should([1, 1, 1]).beConstantValueOf(1); | 45 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]); | 46 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]) | 47 should([1, 1, 1, 1, 2, 2, 3, 3, 3]) |
| 62 .containValues([1, 2, 3], 'one, two, three'); | 48 .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); | 49 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 | 50 |
| 74 task.done(); | 51 task.done(); |
| 75 }); | 52 }); |
| 76 | 53 |
| 77 | 54 |
| 78 audit.run(); | 55 // This task is defined, but you can selectively opt it out when the task |
| 56 // runs. If you would like to see how failure cases get printed, include |
| 57 // this task and launch the task runner. |
| 58 audit.define('empty', function (task, should) { |
| 59 task.describe('This is an empty task.'); |
| 60 |
| 61 task.done(); |
| 62 }); |
| 63 |
| 64 |
| 65 // You can enumerate tasks you want to execute in the order, or simply pass |
| 66 // no argument to run all the defined tasks. |
| 67 audit.run('numerical', 'basic'); |
| 79 </script> | 68 </script> |
| 80 </body> | 69 </body> |
| 81 </html> | 70 </html> |
| OLD | NEW |