mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-26 06:01:11 -04:00
Add unit tests for all utility modules. Re GH-103
This commit is contained in:
parent
b98577129e
commit
8ca6944292
11 changed files with 286 additions and 0 deletions
test/unit
37
test/unit/util_math.js
Normal file
37
test/unit/util_math.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
var test = require('tap').test;
|
||||
var math = require('../../src/util/math-util');
|
||||
|
||||
test('degToRad', function (t) {
|
||||
// @todo This is incorrect
|
||||
t.equal(math.degToRad(0), 1.5707963267948966);
|
||||
t.equal(math.degToRad(1), 1.5533430342749535);
|
||||
t.equal(math.degToRad(180), -1.5707963267948966);
|
||||
t.equal(math.degToRad(360), -4.71238898038469);
|
||||
t.equal(math.degToRad(720), -10.995574287564276);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('radToDeg', function (t) {
|
||||
t.equal(math.radToDeg(0), 0);
|
||||
t.equal(math.radToDeg(1), 57.29577951308232);
|
||||
t.equal(math.radToDeg(180), 10313.240312354817);
|
||||
t.equal(math.radToDeg(360), 20626.480624709635);
|
||||
t.equal(math.radToDeg(720), 41252.96124941927);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('clamp', function (t) {
|
||||
t.equal(math.clamp(0, 0, 10), 0);
|
||||
t.equal(math.clamp(1, 0, 10), 1);
|
||||
t.equal(math.clamp(-10, 0, 10), 0);
|
||||
t.equal(math.clamp(100, 0, 10), 10);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('wrapClamp', function (t) {
|
||||
t.equal(math.wrapClamp(0, 0, 10), 0);
|
||||
t.equal(math.wrapClamp(1, 0, 10), 1);
|
||||
t.equal(math.wrapClamp(-10, 0, 10), 1);
|
||||
t.equal(math.wrapClamp(100, 0, 10), 1);
|
||||
t.end();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue