fixed fib sum, it was doing the sum for lenght + 1
[tech-radar.git] / test / models / radar-spec.js
1 describe('tr.models.Radar', function () {
2
3 it('has no quadrants by default', function () {
4 radar = new tr.models.Radar();
5
6 expect(radar.quadrants().I).toBe(null);
7 expect(radar.quadrants().II).toBe(null);
8 expect(radar.quadrants().III).toBe(null);
9 expect(radar.quadrants().IV).toBe(null);
10 });
11
12 it('sets the first quadrant', function () {
13 var quadrant, radar, blip;
14
15 blip = new tr.models.Blip('A', new tr.models.Cycle('First'));
16 quadrant = new tr.models.Quadrant('First');
17 quadrant.add([blip]);
18 radar = new tr.models.Radar();
19
20 radar.setFirstQuadrant(quadrant);
21
22 expect(radar.quadrants().I).toEqual(quadrant);
23 expect(radar.quadrants().I.blips()[0].number()).toEqual(1);
24 });
25
26 it('sets the second quadrant', function () {
27 var quadrant, radar, blip;
28
29 blip = new tr.models.Blip('A', new tr.models.Cycle('First'));
30 quadrant = new tr.models.Quadrant('Second');
31 quadrant.add([blip]);
32 radar = new tr.models.Radar();
33
34 radar.setSecondQuadrant(quadrant);
35
36 expect(radar.quadrants().II).toEqual(quadrant);
37 expect(radar.quadrants().II.blips()[0].number()).toEqual(1);
38 });
39
40 it('sets the third quadrant', function () {
41 var quadrant, radar, blip;
42
43 blip = new tr.models.Blip('A', new tr.models.Cycle('First'));
44 quadrant = new tr.models.Quadrant('Third');
45 quadrant.add([blip]);
46 radar = new tr.models.Radar();
47
48 radar.setThirdQuadrant(quadrant);
49
50 expect(radar.quadrants().III).toEqual(quadrant);
51 expect(radar.quadrants().III.blips()[0].number()).toEqual(1);
52 });
53
54 it('sets the fourth quadrant', function () {
55 var quadrant, radar, blip;
56
57 blip = new tr.models.Blip('A', new tr.models.Cycle('First'));
58 quadrant = new tr.models.Quadrant('Fourth');
59 quadrant.add([blip]);
60 radar = new tr.models.Radar();
61
62 radar.setFourthQuadrant(quadrant);
63
64 expect(radar.quadrants().IV).toEqual(quadrant);
65 expect(radar.quadrants().IV.blips()[0].number()).toEqual(1);
66 });
67
68 describe('blip numbers', function () {
69 var firstQuadrant, secondQuadrant, radar, firstCycle;
70
71 beforeEach(function () {
72 firstCycle = new tr.models.Cycle('Adopt', 0);
73 firstQuadrant = new tr.models.Quadrant('First');
74 secondQuadrant = new tr.models.Quadrant('Second');
75 firstQuadrant.add([
76 new tr.models.Blip('A', firstCycle),
77 new tr.models.Blip('B', firstCycle)
78 ]);
79 secondQuadrant.add([
80 new tr.models.Blip('C', firstCycle),
81 new tr.models.Blip('D', firstCycle)
82 ]);
83 radar = new tr.models.Radar();
84 });
85
86 it('sets blip numbers starting on the first quadrant', function () {
87 radar.setFirstQuadrant(firstQuadrant);
88
89 expect(radar.quadrants().I.blips()[0].number()).toEqual(1);
90 expect(radar.quadrants().I.blips()[1].number()).toEqual(2);
91 });
92
93 it('continues the number from the previous quadrant set', function () {
94 radar.setFirstQuadrant(firstQuadrant);
95 radar.setSecondQuadrant(secondQuadrant);
96
97 expect(radar.quadrants().II.blips()[0].number()).toEqual(3);
98 expect(radar.quadrants().II.blips()[1].number()).toEqual(4);
99 });
100 });
101
102 describe('cycles', function () {
103 var quadrant, radar, firstCycle, secondCycle;
104
105 beforeEach(function () {
106 firstCycle = new tr.models.Cycle('Adopt', 0);
107 secondCycle = new tr.models.Cycle('Hold', 1);
108 quadrant = new tr.models.Quadrant('Fourth');
109 radar = new tr.models.Radar();
110 });
111
112 it('returns an array for a given set of blips', function () {
113 quadrant.add([
114 new tr.models.Blip('A', firstCycle),
115 new tr.models.Blip('B', secondCycle)
116 ]);
117
118 radar.setFirstQuadrant(quadrant);
119
120 expect(radar.cycles()).toEqual([firstCycle, secondCycle]);
121 });
122
123 it('has unique cycles', function () {
124 quadrant.add([
125 new tr.models.Blip('A', firstCycle),
126 new tr.models.Blip('B', firstCycle),
127 new tr.models.Blip('C', secondCycle)
128 ]);
129
130 radar.setFirstQuadrant(quadrant);
131
132 expect(radar.cycles()).toEqual([firstCycle, secondCycle]);
133 });
134
135 it('has sorts by the cycle order', function () {
136 quadrant.add([
137 new tr.models.Blip('C', secondCycle),
138 new tr.models.Blip('A', firstCycle),
139 new tr.models.Blip('B', firstCycle)
140 ]);
141
142 radar.setFirstQuadrant(quadrant);
143
144 expect(radar.cycles()).toEqual([firstCycle, secondCycle]);
145 });
146 });
147 });