1 describe("Ext.Number", function(){
2 var Number = Ext.Number;
4 describe("constraining a number", function(){
5 describe("integers", function(){
6 describe("if the number is within the constaints", function(){
7 it("should leave the number alone if it is equal to the min and the max", function(){
8 expect(Number.constrain(1, 1, 1)).toEqual(1);
11 it("should leave the number alone if it is equal to the min", function(){
12 expect(Number.constrain(1, 1, 5)).toEqual(1);
15 it("should leave the number alone if it is equal to the max", function(){
16 expect(Number.constrain(5, 1, 5)).toEqual(5);
19 it("should leave the number alone if it is within the min and the max", function(){
20 expect(Number.constrain(3, 1, 5)).toEqual(3);
23 it("should leave a negative number alone if it is within the min and the max", function(){
24 expect(Number.constrain(-3, -5, -1)).toEqual(-3);
28 describe("if the number is not within the constraints", function(){
29 it("should make the number equal to the min value", function(){
30 expect(Number.constrain(1, 3, 5)).toEqual(3);
33 it("should make the number equal to the max value", function(){
34 expect(Number.constrain(100, 1, 5)).toEqual(5);
37 describe("and the number is negative", function(){
38 it("should make the number equal to the min value", function(){
39 expect(Number.constrain(-10, -50, -30)).toEqual(-30);
42 it("should make the number equal to the max value", function(){
43 expect(Number.constrain(-100, -50, -30)).toEqual(-50);
49 describe("floating point numbers", function(){
50 describe("if the number is within the constaints", function(){
51 it("should leave the number alone", function(){
52 expect(Number.constrain(3.3, 3.1, 3.5)).toEqual(3.3);
55 it("should leave a negative number alone", function(){
56 expect(Number.constrain(-3.3, -3.5, -3.1)).toEqual(-3.3);
60 describe("and the number is negative", function(){
61 it("should make the number equal to the min value", function(){
62 expect(Number.constrain(-3.3, -3.1, -3)).toEqual(-3.1);
65 it("should make the number equal to the max value", function(){
66 expect(Number.constrain(-2.1, -3.1, -3)).toEqual(-3);
72 describe("toFixed", function(){
74 var f = Number.toFixed;
76 it("should return a string", function(){
77 expect(typeof f(1)).toEqual('string');
80 it("should default precision to 0", function(){
81 expect(f(1.23456)).toEqual('1');
84 it("should output the correct number of decimal places", function(){
85 expect(f(1, 3)).toEqual('1.000');
88 it("should round correctly", function(){
89 expect(f(1.9834657, 1)).toEqual('2.0');
92 it("should round with negative numbers", function(){
93 expect(f(-3.4265, 2)).toEqual('-3.43');