| author | hamidouk |
| Wed, 30 Nov 2011 14:27:39 +0100 | |
| branch | popcorn-port |
| changeset 361 | 15074091bdba |
| parent 308 | 495ef0f3e483 |
| child 362 | 0b1bf06c28ed |
| permissions | -rw-r--r-- |
|
308
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
1 |
function test_utils() { |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
2 |
module("Utility function tests"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
3 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
4 |
test("test a function to preserve the scope of a method in a callback", function() { |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
5 |
var obj = { a : 2}; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
6 |
obj.b = function(e, f) { |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
7 |
equal(this.a, 2, "the scope is preserved"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
8 |
equal(e, 1, "arg 1 passed correctly"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
9 |
equal(f, 2, "arg 2 passed correctly"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
10 |
}; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
11 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
12 |
(IriSP.wrap(obj, obj.b))(1, 2); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
13 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
14 |
}); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
15 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
16 |
test("test function to convert a ratio to a percentage", function() { |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
17 |
var time = 2; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
18 |
var total = 3; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
19 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
20 |
equal(IriSP.timeToPourcent(2, 3), 66, "the function returns the correct result"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
21 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
22 |
var total = -total; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
23 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
24 |
equal(IriSP.timeToPourcent(2, 3), 66, "the function is immune to negative numbers"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
25 |
}); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
26 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
27 |
test("test padding function", function() { |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
28 |
equal(IriSP.padWithZeros(3), "03", "function works correctly"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
29 |
}); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
30 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
31 |
test("test function to convert from seconds to a time", function() { |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
32 |
var h = 13, m = 7, s = 41; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
33 |
var t = 13 * 3600 + 7* 60 + 41; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
34 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
35 |
var r = IriSP.secondsToTime(t); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
36 |
ok(r.hours === h && r.minutes === m && r.seconds === s, "the converted time is correct"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
37 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
38 |
t = -t; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
39 |
var r = IriSP.secondsToTime(t); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
40 |
ok(r.hours === h && r.minutes === m && r.seconds === s, "the function is immune to negative numbers."); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
41 |
equal(IriSP.secondsToTime(t), "13:07:41"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
42 |
}); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
43 |
|
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
44 |
test("test function to format a tweet", function() { |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
45 |
var input = "@handle @bundle #hashtag http://t.co/11111"; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
46 |
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>"; |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
47 |
equal(IriSP.formatTweet(input), output, "the correct output is given"); |
|
495ef0f3e483
added a toString method to the object returned by IriSP.secondsToTime.
hamidouk
parents:
297
diff
changeset
|
48 |
}); |
| 361 | 49 |
|
50 |
test("test function to convert decimal color to hexadecimal", function() { |
|
51 |
equal(IriSP.DEC_HEXA_COLOR(125), "7D", "first test passes"); |
|
52 |
equal(IriSP.DEC_HEXA_COLOR(24345), "5F19", "second test passes"); |
|
53 |
||
54 |
}); |
|
55 |
} |