Add Set tests

This commit is contained in:
vejnar 2020-03-10 14:58:31 -04:00
parent 5bbeff036c
commit 219e1ab036

View file

@ -282,6 +282,22 @@ func TestAt(t *testing.T) {
}
}
func TestSet(t *testing.T) {
var q Deque
for i := 0; i < 1000; i++ {
q.PushBack(i)
q.Set(i, i+50)
}
// Front to back.
for j := 0; j < q.Len(); j++ {
if q.At(j).(int) != j+50 {
t.Errorf("index %d doesn't contain %d", j, j+50)
}
}
}
func TestClear(t *testing.T) {
var q Deque
@ -444,6 +460,22 @@ func TestAtOutOfRangePanics(t *testing.T) {
})
}
func TestSetOutOfRangePanics(t *testing.T) {
var q Deque
q.PushBack(1)
q.PushBack(2)
q.PushBack(3)
assertPanics(t, "should panic when negative index", func() {
q.Set(-4, 1)
})
assertPanics(t, "should panic when index greater than length", func() {
q.Set(4, 1)
})
}
func TestInsertOutOfRangePanics(t *testing.T) {
q := new(Deque)