diff --git a/micro/microfunctions.go b/micro/microfunctions.go index fb9061c7..9d124283 100644 --- a/micro/microfunctions.go +++ b/micro/microfunctions.go @@ -439,6 +439,46 @@ func MinInt64(Mass ...int64) int64 { return Otvet } +// MaxInt returns the largest value +func MaxInt(Mass ...int) int { + var Otvet int + + // + if len(Mass) == 0 { + return Otvet + } + + // + Otvet = Mass[0] + for _, val := range Mass { + if val > Otvet { + Otvet = val + } + } + + return Otvet +} + +// MinInt returns the smallest value +func MinInt(Mass ...int) int { + var Otvet int + + // + if len(Mass) == 0 { + return Otvet + } + + // + Otvet = Mass[0] + for _, val := range Mass { + if val < Otvet { + Otvet = val + } + } + + return Otvet +} + // MaxFloat64 returns the largest value func MaxFloat64(Mass ...float64) float64 { var Otvet float64 diff --git a/micro/microfunctions_test.go b/micro/microfunctions_test.go index 9b14d6f9..689a1907 100644 --- a/micro/microfunctions_test.go +++ b/micro/microfunctions_test.go @@ -220,6 +220,20 @@ func TestMinInt64(t *testing.T) { } } +func TestMaxInt(t *testing.T) { + Otvet := MaxInt(1, 2, 3, 4) + if Otvet != 4 { + t.Error("microfunctions_test.TestMaxInt() error: Otvet != 2") + } +} + +func TestMinInt(t *testing.T) { + Otvet := MinInt(1, 2, 3, 4) + if Otvet != 1 { + t.Error("microfunctions_test.TestMinInt() error: Otvet != 1") + } +} + func TestGoGo(t *testing.T) { fn := func() error { Pause(2000)