aboutsummaryrefslogtreecommitdiff
path: root/test/index.js
blob: 6bbb0bfbe296e85aa936403a64513dd92cfba106 (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
var should = require('should');
var itoa = require('../');

describe('itoa', function() {
	describe('input types', function() {
		it('should handle string inputs', function() {
			itoa('12').should.equal('twelve');
		});
		it('should handle number inputs', function() {
			itoa(12).should.equal('twelve');
		});
		it('should handle hex inputs (using bignumber.js)', function() {
			itoa('0x10').should.equal('sixteen');
		});
	});

	describe('special cases', function() {
		it('should handle zero', function() {
			itoa('0').should.equal('zero');
		});
		it('should handle negatives', function() {
			itoa('-27').should.equal('negative twenty seven');
		});
	});

	describe('triples', function() {
		it('should handle one-digit numbers', function() {
			itoa('6').should.equal('six');
		});
		it('should handle two-digit numbers like nineteen', function() {
			itoa('19').should.equal('nineteen');
		});
		it('should handle two-digit numbers like thirty six', function() {
			itoa('36').should.equal('thirty six');
		});
		it('should handle two-digit numbers with a zero in the ones place', function() {
			itoa('40').should.equal('forty');
		});
		it('should handle three-digit numbers', function() {
			itoa('274').should.equal('two hundred seventy four');
		});
		it('should handle three-digit numbers with a zero in the tens place', function() {
			itoa('204').should.equal('two hundred four');
		});
		it('should handle three-digit numbers with a zero in the tens and ones place', function() {
			itoa('200').should.equal('two hundred');
		});
	});

	describe('big numbers', function() {
		it('should handle numbers with more than 3 digits', function() {
			itoa('14021').should.equal('fourteen thousand twenty one');
		});
		it('should handle numbers with segments of zeroes', function() {
			itoa('12000001').should.equal('twelve million one');
		});
	});

	describe('using "and"', function() {
		it('should not insert "and" when requested but uneeded', function() {
			itoa('1', true).should.equal('one');
		});
		it('should not insert "and" when requested but uneeded', function() {
			itoa('12', true).should.equal('twelve');
		});
		it('should insert "and" when requested', function() {
			itoa('112', true).should.equal('one hundred and twelve');
		});
		it('should insert "and" when requested in long numbers', function() {
			itoa('12000001', true).should.equal('twelve million and one');
		});
	});
});