unittests/tests/utils.js
author hamidouk
Wed, 16 Nov 2011 11:40:57 +0100
branchpopcorn-port
changeset 253 95c6b77f005e
parent 252 fd84e0fb26d8
child 254 cafaa694b709
permissions -rw-r--r--
added more test for utility functions.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
     4
  test("test a function to preserve the scope of a method in a callback", function() {
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
     5
    var obj = { a : 2};
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
     6
    obj.b = function(e, f) { 
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
     7
      equal(this.a, 2, "the scope is preserved");
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
     8
      equal(e, 1, "arg 1 passed correctly");
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
     9
      equal(f, 2, "arg 2 passed correctly");
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    10
    };
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    11
    
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    12
    (IriSP.wrap(obj, obj.b))(1, 2);
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    13
  
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    14
  });
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    15
  
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    16
  test("test function to convert a ratio to a percentage", function() {
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    17
    var time = 2;
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    18
    var total = 3;
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    19
    
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    20
    equal(IriSP.timeToPourcent(2, 3), 66, "the function returns the correct result");    
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    21
    
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    22
    var total = -total;    
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    23
    
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    24
    equal(IriSP.timeToPourcent(2, 3), 66, "the function is immune to negative numbers");            
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    25
  });
95c6b77f005e added more test for utility functions.
hamidouk
parents: 252
diff changeset
    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
}