1
|
|
|
const assert = require('assert'); |
2
|
|
|
|
3
|
|
|
const sinon = require('sinon'); |
4
|
|
|
|
5
|
|
|
const Geezify = require('../src/Geezify'); |
6
|
|
|
const GeezConverter = require('../src/Converter/GeezConverter'); |
7
|
|
|
const AsciiConverter = require('../src/Converter/AsciiConverter'); |
8
|
|
|
|
9
|
|
|
/* global describe, it */ |
10
|
|
|
|
11
|
|
|
describe('GeezifyTest', () => { |
12
|
|
|
describe('#test_random_numbers()', () => { |
13
|
|
|
it('should convert random ascii number to geez and back to the original', () => { |
14
|
|
|
const $geezify = Geezify.create(); |
15
|
|
|
|
16
|
|
|
for (let $i = 0; $i < 10000; $i += 1) { |
17
|
|
|
const $random_number = Math.floor(Math.random() * 9999999999); |
18
|
|
|
|
19
|
|
|
const $geez_number = $geezify.toGeez($random_number); |
20
|
|
|
const $ascii_number = $geezify.toAscii($geez_number); |
21
|
|
|
|
22
|
|
|
assert.equal($random_number, $ascii_number); |
23
|
|
|
} |
24
|
|
|
}); |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
describe('#test_geezify_build_process()', () => { |
28
|
|
|
it('should use provided ascii and geez number converters', () => { |
29
|
|
|
const $geez = new GeezConverter(); |
30
|
|
|
const $ascii = new AsciiConverter(); |
31
|
|
|
|
32
|
|
|
sinon |
33
|
|
|
.stub($geez, 'convert') |
34
|
|
|
.withArgs(123) |
35
|
|
|
.returns('giber gaber'); |
36
|
|
|
sinon |
37
|
|
|
.stub($ascii, 'convert') |
38
|
|
|
.withArgs('lorem ipsum') |
39
|
|
|
.returns(321); |
40
|
|
|
|
41
|
|
|
const $geezify = new Geezify($geez, $ascii); |
42
|
|
|
|
43
|
|
|
// assert the response |
44
|
|
|
assert.equal(321, $geezify.toAscii('lorem ipsum')); |
45
|
|
|
assert.equal('giber gaber', $geezify.toGeez(123)); |
46
|
|
|
}); |
47
|
|
|
}); |
48
|
|
|
|
49
|
|
|
describe('#test_setter_and_getters()', () => { |
50
|
|
|
it('should be able to substitute implementations', () => { |
51
|
|
|
const $geezify = Geezify.create(); |
52
|
|
|
|
53
|
|
|
const $geez_dummy = sinon.createStubInstance(GeezConverter); |
54
|
|
|
const $ascii_dummy = sinon.createStubInstance(AsciiConverter); |
55
|
|
|
|
56
|
|
|
$geezify.setGeezConverter($geez_dummy); |
57
|
|
|
$geezify.setAsciiConverter($ascii_dummy); |
58
|
|
|
|
59
|
|
|
assert.equal($geez_dummy, $geezify.getGeezConverter()); |
60
|
|
|
assert.equal($ascii_dummy, $geezify.getAsciiConverter()); |
61
|
|
|
}); |
62
|
|
|
}); |
63
|
|
|
}); |
64
|
|
|
|