|
|
@@ -69,6 +69,19 @@ func TestQueueGet(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestQueueGetNegative(t *testing.T) {
|
|
|
+ q := New()
|
|
|
+
|
|
|
+ for i := 0; i < 1000; i++ {
|
|
|
+ q.Add(i)
|
|
|
+ for j := 1; j <= q.Length(); j++ {
|
|
|
+ if q.Get(-j).(int) != q.Length()-j {
|
|
|
+ t.Errorf("index %d doesn't contain %d", -j, q.Length()-j)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestQueueGetOutOfRangePanics(t *testing.T) {
|
|
|
q := New()
|
|
|
|
|
|
@@ -77,7 +90,7 @@ func TestQueueGetOutOfRangePanics(t *testing.T) {
|
|
|
q.Add(3)
|
|
|
|
|
|
assertPanics(t, "should panic when negative index", func() {
|
|
|
- q.Get(-1)
|
|
|
+ q.Get(-4)
|
|
|
})
|
|
|
|
|
|
assertPanics(t, "should panic when index greater than length", func() {
|