You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
971 B
47 lines
971 B
2 years ago
|
package deletemiddle_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
dm "git.jxs.me/leetgo/deletemiddle"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func buildList(values []int) *dm.ListNode {
|
||
|
var result *dm.ListNode
|
||
|
|
||
|
for i := len(values) - 1; i >= 0; i-- {
|
||
|
result = &dm.ListNode{Val: values[i], Next: result}
|
||
|
}
|
||
|
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
func TestEmpty(t *testing.T) {
|
||
|
var head *dm.ListNode
|
||
|
require.Nil(t, dm.Delete(head))
|
||
|
}
|
||
|
|
||
|
func TestOne(t *testing.T) {
|
||
|
head := buildList([]int{1})
|
||
|
require.Nil(t, dm.Delete(head))
|
||
|
}
|
||
|
|
||
|
func TestTwo(t *testing.T) {
|
||
|
head := buildList([]int{2, 1})
|
||
|
expected := buildList([]int{2})
|
||
|
require.Equal(t, expected, dm.Delete(head))
|
||
|
}
|
||
|
|
||
|
func TestFour(t *testing.T) {
|
||
|
head := buildList([]int{1, 2, 3, 4})
|
||
|
expected := buildList([]int{1, 2, 4})
|
||
|
require.Equal(t, expected, dm.Delete(head))
|
||
|
}
|
||
|
|
||
|
func TestExample1(t *testing.T) {
|
||
|
head := buildList([]int{1, 3, 4, 7, 1, 2, 6})
|
||
|
expected := buildList([]int{1, 3, 4, 1, 2, 6})
|
||
|
require.Equal(t, expected, dm.Delete(head))
|
||
|
}
|