Skip to content

Commit

Permalink
♻️ スライスのMax/Minを関数に置き換え
Browse files Browse the repository at this point in the history
  • Loading branch information
toriwasa committed Oct 30, 2023
1 parent cef129e commit 16a046e
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions app/grouping/grouping_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grouping

import (
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -189,16 +190,9 @@ func Test_n個の連番をランダムに並び替えた配列をg個のグル

t.Log("各グループ要素数の最大値と最小値の差は0または1であることを検証する")
// actualIntLengthSlice の最大値および最小値取得
max := 0
min := n
for _, v := range actualIntLengthSlice {
if v > max {
max = v
}
if v < min {
min = v
}
}
max := slices.Max(actualIntLengthSlice)
min := slices.Min(actualIntLengthSlice)
t.Logf("max: %d, min: %d", max, min)
// 最大値と最小値の差が0または1であることを検証する
if max-min != 0 && max-min != 1 {
t.Fatalf("expected: %d or %d, actual: %d", 0, 1, max-min)
Expand Down

0 comments on commit 16a046e

Please sign in to comment.