mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 23:04:42 +01:00
20201221
This commit is contained in:
25
20201221/main.go
Normal file
25
20201221/main.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func isMountain(nums []int) bool {
|
||||||
|
hasUp := false
|
||||||
|
hasDown := false
|
||||||
|
c := nums[0]
|
||||||
|
for i := 0; i < len(nums); i++ {
|
||||||
|
n := nums[i]
|
||||||
|
if !hasUp && !hasDown && n > c {
|
||||||
|
hasUp = true
|
||||||
|
}
|
||||||
|
if c > n {
|
||||||
|
hasDown = true
|
||||||
|
}
|
||||||
|
if n > c && hasDown {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
c = n
|
||||||
|
}
|
||||||
|
return hasDown && hasUp
|
||||||
|
}
|
||||||
37
20201221/main_test.go
Normal file
37
20201221/main_test.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func Test_isMountain(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
nums []int
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"test1",
|
||||||
|
args{[]int{2, 1}},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test2",
|
||||||
|
args{[]int{3, 5, 5}},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test3",
|
||||||
|
args{[]int{0, 3, 2, 1}},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := isMountain(tt.args.nums); got != tt.want {
|
||||||
|
t.Errorf("isMountain() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user