diff --git a/graph.go b/graph.go index fdcc0bf..43ab40e 100644 --- a/graph.go +++ b/graph.go @@ -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 @@ -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 diff --git a/pagerank_test.go b/pagerank_test.go index 8ecf38f..2d67669 100644 --- a/pagerank_test.go +++ b/pagerank_test.go @@ -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)