| Conditions | 1 |
| Paths | 2 |
| Total Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | define(function(require) { |
||
| 9 | describe('oroworkflow/js/tools/path-finder/graph', function() { |
||
| 10 | beforeEach(function prepareGraph() { |
||
| 11 | var graph = new Graph(); |
||
| 12 | graph.outerRect = new Rectangle(0, 0, 500, 500); |
||
| 13 | graph.rectangles.push(new Rectangle(100, 100, 100, 100)); |
||
| 14 | this.graph = graph; |
||
| 15 | }); |
||
| 16 | |||
| 17 | function isConnected(node) { |
||
| 18 | return node.connections[directions.TOP_TO_BOTTOM.id] || |
||
| 19 | node.connections[directions.BOTTOM_TO_TOP.id] || |
||
| 20 | node.connections[directions.LEFT_TO_RIGHT.id] || |
||
| 21 | node.connections[directions.RIGHT_TO_LEFT.id]; |
||
| 22 | } |
||
| 23 | |||
| 24 | it('should add axises around block', function() { |
||
| 25 | var graph = this.graph; |
||
| 26 | var firstRect = graph.rectangles[0]; |
||
| 27 | graph.buildCornerAxises(); |
||
| 28 | expect(graph.baseAxises.length).toBe(4); |
||
| 29 | expect(_.any(graph.baseAxises, function(axis) { |
||
| 30 | return axis.a.x === firstRect.top; |
||
| 31 | })).toBeTruthy(); |
||
| 32 | expect(_.any(graph.baseAxises, function(axis) { |
||
| 33 | return axis.a.x === firstRect.bottom; |
||
| 34 | })).toBeTruthy(); |
||
| 35 | expect(_.any(graph.baseAxises, function(axis) { |
||
| 36 | return axis.a.y === firstRect.left; |
||
| 37 | })).toBeTruthy(); |
||
| 38 | expect(_.any(graph.baseAxises, function(axis) { |
||
| 39 | return axis.a.y === firstRect.right; |
||
| 40 | })).toBeTruthy(); |
||
| 41 | }); |
||
| 42 | |||
| 43 | it('should add axises out from block center', function() { |
||
| 44 | var graph = this.graph; |
||
| 45 | var firstRect = graph.rectangles[0]; |
||
| 46 | var rectCenter = firstRect.center; |
||
| 47 | graph.buildCenterAxises(); |
||
| 48 | |||
| 49 | var vX = _.countBy(graph.baseAxises, function(axis) { |
||
| 50 | return axis.a.x; |
||
| 51 | }); |
||
| 52 | var vY = _.countBy(graph.baseAxises, function(axis) { |
||
| 53 | return axis.a.y; |
||
| 54 | }); |
||
| 55 | |||
| 56 | expect(graph.baseAxises.length).toBe(8); |
||
| 57 | |||
| 58 | expect(vX[rectCenter.x - 1]).toBe(2); |
||
| 59 | expect(vX[rectCenter.x]).toBe(4); |
||
| 60 | expect(vX[rectCenter.x + 1]).toBe(2); |
||
| 61 | |||
| 62 | expect(vY[rectCenter.y - 1]).toBe(2); |
||
| 63 | expect(vY[rectCenter.y]).toBe(4); |
||
| 64 | expect(vY[rectCenter.y + 1]).toBe(2); |
||
| 65 | }); |
||
| 66 | |||
| 67 | it('should add axises at center between block pairs', function() { |
||
| 68 | var graph = this.graph; |
||
| 69 | graph.rectangles.push(new Rectangle(300, 300, 100, 100)); |
||
| 70 | graph.buildCenterLinesBetweenNodes(); |
||
| 71 | expect(graph.baseAxises.length).toBe(2); |
||
| 72 | expect(_.every(graph.baseAxises, function(ax) { |
||
| 73 | return ax.a.x === 250 || ax.a.y === 250; |
||
| 74 | })).toBeTruthy(); |
||
| 75 | }); |
||
| 76 | |||
| 77 | it('should finalize (setup connections) correctly', function() { |
||
| 78 | var graph = this.graph; |
||
| 79 | graph.rectangles.push(new Rectangle(300, 300, 100, 100)); |
||
| 80 | graph.build(); |
||
| 81 | expect(graph.verticalAxises.length).toBe(graph.horizontalAxises.length); |
||
| 82 | expect(graph.verticalAxises.length).toBe(13); |
||
| 83 | for (var id in graph.nodes) { |
||
| 84 | if (graph.nodes.hasOwnProperty(id)) { |
||
| 85 | expect(isConnected(graph.nodes[id])).toBeTruthy(); |
||
| 86 | expect(graph.nodes[id].vAxis).not.toBe(graph.nodes[id].hAxis); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | }); |
||
| 90 | }); |
||
| 91 | }); |
||
| 92 |