This repository was archived by the owner on Dec 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 504
Expand file tree
/
Copy pathbyte-format.js
More file actions
54 lines (41 loc) · 1.51 KB
/
Copy pathbyte-format.js
File metadata and controls
54 lines (41 loc) · 1.51 KB
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
var expect = require('chai').expect;
var byteFormat = require('../../solutions/javascript/byte-format');
describe('Byte format', function() {
it('should show B format', function() {
expect(byteFormat(1022)).to.equal('1022 B');
});
it('should show KB format', function() {
expect(byteFormat(10221)).to.equal('9.99 KB');
});
it('should show KB format rounded to 3 digital', function() {
expect(byteFormat(10221, 3)).to.equal('9.982 KB');
});
it('should show MB format', function() {
expect(byteFormat(1022932324)).to.equal('975.55 MB');
});
it('should show GB format', function() {
expect(byteFormat(1022932123237)).to.equal('952.68 GB');
});
it('should show TB format', function() {
expect(byteFormat(1022932453333234)).to.equal('930.36 TB');
});
it('should show PB format', function() {
expect(byteFormat(1022932453333234444)).to.equal('908.55 PB');
});
it('should show EB format', function() {
expect(byteFormat(1022932453333234444324)).to.equal('887.26 EB');
});
it('should show ZB format', function() {
expect(byteFormat(1022932453333234444324454)).to.equal('866.46 ZB');
});
it('should show YB format', function() {
expect(byteFormat(10243245333323444432445431)).to.equal('8.48 YB');
});
it('should show YB format when number larger than 1024YB', function() {
var result = byteFormat(232932453333234444324454333424324);
expect(result).to.equal('192677209.44 YB');
});
it('should not show any decimals', function () {
expect(byteFormat(9999, 0)).to.equal('10 KB');
});
});