-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnumbers.js
156 lines (131 loc) · 5.73 KB
/
numbers.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import inspect from '../lib/index.js'
import { expect } from 'chai'
describe('numbers', () => {
it('returns number as passed in', () => {
expect(inspect(3.141)).to.equal('3.141')
})
it('returns 0 as +0', () => {
expect(inspect(0)).to.equal('+0')
})
it('returns -0 as -0', () => {
expect(inspect(-0)).to.equal('-0')
})
it('uses scientific notation where possible', () => {
expect(inspect(1e300)).to.equal('1e+300')
})
describe('colors', () => {
it('returns string with yellow color, if colour is set to true', () => {
expect(inspect(3.141, { colors: true })).to.equal('\u001b[33m3.141\u001b[39m')
})
})
describe('truncate', () => {
it('returns the full representation when truncate is over string length', () => {
expect(inspect(3.141592654, { truncate: 11 })).to.equal('3.141592654')
})
it('truncates numbers longer than truncate (10)', () => {
expect(inspect(3.141592654, { truncate: 10 })).to.equal('3.1415926…')
})
it('truncates numbers longer than truncate (9)', () => {
expect(inspect(3.141592654, { truncate: 9 })).to.equal('3.141592…')
})
it('truncates numbers longer than truncate (8)', () => {
expect(inspect(3.141592654, { truncate: 8 })).to.equal('3.14159…')
})
it('truncates numbers longer than truncate (7)', () => {
expect(inspect(3.141592654, { truncate: 7 })).to.equal('3.1415…')
})
it('truncates numbers longer than truncate (6)', () => {
expect(inspect(3.141592654, { truncate: 6 })).to.equal('3.141…')
})
it('truncates numbers longer than truncate (5)', () => {
expect(inspect(3.141592654, { truncate: 5 })).to.equal('3.14…')
})
it('truncates numbers longer than truncate (4)', () => {
expect(inspect(3.141592654, { truncate: 4 })).to.equal('3.1…')
})
it('truncates numbers longer than truncate (3)', () => {
expect(inspect(3.141592654, { truncate: 3 })).to.equal('3.…')
})
it('truncates numbers longer than truncate (2)', () => {
expect(inspect(3.141592654, { truncate: 2 })).to.equal('3…')
})
it('truncates numbers longer than truncate (1)', () => {
expect(inspect(3.141592654, { truncate: 1 })).to.equal('…')
})
it('disregards truncate when it cannot truncate further (0)', () => {
expect(inspect(3.141592654, { truncate: 0 })).to.equal('…')
})
it('does not truncate if tail is same length as value', () => {
expect(inspect(3, { truncate: 0 })).to.equal('3')
})
})
describe('NaN', () => {
it('returns `NaN`', () => {
expect(inspect(NaN)).to.equal('NaN')
})
describe('colors', () => {
it('returns string with yellow color, if colour is set to true', () => {
expect(inspect(NaN, { colors: true })).to.equal('\u001b[33mNaN\u001b[39m')
})
})
describe('truncate', () => {
it('returns the full string representation regardless of truncate', () => {
expect(inspect(NaN, { truncate: 9 })).to.equal('NaN')
expect(inspect(NaN, { truncate: 8 })).to.equal('NaN')
expect(inspect(NaN, { truncate: 7 })).to.equal('NaN')
expect(inspect(NaN, { truncate: 6 })).to.equal('NaN')
expect(inspect(NaN, { truncate: 5 })).to.equal('NaN')
expect(inspect(NaN, { truncate: 4 })).to.equal('NaN')
expect(inspect(NaN, { truncate: 3 })).to.equal('NaN')
expect(inspect(NaN, { truncate: 2 })).to.equal('NaN')
expect(inspect(NaN, { truncate: 1 })).to.equal('NaN')
})
})
})
describe('Infinity', () => {
it('returns `Infinity`', () => {
expect(inspect(Infinity)).to.equal('Infinity')
})
describe('colors', () => {
it('returns string with yellow color, if colour is set to true', () => {
expect(inspect(Infinity, { colors: true })).to.equal('\u001b[33mInfinity\u001b[39m')
})
})
describe('truncate', () => {
it('returns the full string representation regardless of truncate', () => {
expect(inspect(Infinity, { truncate: 9 })).to.equal('Infinity')
expect(inspect(Infinity, { truncate: 8 })).to.equal('Infinity')
expect(inspect(Infinity, { truncate: 7 })).to.equal('Infinity')
expect(inspect(Infinity, { truncate: 6 })).to.equal('Infinity')
expect(inspect(Infinity, { truncate: 5 })).to.equal('Infinity')
expect(inspect(Infinity, { truncate: 4 })).to.equal('Infinity')
expect(inspect(Infinity, { truncate: 3 })).to.equal('Infinity')
expect(inspect(Infinity, { truncate: 2 })).to.equal('Infinity')
expect(inspect(Infinity, { truncate: 1 })).to.equal('Infinity')
})
})
})
describe('-Infinity', () => {
it('returns `-Infinity`', () => {
expect(inspect(-Infinity)).to.equal('-Infinity')
})
describe('colors', () => {
it('returns string with yellow color, if colour is set to true', () => {
expect(inspect(-Infinity, { colors: true })).to.equal('\u001b[33m-Infinity\u001b[39m')
})
})
describe('truncate', () => {
it('returns the full string representation regardless of truncate', () => {
expect(inspect(-Infinity, { truncate: 9 })).to.equal('-Infinity')
expect(inspect(-Infinity, { truncate: 8 })).to.equal('-Infinity')
expect(inspect(-Infinity, { truncate: 7 })).to.equal('-Infinity')
expect(inspect(-Infinity, { truncate: 6 })).to.equal('-Infinity')
expect(inspect(-Infinity, { truncate: 5 })).to.equal('-Infinity')
expect(inspect(-Infinity, { truncate: 4 })).to.equal('-Infinity')
expect(inspect(-Infinity, { truncate: 3 })).to.equal('-Infinity')
expect(inspect(-Infinity, { truncate: 2 })).to.equal('-Infinity')
expect(inspect(-Infinity, { truncate: 1 })).to.equal('-Infinity')
})
})
})
})