Skip to content

Commit

Permalink
Fixed edge problems with type not being saved and added equality tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericfode committed Aug 24, 2012
1 parent a730214 commit 0bb6816
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
1 change: 1 addition & 0 deletions Edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Edge interface {

SetFirstNode(node Node)
SetSecondNode(node Node)
Equals(o Edge) bool
}

type EdgeConstructor func(id string, gm GraphBackend) Edge
26 changes: 6 additions & 20 deletions GraphManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func TestGetEdge(t *testing.T) {
if edge == nil {
t.Error("GM did not retrieve edge (nil)")
}
if !edge.Equals(edges[0]) {
t.Errorf("Edges are not equal")
}
}

func TestAddSingleEdge(t *testing.T) {
Expand All @@ -221,8 +224,8 @@ func TestAddSingleEdge(t *testing.T) {

gm.AddEdge(edge)

if edge.GetID() != "0" {
t.Errorf("GraphManager: id 0 was %d", edge.GetID())
if !edge.Equals(e[0]) {
t.Errorf("Edges are not equal")
}
}

Expand Down Expand Up @@ -347,22 +350,6 @@ func TestNodeFromHash(t *testing.T) {
}
}

func TestGetNodeEdges(t *testing.T) {
gm = new(spiderDB.GraphManager)
gm.Initialize()
defer gm.ClearAll()

nodes := initTestNodes(gm)
edges := initTestEdges(gm)

for _, v := range nodes {
gm.AddNode(v)
}
for _, v := range edges {
gm.AddEdge(v)
}
}

func TestGetNeighbors(t *testing.T) {
gm = new(spiderDB.GraphManager)

Expand All @@ -388,9 +375,8 @@ func TestGetNeighbors(t *testing.T) {
}

if len(neighbors) != 1 {
t.Errorf("GetNeighbors Failed - %v neighbors", len(neighbors))

fmt.Printf("***************%v ************\n", neighbors)
t.Errorf("GetNeighbors Failed - %v neighbors", len(neighbors))
}

if err != nil {
Expand Down
13 changes: 12 additions & 1 deletion socialGraph/SocialEdge.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *SocialEdge) GetType() string {
return s.typ
}
func (s *SocialEdge) SetType(typestr string) {

s.typ = typestr
}

func (s *SocialEdge) SetPropMap(props map[string][]byte) {
Expand Down Expand Up @@ -94,3 +94,14 @@ func (s *SocialEdge) SetSecondNode(node spiderDB.Node) {
func (s *SocialEdge) IsDirected() bool {
return true
}

func (s *SocialEdge) Equals(o spiderDB.Edge) bool {
if a, ok := o.(*SocialEdge); ok {
if (s.GetID() == a.GetID() &&
s.GetDate() == a.GetDate() &&
s.GetType() == a.GetType()){
return true
}
}
return false
}

0 comments on commit 0bb6816

Please sign in to comment.