-
Notifications
You must be signed in to change notification settings - Fork 0
/
CastleBuilderControllerTests.js
63 lines (44 loc) · 1.91 KB
/
CastleBuilderControllerTests.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
'use strict';
describe('Castle Company Test suit', function () {
describe('Castle Builder Controller Tests', function () {
var $scope;
beforeEach(module('CastleCompany'));
beforeEach(inject(function ($rootScope, $controller) {
$scope = $rootScope.$new();
$controller('CastleBuilderController', {
$scope: $scope
});
}));
it('should return the array without consecutive duplicate values', function () {
var array = [1, 2, 2, 3, 4, 4];
expect($scope.removeConsecutiveDuplicates(array)).toEqual([1, 2, 3, 4]);
});
describe('Build Castles', function () {
it('should set castles to 0 if no data is defined', function () {
$scope.buildCastles();
expect($scope.castles).toEqual(0);
});
it('should set castles to 1 if the input array is length 1', function () {
$scope.heights = [999];
$scope.buildCastles();
expect($scope.castles).toEqual(1);
});
it('should set castles to 2 if the input array has only one peak or valley', function () {
$scope.heights = [1, 2, 1];
$scope.buildCastles();
expect($scope.castles).toEqual(2);
$scope.heights = [2, 1, 2];
$scope.buildCastles();
expect($scope.castles).toEqual(2);
});
it('should only count a peak or a valley once when its represented by consecutive equal integers', function () {
$scope.heights = [1, 2, 2, 2, 2, 1];
$scope.buildCastles();
expect($scope.castles).toEqual(2);
$scope.heights = [2, 1, 1, 1, 1, 2];
$scope.buildCastles();
expect($scope.castles).toEqual(2);
});
});
});
});