| 1 |
dojo.provide("dojox.math.tests.round"); |
| 2 |
dojo.require("dojox.math.round"); |
| 3 |
|
| 4 |
tests.register("dojox.math.tests.round", |
| 5 |
[ |
| 6 |
{ |
| 7 |
name: "round", |
| 8 |
runTest: function(t){ |
| 9 |
t.is(0, dojox.math.round(0)); |
| 10 |
t.is(1, dojox.math.round(0.5)); |
| 11 |
t.is(-1, dojox.math.round(-0.5)); |
| 12 |
t.is(0.1, dojox.math.round(0.05, 1)); |
| 13 |
t.is(-0.1, dojox.math.round(-0.05, 1)); |
| 14 |
t.is(1.1, dojox.math.round(1.05, 1)); |
| 15 |
t.is(-1.1, dojox.math.round(-1.05, 1)); |
| 16 |
t.is(-162.3, dojox.math.round(-162.295, 2)); |
| 17 |
t.is(162.3, dojox.math.round(162.295, 2)); |
| 18 |
} |
| 19 |
}, |
| 20 |
{ |
| 21 |
name: "round_multiple", |
| 22 |
runTest: function(t){ |
| 23 |
t.is("123.455", dojox.math.round(123.4525, 2, 5)); |
| 24 |
t.is("123.45", dojox.math.round(123.452, 2, 5)); |
| 25 |
t.is("123.455", dojox.math.round(123.454, 2, 5)); |
| 26 |
t.is("123.455", dojox.math.round(123.456, 2, 5)); |
| 27 |
t.is("-123.45", dojox.math.round(-123.452, 2, 5)); |
| 28 |
t.is("-123.455", dojox.math.round(-123.4525, 2, 5)); |
| 29 |
t.is("-123.455", dojox.math.round(-123.454, 2, 5)); |
| 30 |
t.is("-123.455", dojox.math.round(-123.456, 2, 5)); |
| 31 |
} |
| 32 |
}, |
| 33 |
{ |
| 34 |
name: "round_speleotrove", |
| 35 |
runTest: function(t){ |
| 36 |
|
| 37 |
t.is(12345, dojox.math.round(12345 + -0.1), "radx200"); |
| 38 |
t.is(12345, dojox.math.round(12345 + -0.01), "radx201"); |
| 39 |
t.is(12345, dojox.math.round(12345 + -0.001), "radx202"); |
| 40 |
t.is(12345, dojox.math.round(12345 + -0.00001), "radx203"); |
| 41 |
t.is(12345, dojox.math.round(12345 + -0.000001), "radx204"); |
| 42 |
t.is(12345, dojox.math.round(12345 + -0.0000001), "radx205"); |
| 43 |
t.is(12345, dojox.math.round(12345 + 0), "radx206"); |
| 44 |
t.is(12345, dojox.math.round(12345 + 0.0000001), "radx207"); |
| 45 |
t.is(12345, dojox.math.round(12345 + 0.000001), "radx208"); |
| 46 |
t.is(12345, dojox.math.round(12345 + 0.00001), "radx209"); |
| 47 |
t.is(12345, dojox.math.round(12345 + 0.0001), "radx210"); |
| 48 |
t.is(12345, dojox.math.round(12345 + 0.001), "radx211"); |
| 49 |
t.is(12345, dojox.math.round(12345 + 0.01), "radx212"); |
| 50 |
t.is(12345, dojox.math.round(12345 + 0.1), "radx213"); |
| 51 |
|
| 52 |
t.is(12346, dojox.math.round(12346 + 0.49999), "radx215"); |
| 53 |
t.is(12347, dojox.math.round(12346 + 0.5), "radx216"); |
| 54 |
t.is(12347, dojox.math.round(12346 + 0.50001), "radx217"); |
| 55 |
|
| 56 |
t.is(12345, dojox.math.round(12345 + 0.4), "radx220"); |
| 57 |
t.is(12345, dojox.math.round(12345 + 0.49), "radx221"); |
| 58 |
t.is(12345, dojox.math.round(12345 + 0.499), "radx222"); |
| 59 |
t.is(12345, dojox.math.round(12345 + 0.49999), "radx223"); |
| 60 |
t.is(12346, dojox.math.round(12345 + 0.5), "radx224"); |
| 61 |
t.is(12346, dojox.math.round(12345 + 0.50001), "radx225"); |
| 62 |
t.is(12346, dojox.math.round(12345 + 0.5001), "radx226"); |
| 63 |
t.is(12346, dojox.math.round(12345 + 0.501), "radx227"); |
| 64 |
t.is(12346, dojox.math.round(12345 + 0.51), "radx228"); |
| 65 |
t.is(12346, dojox.math.round(12345 + 0.6), "radx229"); |
| 66 |
|
| 67 |
|
| 68 |
t.is(-12345, dojox.math.round(-12345 + -0.1), "rsux200"); |
| 69 |
t.is(-12345, dojox.math.round(-12345 + -0.01), "rsux201"); |
| 70 |
t.is(-12345, dojox.math.round(-12345 + -0.001), "rsux202"); |
| 71 |
t.is(-12345, dojox.math.round(-12345 + -0.00001), "rsux203"); |
| 72 |
t.is(-12345, dojox.math.round(-12345 + -0.000001), "rsux204"); |
| 73 |
t.is(-12345, dojox.math.round(-12345 + -0.0000001), "rsux205"); |
| 74 |
t.is(-12345, dojox.math.round(-12345 + 0), "rsux206"); |
| 75 |
t.is(-12345, dojox.math.round(-12345 + 0.0000001), "rsux207"); |
| 76 |
t.is(-12345, dojox.math.round(-12345 + 0.000001), "rsux208"); |
| 77 |
t.is(-12345, dojox.math.round(-12345 + 0.00001), "rsux209"); |
| 78 |
t.is(-12345, dojox.math.round(-12345 + 0.0001), "rsux210"); |
| 79 |
t.is(-12345, dojox.math.round(-12345 + 0.001), "rsux211"); |
| 80 |
t.is(-12345, dojox.math.round(-12345 + 0.01), "rsux212"); |
| 81 |
t.is(-12345, dojox.math.round(-12345 + 0.1), "rsux213"); |
| 82 |
|
| 83 |
t.is(-12346, dojox.math.round(-12346 + 0.49999), "rsux215"); |
| 84 |
t.is(-12346, dojox.math.round(-12346 + 0.5), "rsux216"); |
| 85 |
t.is(-12345, dojox.math.round(-12346 + 0.50001 ), "rsux217"); |
| 86 |
|
| 87 |
t.is(-12345, dojox.math.round(-12345 + 0.4), "rsux220"); |
| 88 |
t.is(-12345, dojox.math.round(-12345 + 0.49), "rsux221"); |
| 89 |
t.is(-12345, dojox.math.round(-12345 + 0.499), "rsux222"); |
| 90 |
t.is(-12345, dojox.math.round(-12345 + 0.49999), "rsux223"); |
| 91 |
t.is(-12345, dojox.math.round(-12345 + 0.5), "rsux224"); |
| 92 |
t.is(-12344, dojox.math.round(-12345 + 0.50001), "rsux225"); |
| 93 |
t.is(-12344, dojox.math.round(-12345 + 0.5001), "rsux226"); |
| 94 |
t.is(-12344, dojox.math.round(-12345 + 0.501), "rsux227"); |
| 95 |
t.is(-12344, dojox.math.round(-12345 + 0.51), "rsux228"); |
| 96 |
t.is(-12344, dojox.math.round(-12345 + 0.6), "rsux229"); |
| 97 |
|
| 98 |
t.is(12345, dojox.math.round( 12345 / 1), "rdvx401"); |
| 99 |
t.is(12344, dojox.math.round( 12345 / 1.0001), "rdvx402"); |
| 100 |
t.is(12333, dojox.math.round( 12345 / 1.001), "rdvx403"); |
| 101 |
t.is(12223, dojox.math.round( 12345 / 1.01), "rdvx404"); |
| 102 |
t.is(11223, dojox.math.round( 12345 / 1.1), "rdvx405"); |
| 103 |
|
| 104 |
t.is(3088.8, dojox.math.round( 12355 / 4, 1), "rdvx406"); |
| 105 |
t.is(3086.3, dojox.math.round( 12345 / 4, 1), "rdvx407"); |
| 106 |
t.is(3088.7, dojox.math.round( 12355 / 4.0001, 1), "rdvx408"); |
| 107 |
t.is(3086.2, dojox.math.round( 12345 / 4.0001, 1), "rdvx409"); |
| 108 |
t.is(2519.4, dojox.math.round( 12345 / 4.9, 1), "rdvx410"); |
| 109 |
t.is(2473.9, dojox.math.round( 12345 / 4.99, 1), "rdvx411"); |
| 110 |
t.is(2469.5, dojox.math.round( 12345 / 4.999, 1), "rdvx412"); |
| 111 |
t.is(2469.0, dojox.math.round( 12345 / 4.9999, 1), "rdvx413"); |
| 112 |
t.is(2469, dojox.math.round( 12345 / 5, 1), "rdvx414"); |
| 113 |
t.is(2469.0, dojox.math.round( 12345 / 5.0001, 1), "rdvx415"); |
| 114 |
t.is(2468.5, dojox.math.round( 12345 / 5.001, 1), "rdvx416"); |
| 115 |
t.is(2464.1, dojox.math.round( 12345 / 5.01, 1), "rdvx417"); |
| 116 |
t.is(2420.6, dojox.math.round( 12345 / 5.1, 1), "rdvx418"); |
| 117 |
|
| 118 |
t.is(12345, dojox.math.round( 12345 * 1), "rmux401"); |
| 119 |
t.is(12346, dojox.math.round( 12345 * 1.0001), "rmux402"); |
| 120 |
t.is(12357, dojox.math.round( 12345 * 1.001), "rmux403"); |
| 121 |
t.is(12468, dojox.math.round( 12345 * 1.01), "rmux404"); |
| 122 |
t.is(13580, dojox.math.round( 12345 * 1.1), "rmux405"); |
| 123 |
t.is(49380, dojox.math.round( 12345 * 4), "rmux406"); |
| 124 |
t.is(49381, dojox.math.round( 12345 * 4.0001), "rmux407"); |
| 125 |
t.is(60491, dojox.math.round( 12345 * 4.9), "rmux408"); |
| 126 |
t.is(61602, dojox.math.round( 12345 * 4.99), "rmux409"); |
| 127 |
t.is(61713, dojox.math.round( 12345 * 4.999), "rmux410"); |
| 128 |
t.is(61724, dojox.math.round( 12345 * 4.9999), "rmux411"); |
| 129 |
t.is(61725, dojox.math.round( 12345 * 5), "rmux412"); |
| 130 |
t.is(61726, dojox.math.round( 12345 * 5.0001), "rmux413"); |
| 131 |
t.is(61737, dojox.math.round( 12345 * 5.001), "rmux414"); |
| 132 |
t.is(61848, dojox.math.round( 12345 * 5.01), "rmux415"); |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
} |
| 140 |
} |
| 141 |
] |
| 142 |
); |