--- /dev/null
+tr.models.Radar = function() {
+ var self, quadrants;
+
+ quadrants = { I: null, II: null, III: null, IV: null };
+ self = {};
+
+ self.setFirstQuadrant = function (quadrant) {
+ quadrants.I = quadrant;
+ };
+
+ self.setSecondQuadrant = function (quadrant) {
+ quadrants.II = quadrant;
+ };
+
+ self.setThirdQuadrant = function (quadrant) {
+ quadrants.III = quadrant;
+ };
+
+ self.setFourthQuadrant = function (quadrant) {
+ quadrants.IV = quadrant;
+ };
+
+ function allQuadrants() {
+ var all = [];
+
+ for (var p in quadrants) {
+ if (quadrants.hasOwnProperty(p) && quadrants[p] != null) {
+ all.push(quadrants[p]);
+ }
+ }
+
+ return all;
+ }
+
+ function allBlips() {
+ return allQuadrants().reduce(function (blips, quadrant) {
+ return blips.concat(quadrant.blips());
+ }, []);
+ }
+
+ self.cycles = function () {
+ var cycleHash, cycleArray;
+
+ cycleArray = [];
+ cycleHash = {};
+
+ allBlips().forEach(function (blip) {
+ cycleHash[blip.cycle().name()] = blip.cycle();
+ });
+
+ for (var p in cycleHash) {
+ if (cycleHash.hasOwnProperty(p)) {
+ cycleArray.push(cycleHash[p]);
+ }
+ }
+
+ return cycleArray.slice(0);
+ };
+
+ self.quadrants = function () {
+ return quadrants;
+ };
+
+ return self;
+};
--- /dev/null
+describe('tr.models.Radar', function () {
+
+ it('has no quadrants by default', function () {
+ radar = new tr.models.Radar();
+
+ expect(radar.quadrants().I).toBe(null);
+ expect(radar.quadrants().II).toBe(null);
+ expect(radar.quadrants().III).toBe(null);
+ expect(radar.quadrants().IV).toBe(null);
+ });
+
+ it('sets the first quadrant', function () {
+ var quadrant, radar;
+
+ quadrant = new tr.models.Quadrant('First');
+ radar = new tr.models.Radar();
+
+ radar.setFirstQuadrant(quadrant);
+
+ expect(radar.quadrants().I).toEqual(quadrant);
+ });
+
+ it('sets the second quadrant', function () {
+ var quadrant, radar;
+
+ quadrant = new tr.models.Quadrant('Second');
+ radar = new tr.models.Radar();
+
+ radar.setSecondQuadrant(quadrant);
+
+ expect(radar.quadrants().II).toEqual(quadrant);
+ });
+
+ it('sets the third quadrant', function () {
+ var quadrant, radar;
+
+ quadrant = new tr.models.Quadrant('Third');
+ radar = new tr.models.Radar();
+
+ radar.setThirdQuadrant(quadrant);
+
+ expect(radar.quadrants().III).toEqual(quadrant);
+ });
+
+ it('sets the fourth quadrant', function () {
+ var quadrant, radar;
+
+ quadrant = new tr.models.Quadrant('Fourth');
+ radar = new tr.models.Radar();
+
+ radar.setFourthQuadrant(quadrant);
+
+ expect(radar.quadrants().IV).toEqual(quadrant);
+ });
+
+ describe('cycles', function () {
+ var quadrant, radar, firstCycle, secondCycle;
+
+ beforeEach(function () {
+ firstCycle = new tr.models.Cycle('Adopt');
+ secondCycle = new tr.models.Cycle('Hold');
+ quadrant = new tr.models.Quadrant('Fourth');
+ radar = new tr.models.Radar();
+ });
+
+ it('returns an array for a given set of blips', function () {
+ quadrant.add([
+ new tr.models.Blip('A', firstCycle),
+ new tr.models.Blip('B', secondCycle)
+ ]);
+
+ radar.setFirstQuadrant(quadrant);
+
+ expect(radar.cycles()).toEqual([firstCycle, secondCycle]);
+ });
+
+ it('has unique cycles', function () {
+ quadrant.add([
+ new tr.models.Blip('A', firstCycle),
+ new tr.models.Blip('B', firstCycle),
+ new tr.models.Blip('C', secondCycle)
+ ]);
+
+ radar.setFirstQuadrant(quadrant);
+
+ expect(radar.cycles()).toEqual([firstCycle, secondCycle]);
+ });
+ });
+});