1 function test_utils() { |
1 function test_utils() { |
2 module("Utility function tests"); |
2 module("Utility function tests"); |
|
3 |
|
4 test("test a function to preserve the scope of a method in a callback", function() { |
|
5 var obj = { a : 2}; |
|
6 obj.b = function(e, f) { |
|
7 equal(this.a, 2, "the scope is preserved"); |
|
8 equal(e, 1, "arg 1 passed correctly"); |
|
9 equal(f, 2, "arg 2 passed correctly"); |
|
10 }; |
|
11 |
|
12 (IriSP.wrap(obj, obj.b))(1, 2); |
|
13 |
|
14 }); |
|
15 |
|
16 test("test function to convert a ratio to a percentage", function() { |
|
17 var time = 2; |
|
18 var total = 3; |
|
19 |
|
20 equal(IriSP.timeToPourcent(2, 3), 66, "the function returns the correct result"); |
|
21 |
|
22 var total = -total; |
|
23 |
|
24 equal(IriSP.timeToPourcent(2, 3), 66, "the function is immune to negative numbers"); |
|
25 }); |
3 |
26 |
4 test("test function to convert from seconds to a time", function() { |
27 test("test function to convert from seconds to a time", function() { |
5 var h = 13, m = 7, s = 41; |
28 var h = 13, m = 7, s = 41; |
6 var t = 13 * 3600 + 7* 60 + 41; |
29 var t = 13 * 3600 + 7* 60 + 41; |
7 deepEqual(IriSP.secondsToTime(t), [h, m, s], "the converted time is correct"); |
30 deepEqual(IriSP.secondsToTime(t), [h, m, s], "the converted time is correct"); |