1 |
|
2 | //
|
3 | // # Adjacent nodes
|
4 | //
|
5 |
|
6 | var iper = require('iper');
|
7 |
|
8 | var IperGraph = iper.IperGraph;
|
9 |
|
10 | //
|
11 | // Let's create an empty graph and add some nodes
|
12 | //
|
13 |
|
14 | var graph = new IperGraph();
|
15 |
|
16 | /*
|
17 | var id1, id2, id3, id4, id5
|
18 | , adjacentNodeIds;
|
19 |
|
20 | id1 = graph.createNode();
|
21 | id2 = graph.createNode();
|
22 | id3 = graph.createNode();
|
23 | id4 = graph.createNode();
|
24 | id5 = graph.createNode();
|
25 |
|
26 | // retrieve a reference to the first node
|
27 | node1 = graph.getNode(id1);
|
28 |
|
29 | // Two nodes are adjacents if there is an hyperedge that contains both of
|
30 | // these nodes, so by now there is no adjacent node
|
31 |
|
32 | adjacentNodeIds = node1.getAdjacentNodeIds();
|
33 | // TODO adjacentNodeIds.should.be.empty();
|
34 |
|
35 | // Now we can add some edges and check adjacentNodeIds
|
36 | graph.createEdge([id1, id2]);
|
37 | adjacentNodeIds = node1.getAdjacentNodeIds();
|
38 | adjacentNodeIds.should.be.eql([id2]);
|
39 |
|
40 | // adjacentNodeIds list is a list of uniq ids
|
41 | // creating an edge with same endpoints than above should not
|
42 | // change adjacentNodeIds list
|
43 | graph.createEdge([id1, id2]);
|
44 | adjacentNodeIds = node1.getAdjacentNodeIds();
|
45 | adjacentNodeIds.should.be.eql([id2]);
|
46 |
|
47 | // let's try with a 3-edge
|
48 | graph.createEdge([id1, id3, id4]);
|
49 | adjacentNodeIds = node1.getAdjacentNodeIds();
|
50 | adjacentNodeIds.should.be.eql([id2, id3, id4]);
|
51 |
|
52 | // this edge should not change adjacentNodeIds list, since id1 is not involved
|
53 | graph.createEdge([id3, id4, id5]);
|
54 | adjacentNodeIds = node1.getAdjacentNodeIds();
|
55 | adjacentNodeIds.should.be.eql([id2, id3, id4]);
|
56 |
|
57 | // let's try removing a node
|
58 | graph.removeNode(id3);
|
59 | adjacentNodeIds = node1.getAdjacentNodeIds();
|
60 | adjacentNodeIds.should.be.eql([id2, id4]);
|
61 |
|
62 | */
|
63 |
|