Passed
Branch master (b8a2ae)
by Samson
02:23
created

eezify_build_process()ꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 15
rs 9.95
c 0
b 0
f 0
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
describe('GeezifyTest', function () {
10
11
    describe('#test_random_numbers()', function () {
12
        it('should convert random ascii number to geez and back to the original', function () {
13
            let $geezify = Geezify.create();
14
15
            for (let $i = 0; $i < 10000; $i++) {
16
                let $random_number = Math.floor(Math.random() * 9999999999);
17
18
                let $geez_number = $geezify.toGeez($random_number);
19
                let $ascii_number = $geezify.toAscii($geez_number);
20
21
                assert.equal($random_number, $ascii_number);
22
            }
23
        });
24
    });
25
26
    describe('#test_geezify_build_process()', function () {
27
        it('should use provided ascii and geez number converters', function () {
28
            let $geez = new GeezConverter();
29
            let $ascii = new AsciiConverter();
30
31
            sinon.stub($geez, 'convert').withArgs(123).returns('giber gaber');
32
            sinon.stub($ascii, 'convert').withArgs('lorem ipsum').returns(321);
33
34
            let $geezify = new Geezify($geez, $ascii);
35
36
            // assert the response
37
            assert.equal(321, $geezify.toAscii('lorem ipsum'));
38
            assert.equal('giber gaber', $geezify.toGeez(123));
39
        });
40
    });
41
42
    describe('#test_setter_and_getters()', function () {
43
        it('should be able to substitute implementations', function () {
44
            let $geezify = Geezify.create();
45
46
            let $geez_dummy = sinon.createStubInstance(GeezConverter);
47
            let $ascii_dummy = sinon.createStubInstance(AsciiConverter);
48
49
            $geezify.setGeezConverter($geez_dummy);
50
            $geezify.setAsciiConverter($ascii_dummy);
51
52
            assert.equal($geez_dummy, $geezify.getGeezConverter());
53
            assert.equal($ascii_dummy, $geezify.getAsciiConverter());
54
        });
55
    });
56
57
});
58