-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.html
52 lines (51 loc) · 1.67 KB
/
tests.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!doctype html>
<html>
<head>
<title>number.fmt.js tests</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="number.fmt.js"></script>
<style>
table { border-collapse: collapse; }
td { border: 1px solid #999; padding: 0.5em 1em; }
td.hl { background-color: #ffa; }
td.ok { background-color: #afa; }
td.err { background-color: #faa; }
</style>
<script>
jQuery(function($){
var $tt = $('#tt'),
test = function(){
var args = $.makeArray(arguments),
num = args.shift(),
tst = args.pop(),
str = Number.prototype.fmt.apply(num,args);
$tt.append(['<tr><td>',num.toString(),'</td><td>',args.toString(),'</td><td class="hl">',tst,
'</td><td class="',(str===tst?'ok':'err'),'">',str,'</td></tr>'
].join(''));
};
test(12323435346.236345, "12 323 435 346");
test(12323435346.236345, 1, "12 323 435 346.2");
test(-12323435346.236345, 2, "-12 323 435 346.24");
test(12323435346.236345, 3, 'PLN', ', ', '.', "12.323.435.346, 236 PLN");
test(123234353462363453, 0, '', '.', ' ', 4, "12 3234 3534 6236 3460");
test(12323435, 4, "12 323 435.0000");
test(NaN, "NaN");
test(Infinity, "Infinity");
test(0.123, "0");
test(0.123, 4, "0.1230");
test(0.0123, 4, "0.0123");
test(0.00123, 4, "0.0012");
test(-0.00123, 4, "-0.0012");
test(0, 4, "0.0000");
});
</script>
</head>
<body>
<table>
<thead>
<tr><td>Number</td><td>Arguments</td><td>Expected</td><td>Evaluated</td></tr>
</thead>
<tbody id="tt"></tbody>
</table>
</body>
</html>