Something went wrong. Try again.
An ATProto Powered Reputation Network
Something went wrong. Try again.
1.4 kB · 36 lines
Go
at master
12345678910111213141516171819202122232425262728293031323334353637package algorithms_test
import ( "context" "fmt" "provenance/internal/domain" "provenance/internal/trust" "provenance/internal/trust/algorithms" "testing")
func TestDepthCap(t *testing.T) { edges := make([]domain.Vouch, trust.MaxDepth+1) for index := range edges { edges[index] = domain.Vouch{Author: fmt.Sprint(index), Subject: fmt.Sprint(index + 1), Score: 2} } for _, algorithm := range []trust.Algorithm{algorithms.Optimistic{}, algorithms.ShortestPath{}} { t.Run(algorithm.Describe().Name, func(t *testing.T) { input := trust.Input{Source: "0", Target: fmt.Sprint(trust.MaxDepth), Edges: edges, Limits: trust.Limits{States: 100, Edges: 100, Penalty: .1}} got, err := algorithm.Calculate(context.Background(), input) if err != nil || got.Status != trust.CalculatedStatus || len(got.Path) != trust.MaxDepth+1 { t.Fatalf("boundary path: %+v %v", got, err) } input.Target = fmt.Sprint(trust.MaxDepth + 1) got, err = algorithm.Calculate(context.Background(), input) if err != nil || got.Status != trust.UnknownStatus { t.Fatalf("over-depth path: %+v %v", got, err) } input.Edges = append(input.Edges, domain.Vouch{Author: "0", Subject: input.Target, Score: 0}) got, err = algorithm.Calculate(context.Background(), input) if err != nil || got.Score == nil || *got.Score != 0 || len(got.Path) != 2 { t.Fatalf("bounded alternative: %+v %v", got, err) } }) }}