forked from TrueCloudLab/frostfs-node
3775d61ccb
Check if `new(big.Int)` will be efficient later and replace all `big.NewInt()` in code or leave it as it is. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
54 lines
988 B
Go
54 lines
988 B
Go
package basic
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type normalizedValueCase struct {
|
|
name string
|
|
n, total, limit uint64
|
|
expected uint64
|
|
}
|
|
|
|
func TestNormalizedValues(t *testing.T) {
|
|
testCases := []normalizedValueCase{
|
|
{
|
|
name: "zero limit",
|
|
n: 50,
|
|
total: 100,
|
|
limit: 0,
|
|
expected: 0,
|
|
},
|
|
{
|
|
name: "scale down",
|
|
n: 50,
|
|
total: 100,
|
|
limit: 10,
|
|
expected: 5,
|
|
},
|
|
{
|
|
name: "scale up",
|
|
n: 50,
|
|
total: 100,
|
|
limit: 1000,
|
|
expected: 500,
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
testNormalizedValues(t, testCase)
|
|
}
|
|
}
|
|
|
|
func testNormalizedValues(t *testing.T, c normalizedValueCase) {
|
|
n := big.NewInt(0).SetUint64(c.n)
|
|
total := big.NewInt(0).SetUint64(c.total)
|
|
limit := big.NewInt(0).SetUint64(c.limit)
|
|
exp := big.NewInt(0).SetUint64(c.expected)
|
|
|
|
got := normalizedValue(n, total, limit)
|
|
require.Zero(t, exp.Cmp(got), c.name)
|
|
}
|