github.com/MetalBlockchain/metalgo@v1.11.9/utils/sampler/weighted_linear_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package sampler 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestWeightedLinearElementCompare(t *testing.T) { 14 tests := []struct { 15 a weightedLinearElement 16 b weightedLinearElement 17 expected int 18 }{ 19 { 20 a: weightedLinearElement{}, 21 b: weightedLinearElement{}, 22 expected: 0, 23 }, 24 { 25 a: weightedLinearElement{ 26 cumulativeWeight: 1, 27 }, 28 b: weightedLinearElement{ 29 cumulativeWeight: 2, 30 }, 31 expected: 1, 32 }, 33 } 34 for _, test := range tests { 35 t.Run(fmt.Sprintf("%d_%d_%d", test.a.cumulativeWeight, test.b.cumulativeWeight, test.expected), func(t *testing.T) { 36 require := require.New(t) 37 38 require.Equal(test.expected, test.a.Compare(test.b)) 39 require.Equal(-test.expected, test.b.Compare(test.a)) 40 }) 41 } 42 }