UNPKG

1.65 kBJavaScriptView Raw
1
2//
3// # Adjacent nodes
4//
5
6var iper = require('iper');
7
8var IperGraph = iper.IperGraph;
9
10//
11// Let's create an empty graph and add some nodes
12//
13
14var graph = new IperGraph();
15
16/*
17var id1, id2, id3, id4, id5
18 , adjacentNodeIds;
19
20id1 = graph.createNode();
21id2 = graph.createNode();
22id3 = graph.createNode();
23id4 = graph.createNode();
24id5 = graph.createNode();
25
26// retrieve a reference to the first node
27node1 = 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
32adjacentNodeIds = node1.getAdjacentNodeIds();
33// TODO adjacentNodeIds.should.be.empty();
34
35// Now we can add some edges and check adjacentNodeIds
36graph.createEdge([id1, id2]);
37adjacentNodeIds = node1.getAdjacentNodeIds();
38adjacentNodeIds.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
43graph.createEdge([id1, id2]);
44adjacentNodeIds = node1.getAdjacentNodeIds();
45adjacentNodeIds.should.be.eql([id2]);
46
47// let's try with a 3-edge
48graph.createEdge([id1, id3, id4]);
49adjacentNodeIds = node1.getAdjacentNodeIds();
50adjacentNodeIds.should.be.eql([id2, id3, id4]);
51
52// this edge should not change adjacentNodeIds list, since id1 is not involved
53graph.createEdge([id3, id4, id5]);
54adjacentNodeIds = node1.getAdjacentNodeIds();
55adjacentNodeIds.should.be.eql([id2, id3, id4]);
56
57// let's try removing a node
58graph.removeNode(id3);
59adjacentNodeIds = node1.getAdjacentNodeIds();
60adjacentNodeIds.should.be.eql([id2, id4]);
61
62*/
63