blob: 932b17fcf3656f224d21c423b6c573a7b4809f42 [file] [log] [blame]
Matteo Scandolocc0db942016-02-11 17:37:08 -08001(function () {
2 'use strict';
3
4 const computeNodes = [
5 {
6 humanReadableName: 'cp-1.teone.xos-pg0.clemson.cloudlab.us',
7 instances: [
8 {
9 instance_name: 'mysite_clients-3'
10 },
11 {
12 instance_name: 'mysite_clients-4'
13 },
14 {
15 instance_name: 'mysite_clients-5'
16 }
17 ]
18 },
19 {
20 humanReadableName: 'cp-2.teone.xos-pg0.clemson.cloudlab.us',
21 instances: [
22 {
23 instance_name: 'mysite_clients-1'
24 },
25 {
26 instance_name: 'mysite_clients-2'
27 }
28 ]
29 },
30 {
31 humanReadableName: 'cp-2.teone.xos-pg0.clemson.cloudlab.us',
32 instances: [
33 {
34 instance_name: 'mysite_clients-1'
35 },
36 {
37 instance_name: 'mysite_clients-2'
38 }
39 ]
40 }
41 ];
42
43 describe('The Rack Helper Service', () => {
44
45 var Service;
46
47 beforeEach(module('xos.serviceTopology'));
48
49 // inject the rackHelper service
50 beforeEach(inject(function (_RackHelper_) {
51 // The injector unwraps the underscores (_) from around the parameter names when matching
52 Service = _RackHelper_;
53 }));
54
55 describe('Given a list of instances', () => {
56 it('should calculate the Compute Node Size', () => {
57 const [width, height] = Service.getComputeNodeSize(computeNodes[0].instances);
58 expect(width).toBe(95);
59 expect(height).toBe(67);
60 });
61 });
62
63 describe('Given a list of Compute Nodes', () => {
64 it('should return rack size', () => {
65 const [width, height] = Service.getRackSize(computeNodes);
66 expect(width).toBe(105);
67 expect(height).toBe(179);
68 });
69 });
70
71 describe('Given an instance index', () => {
72 it('should return the position for first instance', () => {
73 const [x, y] = Service.getInstancePosition(0);
74 expect(x).toBe(5);
75 expect(y).toBe(25);
76 });
77
78 it('should return the position for second instance', () => {
79 const [x, y] = Service.getInstancePosition(1);
80 expect(x).toBe(50);
81 expect(y).toBe(25);
82 });
83
84 it('should return the position for third instance', () => {
85 const [x, y] = Service.getInstancePosition(2);
86 expect(x).toBe(5);
87 expect(y).toBe(46);
88 });
89
90 it('should return the position for 4th instance', () => {
91 const [x, y] = Service.getInstancePosition(3);
92 expect(x).toBe(50);
93 expect(y).toBe(46);
94 });
95 });
96
97 describe('Given an ComputeNode index', () => {
98 it('should return the position for 1st node', () => {
99 const [x, y] = Service.getComputeNodePosition(computeNodes, 0);
100 expect(x).toBe(5);
101 expect(y).toBe(5);
102 });
103
104 it('should return the position for 2st node', () => {
105 const [x, y] = Service.getComputeNodePosition(computeNodes, 1);
106 expect(x).toBe(5);
107 expect(y).toBe(77);
108 });
109
110 it('should return the position for 2st node', () => {
111 const [x, y] = Service.getComputeNodePosition(computeNodes, 2);
112 expect(x).toBe(5);
113 expect(y).toBe(128);
114 });
115 });
116 });
117})();