9 describe("Number Methods", function(){
13 it('should convert a number to an integer', function(){
14 expect((111).toInt()).toEqual(111);
17 it('should convert a number depending on the radix provided', function(){
18 expect((111).toInt(2)).toEqual(7);
19 expect((0x16).toInt(10)).toEqual(22); //ECMA standard, radix is optional so if starts with 0x then parsed as hexadecimal
20 expect((016).toInt(10)).toEqual(14); //ECMA standard, radix is optional so if starts with 0 then parsed as octal
25 it('should convert a number to a float', function(){
26 expect((1.00).toFloat()).toEqual(1);
27 expect((1.12 - 0.12).toFloat()).toEqual(1);
28 expect((0.0010).toFloat()).toEqual(0.001);
29 expect((Number.MIN_VALUE).toFloat()).toEqual(Number.MIN_VALUE);
34 it('should limit a number within a range', function(){
35 expect((-1).limit(0, 1)).toEqual(0);
36 expect((3).limit(1, 2)).toEqual(2);
39 it('should not limit a number if within the range', function(){
40 expect((2).limit(0,4)).toEqual(2);
45 it('should round a number to the nearest whole number if units place is not specified', function(){
46 expect((0.01).round()).toEqual(0);
49 it('should round a number according the units place specified', function(){
50 expect((0.01).round(2)).toEqual(0.01);
51 expect((1).round(3)).toEqual(1);
52 expect((-1.01).round()).toEqual(-1);
53 expect((-1.01).round(2)).toEqual(-1.01);
54 expect((111).round(-1)).toEqual(110);
55 expect((-111).round(-2)).toEqual(-100);
56 expect((100).round(-5)).toEqual(0);
61 it('should call the function for the specified number of times', function(){
63 (3).times(function(i){
68 (0).times(function(i){
72 expect(found).toEqual(2);
73 expect(found2).toEqual(-1);
76 it('should bind and call the function for the specified number of times', function(){
79 (1).times(function(i){
80 found3 = (this == aTest);
82 expect(found3).toBeTruthy();
90 describe('Number Math Methods', function(){
91 Object.each(math, function(value, key){
93 var b = value.test[1];
94 it('should return the ' + value.title + ' value of the number' + ((b) ? ' and the passed number' : ''), function(){
95 expect(value.test[0][key](b)).toEqual(Math[key].apply(null, value.test));
101 abs: { test: [-1], title: 'absolute' },
102 acos: { test: [0], title: 'arc cosine' },
103 asin: { test: [0.5], title: 'arc sine' },
104 atan: { test: [0.5], title: 'arc tangent' },
105 atan2: { test: [0.1, 0.5], title: 'arc tangent' },
106 ceil: { test: [0.6], title: 'number closest to and not less than the' },
107 cos: { test: [30], title: 'cosine' },
108 exp: { test: [2], title: 'exponent' },
109 floor: { test: [2.4], title: 'integer closet to and not greater than' },
110 log: { test: [2], title: 'log' },
111 max: { test: [5, 3], title: 'maximum' },
112 min: { test: [-4, 2], title: 'minimum' },
113 pow: { test: [2, 2], title: 'power' },
114 sin: { test: [0.5], title: 'sine' },
115 sqrt: { test: [4], title: 'square root' },
116 tan: { test: [0.3], title: 'tangent' }