aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/ux/templates/templateSpec.js
blob: e75b8068670636e92ad4809bc56afd3e0a1fabe5 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
 * Copyright 2010-2013 Ben Birch
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this software except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
describe("app.ut.byteSize_template", function() {

	describe("byteSize_template()", function() {
		var byteSize_template = window.app.ut.byteSize_template;

		it("should postfix with a B and have not decimal for number less than 1000", function() {
			expect( byteSize_template( 0 ) ).toBe( "0B" );
			expect( byteSize_template( 1 ) ).toBe( "1B" );
			expect( byteSize_template( 10 ) ).toBe( "10B" );
			expect( byteSize_template( 100 ) ).toBe( "100B" );
			expect( byteSize_template( 999 ) ).toBe( "999B" );
		});

		it("should have 0.xxX for values between 1000 and 1023", function() {
			expect( byteSize_template( 1000  ) ).toBe( "0.98ki" );
			expect( byteSize_template( 1024 * 1000 ) ).toBe( "0.98Mi" );
		});

		it("should always have three significant digits", function() {
			expect( byteSize_template( 1023  ) ).toBe( "1.00ki" );
			expect( byteSize_template( 1024  ) ).toBe( "1.00ki" );
			expect( byteSize_template( 1025  ) ).toBe( "1.00ki" );
			expect( byteSize_template( 1024 * 5 ) ).toBe( "5.00ki" );
			expect( byteSize_template( 1024 * 55 ) ).toBe( "55.0ki" );
			expect( byteSize_template( 1024 * 555 ) ).toBe( "555ki" );
		});

		it("should have the correct postfix", function() {
			expect( byteSize_template( 3 * Math.pow( 1024, 1) ) ).toBe( "3.00ki" );
			expect( byteSize_template( 3 * Math.pow( 1024, 2) ) ).toBe( "3.00Mi" );
			expect( byteSize_template( 3 * Math.pow( 1024, 3) ) ).toBe( "3.00Gi" );
			expect( byteSize_template( 3 * Math.pow( 1024, 4) ) ).toBe( "3.00Ti" );
			expect( byteSize_template( 3 * Math.pow( 1024, 5) ) ).toBe( "3.00Pi" );
			expect( byteSize_template( 3 * Math.pow( 1024, 6) ) ).toBe( "3.00Ei" );
			expect( byteSize_template( 3 * Math.pow( 1024, 7) ) ).toBe( "3.00Zi" );
			expect( byteSize_template( 3 * Math.pow( 1024, 8) ) ).toBe( "3.00Yi" );
		});

		it("should show an overflow for stupidly big numbers", function() {
			expect( byteSize_template( 3 * Math.pow( 1024, 10) ) ).toBe( "3.00..E" );
		});
	});

	describe("count_template()", function() {
		var count_template = window.app.ut.count_template;

		it("should not postfix and not decimal for number less than 1000", function() {
			expect( count_template( 0 ) ).toBe( "0" );
			expect( count_template( 1 ) ).toBe( "1" );
			expect( count_template( 10 ) ).toBe( "10" );
			expect( count_template( 100 ) ).toBe( "100" );
			expect( count_template( 999 ) ).toBe( "999" );
		});

		it("should always have three significant digits", function() {
			expect( count_template( 1000  ) ).toBe( "1.00k" );
			expect( count_template( 1005  ) ).toBe( "1.00k" );
			expect( count_template( 1055  ) ).toBe( "1.05k" );
			expect( count_template( 1000 * 5 ) ).toBe( "5.00k" );
			expect( count_template( 1000 * 55 ) ).toBe( "55.0k" );
			expect( count_template( 1000 * 555 ) ).toBe( "555k" );
		});

		it("should have the correct postfix", function() {
			expect( count_template( 3 * Math.pow( 1000, 1) ) ).toBe( "3.00k" );
			expect( count_template( 3 * Math.pow( 1000, 2) ) ).toBe( "3.00M" );
			expect( count_template( 3 * Math.pow( 1000, 3) ) ).toBe( "3.00G" );
			expect( count_template( 3 * Math.pow( 1000, 4) ) ).toBe( "3.00T" );
			expect( count_template( 3 * Math.pow( 1000, 5) ) ).toBe( "3.00P" );
			expect( count_template( 3 * Math.pow( 1000, 6) ) ).toBe( "3.00E" );
			expect( count_template( 3 * Math.pow( 1000, 7) ) ).toBe( "3.00Z" );
			expect( count_template( 3 * Math.pow( 1000, 8) ) ).toBe( "3.00Y" );
		});

		it("should show an overflow for stupidly big numbers", function() {
			expect( count_template( 3 * Math.pow( 1000, 10) ) ).toBe( "3.00..E" );
		});
	});


});