|
| 1 | +var assert = require("chai").assert; |
1 | 2 | var toGraph = require("../"); |
2 | 3 |
|
3 | 4 | describe("toGraph()", function() { |
4 | | - it.skip("should be able to parse a single graph", function() {}); |
5 | | - it.skip("should be able to parse multiple graphs", function() {}); |
6 | | - it.skip("should throw an error if there are no graphs", function() {}); |
7 | | - it.skip("should support graphs without nodes", function() {}); |
8 | | - it.skip("should support graphs without edges", function() {}); |
9 | | - it.skip("should respect the directed property of a graph", function() {}); |
10 | | - it.skip("should make a graph directed if any of the edges are directed", function() {}); |
11 | | - it.skip("should be a multigraph", function() {}); |
12 | | - it.skip("should use the id for distinguishing edges between the same nodes", function() {}); |
| 5 | + var defaultGraph = { |
| 6 | + graph: { |
| 7 | + nodes: [{ |
| 8 | + id: "1" |
| 9 | + }, { |
| 10 | + id: "2" |
| 11 | + }], |
| 12 | + edges: [{ |
| 13 | + source: "1", |
| 14 | + target: "2" |
| 15 | + }] |
| 16 | + } |
| 17 | + }; |
| 18 | + |
| 19 | + it("should be able to parse a single graph", function() { |
| 20 | + var graph = toGraph(defaultGraph); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should be able to parse multiple graphs", function() { |
| 24 | + var graphs = toGraph({ |
| 25 | + graphs: [defaultGraph, defaultGraph, defaultGraph] |
| 26 | + }); |
| 27 | + |
| 28 | + assert.lengthOf(graphs, 3, "parsed three graphs"); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should throw an error if there are no graphs", function(done) { |
| 32 | + try { |
| 33 | + toGraph({}); |
| 34 | + } catch (e) { |
| 35 | + done(); |
| 36 | + } |
| 37 | + }); |
| 38 | + |
| 39 | + it("should support graphs without edges", function() { |
| 40 | + toGraph({ |
| 41 | + graph: { |
| 42 | + nodes: [{ |
| 43 | + id: 1 |
| 44 | + }] |
| 45 | + } |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should support graphs without nodes", function() { |
| 50 | + toGraph({ |
| 51 | + graph: {} |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it("should respect the directed property of a graph", function() { |
| 56 | + assert.notOk(toGraph({ |
| 57 | + graph: { |
| 58 | + directed: false |
| 59 | + } |
| 60 | + }).isDirected(), "Graph is not directed"); |
| 61 | + |
| 62 | + assert.ok(toGraph({ |
| 63 | + graph: { |
| 64 | + directed: true |
| 65 | + } |
| 66 | + }).isDirected(), "Graph is directed"); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should make a graph directed if any of the edges are directed", function() { |
| 70 | + assert.ok(toGraph({ |
| 71 | + graph: { |
| 72 | + nodes: [{ |
| 73 | + id: "1" |
| 74 | + }, { |
| 75 | + id: "2" |
| 76 | + }], |
| 77 | + edges: [{ |
| 78 | + directed: true, |
| 79 | + source: 1, |
| 80 | + target: 1 |
| 81 | + }] |
| 82 | + } |
| 83 | + }).isDirected(), "Graph is directed"); |
| 84 | + }); |
| 85 | + |
| 86 | + it("should be a multigraph", function() { |
| 87 | + assert.ok(toGraph(defaultGraph).isMultigraph(), "Is a multigraph") |
| 88 | + }); |
| 89 | + |
| 90 | + it("should use the id for distinguishing edges between the same nodes", function() { |
| 91 | + var graph = toGraph({ |
| 92 | + graph: { |
| 93 | + nodes: [{ |
| 94 | + id: "1" |
| 95 | + }, { |
| 96 | + id: "2" |
| 97 | + }], |
| 98 | + edges: [{ |
| 99 | + id: "e1", |
| 100 | + directed: true, |
| 101 | + source: "1", |
| 102 | + target: "2" |
| 103 | + }, { |
| 104 | + id: "e2", |
| 105 | + directed: true, |
| 106 | + source: "1", |
| 107 | + target: "2" |
| 108 | + }] |
| 109 | + } |
| 110 | + }); |
| 111 | + |
| 112 | + var e1 = graph.edge("1", "2", "e1"); |
| 113 | + var e2 = graph.edge("1", "2", "e2"); |
| 114 | + |
| 115 | + assert.notEqual(e1, e2, "Edges were different") |
| 116 | + }); |
13 | 117 | }); |
0 commit comments