From 919710467e4b10da421b135a27d3bd3f4b2c8aa7 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Sat, 28 Mar 2020 16:38:46 +0100 Subject: [PATCH] autopilot: tidying up source code to fit to 80 cols --- autopilot/betweenness_centrality.go | 18 +++++++++--------- autopilot/betweenness_centrality_test.go | 15 ++++++++++----- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/autopilot/betweenness_centrality.go b/autopilot/betweenness_centrality.go index 34a10f7a..85041864 100644 --- a/autopilot/betweenness_centrality.go +++ b/autopilot/betweenness_centrality.go @@ -98,13 +98,13 @@ func betweennessCentrality(g *SimpleGraph, s int, centrality []float64) { // shortest path from s to t for each node t. pred := make([][]int, len(g.Nodes)) - // sigma[t] is the number of shortest paths between nodes s and t for - // each node t. + // sigma[t] is the number of shortest paths between nodes s and t + // for each node t. sigma := make([]int, len(g.Nodes)) sigma[s] = 1 - // dist[t] holds the distance between s and t for each node t. We initialize - // this to -1 (meaning infinity) for each t != s. + // dist[t] holds the distance between s and t for each node t. + // We initialize this to -1 (meaning infinity) for each t != s. dist := make([]int, len(g.Nodes)) for i := range dist { dist[i] = -1 @@ -178,9 +178,9 @@ func (bc *BetweennessCentrality) Refresh(graph ChannelGraph) error { work := make(chan int) partials := make(chan []float64, bc.workers) - // Each worker will compute a partial result. This - // partial result is a sum of centrality updates on - // roughly N / workers nodes. + // Each worker will compute a partial result. + // This partial result is a sum of centrality updates + // on roughly N / workers nodes. worker := func() { defer wg.Done() partial := make([]float64, len(cache.Nodes)) @@ -199,8 +199,8 @@ func (bc *BetweennessCentrality) Refresh(graph ChannelGraph) error { go worker() } - // Distribute work amongst workers Should be - // fair when graph is sufficiently large. + // Distribute work amongst workers. + // Should be fair when the graph is sufficiently large. for node := range cache.Nodes { work <- node } diff --git a/autopilot/betweenness_centrality_test.go b/autopilot/betweenness_centrality_test.go index 4b71f77f..76ece3ce 100644 --- a/autopilot/betweenness_centrality_test.go +++ b/autopilot/betweenness_centrality_test.go @@ -91,7 +91,7 @@ func buildTestGraph(t *testing.T, for _, v := range neighbors { _, _, err := graph.addRandChannel(nodes[u], nodes[v], chanCapacity) if err != nil { - t.Fatalf("unexpected error while adding random channel: %v", err) + t.Fatalf("unexpected error adding random channel: %v", err) } } } @@ -147,9 +147,12 @@ func TestBetweennessCentralityWithNonEmptyGraph(t *testing.T) { testName := fmt.Sprintf("%v %d workers", chanGraph.name, numWorkers) success := t.Run(testName, func(t1 *testing.T) { - centralityMetric, err := NewBetweennessCentralityMetric(numWorkers) + centralityMetric, err := NewBetweennessCentralityMetric( + numWorkers, + ) if err != nil { - t.Fatalf("construction must succeed with positive number of workers") + t.Fatalf("construction must succeed with " + + "positive number of workers") } graphNodes := buildTestGraph(t1, graph, graphDesc) @@ -169,11 +172,13 @@ func TestBetweennessCentralityWithNonEmptyGraph(t *testing.T) { nodeID := NewNodeID(graphNodes[node]) calculatedCentrality, ok := centrality[nodeID] if !ok { - t1.Fatalf("no result for node: %x (%v)", nodeID, node) + t1.Fatalf("no result for node: %x (%v)", + nodeID, node) } if nodeCentrality != calculatedCentrality { - t1.Errorf("centrality for node: %v should be %v, got: %v", + t1.Errorf("centrality for node: %v "+ + "should be %v, got: %v", node, nodeCentrality, calculatedCentrality) } }