GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch master (b787eb)
by Joss
02:22 queued 56s
created

test/mower.js   A

Complexity

Total Complexity 26
Complexity/F 1

Size

Lines of Code 98
Function Count 26

Duplication

Duplicated Lines 64
Ratio 65.31 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 64
loc 98
rs 10
wmc 26
mnd 0
bc 26
fnc 26
bpm 1
cpm 1
noi 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
'use strict';
2
3
var expect = require('expect.js');
4
5
var Position = require('../lib/position');
6
var Grid = require('../lib/grid');
7
var Mower = require('../lib/mower');
8
9
describe('Mower', function() {
10 View Code Duplication
    describe('start', function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
        var grid = new Grid(new Position({x:5,y:5}, 'N'));
12
        it('should stop at positon 1 3 N', function (done) {
13
            var position = new Position({x:1,y:2}, 'N'),
14
                mower = new Mower(0, grid, position, ['G','A','G','A','G','A','G','A','A']);
15
            mower.start().then(function(mowerUpdated) {
16
                expect(mowerUpdated.position).to.eql({ x:1, y:3, c:'N' });
17
                done();
18
            });
19
        });
20
        it('should stop at positon 4 1 E', function (done) {
21
            var position = new Position({x:3,y:3}, 'E'),
22
                mower = new Mower(0, grid, position, ['A','D','A','A','D','A','D','D','A']);
23
            mower.start().then(function(mowerUpdated) {
24
                expect(mowerUpdated.position).to.eql({ x:4, y:1, c:'E' });
25
                done();
26
            });
27
        });
28
        it('should stop at positon 5 4 N', function (done) {
29
            var position = new Position({x:5,y:2}, 'S'),
30
                mower = new Mower(0, grid, position, ['A','G','A','G','A','A','D','A','G','A']);
31
            mower.start().then(function(mowerUpdated) {
32
                expect(mowerUpdated.position).to.eql({ x:5, y:4, c:'N' });
33
                done();
34
            });
35
        });
36
37
    });
38 View Code Duplication
    describe('runStep', function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
39
        var grid = new Grid(new Position({x:10,y:10}, 'N'));
40
        it('should stop at positon 3 2 E', function (done) {
41
            var position = new Position({x:2,y:2}, 'E');
42
            var mower = new Mower(0, grid, position, ['A']);
43
            mower.runStep(0,function(mowerUpdated) {
44
                expect(mowerUpdated.position).to.eql({ x:3, y:2, c:'E' });
45
                done();
46
            });
47
        });
48
        it('should stop at positon 1 2 W', function (done) {
49
            var position = new Position({x:2,y:2}, 'W'),
50
                mower = new Mower(0, grid, position, ['A']);
51
            mower.runStep(0,function(mowerUpdated) {
52
                expect(mowerUpdated.position).to.eql({ x:1, y:2, c:'W' });
53
                done();
54
            });
55
        });
56
        it('should stop at positon 2 3 N', function (done) {
57
            var position = new Position({x:2,y:2}, 'N'),
58
                mower = new Mower(0, grid, position, ['A']);
59
            mower.runStep(0,function(mowerUpdated) {
60
                expect(mowerUpdated.position).to.eql({ x:2, y:3, c:'N' });
61
                done();
62
            });
63
        });
64
        it('should stop at positon 2 1 S', function (done) {
65
            var position = new Position({x:2,y:2}, 'S'),
66
                mower = new Mower(0, grid, position, ['A']);
67
            mower.runStep(0,function(mowerUpdated) {
68
                expect(mowerUpdated.position).to.eql({ x:2, y:1, c:'S' });
69
                done();
70
            });
71
        });
72
73
    });
74
    describe('isValid', function () {
75
        var grid = new Grid(new Position({x:8,y:8}, 'N')),
76
            position = new Position({x:3,y:3}, 'E');
77
        it('should throw an error when ID is not valid', function () {
78
            expect(function() {
79
                new Mower(false, grid, position, ['A']);
80
            }).to.throwException(/Id is not valid/);
81
        });
82
        it('should throw an error when GRID is not valid', function () {
83
            expect(function() {
84
                new Mower(0, false, position, ['A']);
85
            }).to.throwException(/Grid is not valid/);
86
        });
87
        it('should throw an error when POSITION is not valid', function () {
88
            expect(function() {
89
                new Mower(0, grid, false, ['A']);
90
            }).to.throwException(/Position is not valid/);
91
        });
92
        it('should throw an error when INSTRUCTIONS are not valid', function () {
93
            expect(function() {
94
                new Mower(0, grid, position, false);
95
            }).to.throwException(/Instructions are not valid/);
96
        });
97
    });
98
});