| author | hamidouk |
| Wed, 16 Nov 2011 11:40:57 +0100 | |
| branch | popcorn-port |
| changeset 253 | 95c6b77f005e |
| parent 252 | fd84e0fb26d8 |
| child 254 | cafaa694b709 |
| permissions | -rw-r--r-- |
|
252
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
1 |
function test_utils() { |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
2 |
module("Utility function tests"); |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
3 |
|
| 253 | 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 |
}); |
|
26 |
|
|
|
252
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
27 |
test("test function to convert from seconds to a time", function() { |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
28 |
var h = 13, m = 7, s = 41; |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
29 |
var t = 13 * 3600 + 7* 60 + 41; |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
30 |
deepEqual(IriSP.secondsToTime(t), [h, m, s], "the converted time is correct"); |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
31 |
|
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
32 |
t = -t; |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
33 |
deepEqual(IriSP.secondsToTime(t), [h, m, s], "the function is immune to negative numbers."); |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
34 |
}); |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
35 |
} |