1. Engineering
  2. Computer Science
  3. i am trying to write a package in go i...

Question: i am trying to write a package in go i...

Question details

I am trying to write a package in go. I am given two files:

I need to modify the function to return the min of an array of ints. do not change the first line of code. Please write in go or I will mark this answer as incorrect.

func Min(arr []int) int {

}

I am also given this tester code:

package min

import "testing"

func TestMin(t *testing.T) {
   tests := []struct {
       in []int
       expected int
   }{
       {[]int{0, -1, 1, 2, -4}, -4},
       {[]int{1}, 1},
       {[]int{0}, 0},
       {[]int{}, 0},
       {nil, 0},
       // TODO add more tests for 100% test coverage
   }

   for i, test := range tests {
       actual := Min(test.in)
       if actual != test.expected {
           t.Errorf("#%d: Min(%v)=%d; expected %d", i, test.in, actual, test.expected)
       }
   }
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution