-
Notifications
You must be signed in to change notification settings - Fork 0
/
mymain.go
51 lines (46 loc) · 1.14 KB
/
mymain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
//
// For example:
// GenerateIntegers(2, 8) => [2, 4, 6, 8]
// GenerateIntegers(8, 2) => [2, 4, 6, 8]
// GenerateIntegers(10, 14) => []
func GenerateIntegers(a, b int) []int {
min := func (a, b int) int {
if a > b {
return b
}
return a
}
max := func (a, b int) int {
if a > b {
return a
}
return b
}
lower := max(2, min(a, b))
upper := min(8, max(a, b))
ans := make([]int, 0)
for i := lower;i < upper;i++ {
if i&1==0 {
ans = append(ans, i)
}
}
return ans
}
func ExampleTestGenerateIntegers(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{2, 4, 6, 8}, GenerateIntegers(2, 8))
assert.Equal([]int{2, 4, 6, 8}, GenerateIntegers(8, 2))
assert.Equal([]int{}, GenerateIntegers(10, 14))
}
func main() {
// Here you can call the test functions or any other code
t := &testing.T{}
ExampleTestGenerateIntegers(t)
}