PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/YEDGraphTest.j

http://github.com/rheimbuch/YED
Unknown | 65 lines | 51 code | 14 blank | 0 comment | 0 complexity | 6b3720da028475e366d5fffa6255f285 MD5 | raw file
 1@import "../YEDGraph.j"
 2
 3@implementation YEDGraphTest : OJTestCase
 4
 5- (void)testYEDGraphShouldAllowYEDNodes
 6{
 7    var graph = [YEDGraph graph],
 8        n1 = [YEDNode nodeWithName:"n1"],
 9        n2 = [YEDNode nodeWithName:"n2"];
10        
11    [self assertTrue:([graph allowsNode:n1])
12            message:"Graph should allow n1"];
13            
14    [self assertTrue:([graph allowsNode:n2])
15            message:"Graph should allow n2"];
16    
17    [graph addNode:n1];
18    [graph addNode:n2];
19    
20    [self assertTrue:([graph containsNode:n1])
21            message:"Graph should contain node n1"];
22    
23    [self assertTrue:([graph containsNode:n2])
24            message:"Graph should contain node n2"];
25}
26
27- (void)testCreateDirectedEdge
28{
29    var graph = [YEDGraph graph],
30        n1 = [YEDNode nodeWithName:"n1"],
31        n2 = [YEDNode nodeWithName:"n2"],
32        n3 = [YEDNode nodeWithName:"n3"];
33        
34    // Add n1 and n2 to graph
35    [graph addNode:n1];
36    [graph addNode:n2];
37    
38    // Now create an edge between n1 -> n2
39    [graph createDirectedEdgeFrom:n1 to:n2];
40    
41    // Edge n1 -> n2 should exist
42    [self assertTrue:[n1 hasOutgoingEdgeTo:n2]
43            message:"n1 should have outgoing edge to n2"];
44    [self assertTrue:[n2 hasIncomingEdgeFrom:n1]
45            message:"n2 should have incoming edge from n1"];
46    
47    // Creating an edge to n3 should fail because n3 is not in the graph
48    try 
49    {
50        [graph createDirectedEdgeFrom:n1 to:n3];
51    }
52    catch(err)
53    {
54        CPLog.info(err);
55    }
56    [self assertFalse:[n1 hasOutgoingEdgeTo:n3]
57            message:"edge n1 -> n3 should not have been created"];
58    [self assertFalse:[n3 hasIncomingEdgeFrom:n1]
59            message:"edge n1 -> n3 should not have been created"];
60    [self assertFalse:[graph containsNode:n3]
61            message:"n3 should not been in the graph"];
62}
63
64
65@end