| author | hamidouk |
| Mon, 21 Nov 2011 16:20:16 +0100 | |
| branch | popcorn-port |
| changeset 297 | ed4a459c9290 |
| parent 285 | b7aa28af2c10 |
| child 308 | 495ef0f3e483 |
| 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 |
|
|
|
256
8e1181b855bd
added a function to pad a number with zeros. waiting for the helpers to land into
hamidouk
parents:
254
diff
changeset
|
27 |
test("test padding function", function() { |
|
8e1181b855bd
added a function to pad a number with zeros. waiting for the helpers to land into
hamidouk
parents:
254
diff
changeset
|
28 |
equal(IriSP.padWithZeros(3), "03", "function works correctly"); |
|
8e1181b855bd
added a function to pad a number with zeros. waiting for the helpers to land into
hamidouk
parents:
254
diff
changeset
|
29 |
}); |
|
8e1181b855bd
added a function to pad a number with zeros. waiting for the helpers to land into
hamidouk
parents:
254
diff
changeset
|
30 |
|
|
252
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
var t = 13 * 3600 + 7* 60 + 41; |
|
254
cafaa694b709
fixed the conversion function to accomodate mustache.
hamidouk
parents:
253
diff
changeset
|
34 |
deepEqual(IriSP.secondsToTime(t), {"hours" : h, "minutes" : m, "seconds" : s}, |
|
cafaa694b709
fixed the conversion function to accomodate mustache.
hamidouk
parents:
253
diff
changeset
|
35 |
"the converted time is correct"); |
|
252
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
36 |
|
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
37 |
t = -t; |
|
254
cafaa694b709
fixed the conversion function to accomodate mustache.
hamidouk
parents:
253
diff
changeset
|
38 |
deepEqual(IriSP.secondsToTime(t), {"hours" : h, "minutes" : m, "seconds" : s}, "the function is immune to negative numbers."); |
|
252
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
39 |
}); |
| 285 | 40 |
|
41 |
test("test function to format a tweet", function() { |
|
| 297 | 42 |
var input = "@handle @bundle #hashtag http://t.co/11111"; |
43 |
var output = "<a href='http://twitter.com/handle'>@handle</a> <a href='http://twitter.com/bundle'>@bundle</a> <a href='http://twitter.com/search?q=%23hashtag'>#hashtag</a> <a href='http://t.co/11111'>http://t.co/11111</a>"; |
|
| 285 | 44 |
equal(IriSP.formatTweet(input), output, "the correct output is given"); |
45 |
}); |
|
|
252
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
diff
changeset
|
46 |
} |