mirror of https://github.com/k3s-io/k3s
Merge pull request #60790 from hanxiaoshuai/addut03051
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. add unit test for function AsScaledInt64 **What this PR does / why we need it**: add unit test for function AsScaledInt64 **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```pull/8/head
commit
7fa1b77a1f
|
@ -131,3 +131,32 @@ func TestAmountSign(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt64AmountAsScaledInt64(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
i int64Amount
|
||||
scaled Scale
|
||||
result int64
|
||||
ok bool
|
||||
}{
|
||||
{"test when i.scale < scaled ", int64Amount{value: 100, scale: 0}, 5, 1, true},
|
||||
{"test when i.scale = scaled", int64Amount{value: 100, scale: 1}, 1, 100, true},
|
||||
{"test when i.scale > scaled and result doesn't overflow", int64Amount{value: 100, scale: 5}, 2, 100000, true},
|
||||
{"test when i.scale > scaled and result overflows", int64Amount{value: 876, scale: 30}, 4, 0, false},
|
||||
{"test when i.scale < 0 and fraction exists", int64Amount{value: 93, scale: -1}, 0, 10, true},
|
||||
{"test when i.scale < 0 and fraction doesn't exist", int64Amount{value: 100, scale: -1}, 0, 10, true},
|
||||
{"test when i.value < 0 and fraction exists", int64Amount{value: -1932, scale: 2}, 4, -20, true},
|
||||
{"test when i.value < 0 and fraction doesn't exists", int64Amount{value: -1900, scale: 2}, 4, -19, true},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
r, ok := test.i.AsScaledInt64(test.scaled)
|
||||
if r != test.result {
|
||||
t.Errorf("%v: expected result: %d, got result: %d", test.name, test.result, r)
|
||||
}
|
||||
if ok != test.ok {
|
||||
t.Errorf("%v: expected ok: %t, got ok: %t", test.name, test.ok, ok)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue