mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-01 18:27:43 +02:00
autopilot: add Median method
This commit is contained in:
50
autopilot/graph_test.go
Normal file
50
autopilot/graph_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package autopilot_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/autopilot"
|
||||
)
|
||||
|
||||
// TestMedian tests the Median method.
|
||||
func TestMedian(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
values []btcutil.Amount
|
||||
median btcutil.Amount
|
||||
}{
|
||||
{
|
||||
values: []btcutil.Amount{},
|
||||
median: 0,
|
||||
},
|
||||
{
|
||||
values: []btcutil.Amount{10},
|
||||
median: 10,
|
||||
},
|
||||
{
|
||||
values: []btcutil.Amount{10, 20},
|
||||
median: 15,
|
||||
},
|
||||
{
|
||||
values: []btcutil.Amount{10, 20, 30},
|
||||
median: 20,
|
||||
},
|
||||
{
|
||||
values: []btcutil.Amount{30, 10, 20},
|
||||
median: 20,
|
||||
},
|
||||
{
|
||||
values: []btcutil.Amount{10, 10, 10, 10, 5000000},
|
||||
median: 10,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
res := autopilot.Median(test.values)
|
||||
if res != test.median {
|
||||
t.Fatalf("expected median %v, got %v", test.median, res)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user