scheduler: improve the comment and add more unit test cases for DefaultNormalizeScore

This commit is contained in:
SataQiu 2022-07-14 21:53:43 +08:00
parent 9d577d8a29
commit 9a2eaa8e3f
2 changed files with 12 additions and 2 deletions

View File

@ -21,8 +21,9 @@ import (
)
// DefaultNormalizeScore generates a Normalize Score function that can normalize the
// scores to [0, maxPriority]. If reverse is set to true, it reverses the scores by
// subtracting it from maxPriority.
// scores from [0, max(scores)] to [0, maxPriority]. If reverse is set to true, it
// reverses the scores by subtracting it from maxPriority.
// Note: The input scores are always assumed to be non-negative integers.
func DefaultNormalizeScore(maxPriority int64, reverse bool, scores framework.NodeScoreList) *framework.Status {
var maxCount int64
for i := range scores {

View File

@ -61,6 +61,15 @@ func TestDefaultNormalizeScore(t *testing.T) {
scores: []int64{0, 1, 1, 1},
expectedScores: []int64{100, 0, 0, 0},
},
{
scores: []int64{0, 0, 0, 0},
expectedScores: []int64{0, 0, 0, 0},
},
{
reverse: true,
scores: []int64{0, 0, 0, 0},
expectedScores: []int64{100, 100, 100, 100},
},
}
for i, test := range tests {