Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
balasan committed Oct 30, 2020
1 parent 20ad34f commit 00efd27
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion graph.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Implementation of the Relevant Reputaiton protocol:
// Package reputation is an implementation of the Relevant Reputaiton protocol:
// a personalized pagerank algorithm that supports negative links
// personalized version offers sybil resistance
// can be used for voting, governance, ranking
Expand All @@ -17,8 +17,13 @@ import (
"strconv"
)

// NodeType is positive or negative
// each node in the graph can be represented by two nodes,
// a positive and a negative one
type NodeType int

// Positive nodes are consumers of positive links
// Negative nodes are consumers of neg links
const (
Positive NodeType = iota
Negative
Expand Down
34 changes: 34 additions & 0 deletions pagerank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,40 @@ func TestPersonalized(t *testing.T) {
}
}

func TestPersonalizedNoLink(t *testing.T) {
graph := NewGraph(0.85, 0.000001, 0)

a := NewNodeInput("a", 0, 0)
b := NewNodeInput("b", 0, 0)
c := NewNodeInput("c", 0, 0)
d := NewNodeInput("d", 0, 0)

graph.AddPersonalizationNode(a)

graph.Link(b, c, 1.0)
graph.Link(d, c, 1.0)

actual := map[string]Result{}

expected := map[string]Result{
"a": {pRank: 1.0, nRank: 0},
"b": {pRank: 0, nRank: 0},
"c": {pRank: 0, nRank: 0},
"d": {pRank: 0, nRank: 0},
}

graph.Rank(func(id string, pRank float64, nRank float64) {
actual[id] = Result{
pRank: pRank,
nRank: nRank,
}
})

if reflect.DeepEqual(actual, expected) != true {
t.Error("Expected", expected, "but got", actual)
}
}

func TestCancelOpposites(t *testing.T) {
graph := NewGraph(0.85, 0.000001, 0)

Expand Down

0 comments on commit 00efd27

Please sign in to comment.