This commit is contained in:
xkm
2026-05-11 19:07:09 +08:00
commit 7ccb2ea522
4 changed files with 57 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
package algo
import (
"fmt"
"math/rand/v2"
"testing"
)
func TestFindMax(t *testing.T) {
for range 114 {
arr := make([]int64, 114)
for idx := range arr {
arr[idx] = rand.Int64()
}
expectedResult := arr[0]
for _, val := range arr {
expectedResult = max(expectedResult, val)
}
if expectedResult != FindMax(arr) {
t.Failed()
}
}
}
func BenchmarkFindMax(b *testing.B) {
sizes := []int{10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000}
for _, n := range sizes {
b.Run(fmt.Sprintf("N=%d", n), func(b *testing.B) {
arr := make([]int64, n)
for idx := range arr {
arr[idx] = rand.Int64()
}
b.ResetTimer()
for b.Loop() {
FindMax(arr)
}
})
}
}