github.com/decred/dcrlnd@v0.7.6/autopilot/graph_test.go (about)

     1  package autopilot_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/decred/dcrd/dcrutil/v4"
     7  	"github.com/decred/dcrlnd/autopilot"
     8  )
     9  
    10  // TestMedian tests the Median method.
    11  func TestMedian(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	testCases := []struct {
    15  		values []dcrutil.Amount
    16  		median dcrutil.Amount
    17  	}{
    18  		{
    19  			values: []dcrutil.Amount{},
    20  			median: 0,
    21  		},
    22  		{
    23  			values: []dcrutil.Amount{10},
    24  			median: 10,
    25  		},
    26  		{
    27  			values: []dcrutil.Amount{10, 20},
    28  			median: 15,
    29  		},
    30  		{
    31  			values: []dcrutil.Amount{10, 20, 30},
    32  			median: 20,
    33  		},
    34  		{
    35  			values: []dcrutil.Amount{30, 10, 20},
    36  			median: 20,
    37  		},
    38  		{
    39  			values: []dcrutil.Amount{10, 10, 10, 10, 5000000},
    40  			median: 10,
    41  		},
    42  	}
    43  
    44  	for _, test := range testCases {
    45  		res := autopilot.Median(test.values)
    46  		if res != test.median {
    47  			t.Fatalf("expected median %v, got %v", test.median, res)
    48  		}
    49  	}
    50  }