Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 1 | (function () { |
| 2 | 'use strict'; |
| 3 | |
| 4 | describe('The Logic Topology Helper Service', () => { |
| 5 | |
| 6 | var Service; |
| 7 | |
| 8 | beforeEach(module('xos.serviceTopology')); |
| 9 | |
| 10 | // inject the rackHelper service |
| 11 | beforeEach(inject(function (_LogicTopologyHelper_) { |
| 12 | // The injector unwraps the underscores (_) from around the parameter names when matching |
| 13 | Service = _LogicTopologyHelper_; |
| 14 | })); |
| 15 | |
| 16 | var customMatchers = { |
| 17 | toBeSimilar: () => { |
| 18 | |
| 19 | const tolerance = 0.1; |
| 20 | |
| 21 | return { |
| 22 | compare: (actual, expected) => { |
| 23 | return { |
| 24 | pass: (Math.abs(actual - expected) < tolerance), |
| 25 | message: `Expected ${actual} to be ${expected}` |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | beforeEach(function() { |
| 33 | jasmine.addMatchers(customMatchers); |
| 34 | }); |
| 35 | |
| 36 | it('should calculate horizontal position for each element', () => { |
| 37 | let [el0x, el1x, el2x, el3x, el4x, el5x] = Service.computeElementPosition(900); |
| 38 | |
Matteo Scandolo | bec0a6c | 2016-02-11 17:58:18 -0800 | [diff] [blame] | 39 | expect(el0x).toBeSimilar(870); |
| 40 | expect(el1x).toBeSimilar(736.6); |
| 41 | expect(el2x).toBeSimilar(560.7); |
| 42 | expect(el3x).toBeSimilar(384.8); |
| 43 | expect(el4x).toBeSimilar(251.4); |
| 44 | expect(el5x).toBeSimilar(95); |
Matteo Scandolo | cc0db94 | 2016-02-11 17:37:08 -0800 | [diff] [blame] | 45 | }); |
| 46 | }); |
| 47 | |
| 48 | })(); |