Evan Huus 11 anos atrás
pai
commit
25134b6500
1 arquivos alterados com 21 adições e 0 exclusões
  1. 21 0
      queue_test.go

+ 21 - 0
queue_test.go

@@ -2,6 +2,27 @@ package queue
 
 import "testing"
 
+func TestQueueLength(t *testing.T) {
+	q := New()
+
+	if q.Length() != 0 {
+		t.Error("empty queue length not 0")
+	}
+
+	for i := 0; i < 1000; i++ {
+		q.Add(i)
+		if q.Length() != i+1 {
+			t.Error("adding: queue with", i , "elements has length", q.Length())
+		}
+	}
+	for i := 0; i < 1000; i++ {
+		q.Remove()
+		if q.Length() != 1000-i-1 {
+			t.Error("removing: queue with", 1000-i-i , "elements has length", q.Length())
+		}
+	}
+}
+
 // General warning: Go's benchmark utility (go test -bench .) increases the number of
 // iterations until the benchmarks take a reasonable amount of time to run; memory usage
 // is *NOT* considered. On my machine, these benchmarks hit around ~1GB before they've had