This commit is contained in:
VicRen
2020-12-26 09:12:08 +08:00
parent 280c85895a
commit 4b3b8cbfae
2 changed files with 144 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
package main
import "testing"
func Test_findThirdMax(t *testing.T) {
type args struct {
nums []int
}
tests := []struct {
name string
args args
want int
}{
{
"in:[3,2,1],out:1",
args{
[]int{3, 2, 1},
},
1,
},
{
"in:[1,2],out:2",
args{
[]int{1, 2},
},
2,
},
{
"in:[2,2,3,1],out:1",
args{
[]int{2, 2, 3, 1},
},
1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := findThirdMax(tt.args.nums); got != tt.want {
t.Errorf("findThirdMax() = %v, want %v", got, tt.want)
}
})
}
}
func Test_findThirdMax2(t *testing.T) {
type args struct {
nums []int
}
tests := []struct {
name string
args args
want int
}{
{
"in:[3,2,1],out:1",
args{
[]int{3, 2, 1},
},
1,
},
{
"in:[1,2],out:2",
args{
[]int{1, 2},
},
2,
},
{
"in:[2,2,3,1],out:1",
args{
[]int{2, 2, 3, 1},
},
1,
},
{
"in:[2,2,3],out:3",
args{
[]int{2, 2, 3},
},
3,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := findThirdMax2(tt.args.nums); got != tt.want {
t.Errorf("findThirdMax() = %v, want %v", got, tt.want)
}
})
}
}