This repository has been archived on 2026-06-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
algo-homework/1-B-1/main_test.go
T
2026-05-11 19:07:09 +08:00

42 lines
710 B
Go

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)
}
})
}
}