|
|
@@ -49,5 +49,39 @@ func TestFlowAdd(t *testing.T) {
|
|
|
if f.add(1) {
|
|
|
t.Fatal("adding 1 to max shouldn't be allowed")
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+func TestFlowAddOverflow(t *testing.T) {
|
|
|
+ var f flow
|
|
|
+ if !f.add(0) {
|
|
|
+ t.Fatal("failed to add 0")
|
|
|
+ }
|
|
|
+ if !f.add(-1) {
|
|
|
+ t.Fatal("failed to add -1")
|
|
|
+ }
|
|
|
+ if !f.add(0) {
|
|
|
+ t.Fatal("failed to add 0")
|
|
|
+ }
|
|
|
+ if !f.add(1) {
|
|
|
+ t.Fatal("failed to add 1")
|
|
|
+ }
|
|
|
+ if !f.add(1) {
|
|
|
+ t.Fatal("failed to add 1")
|
|
|
+ }
|
|
|
+ if !f.add(0) {
|
|
|
+ t.Fatal("failed to add 0")
|
|
|
+ }
|
|
|
+ if !f.add(-3) {
|
|
|
+ t.Fatal("failed to add -3")
|
|
|
+ }
|
|
|
+ if got, want := f.available(), int32(-2); got != want {
|
|
|
+ t.Fatalf("size = %d; want %d", got, want)
|
|
|
+ }
|
|
|
+ if !f.add(1<<31 - 1) {
|
|
|
+ t.Fatal("failed to add 2^31-1")
|
|
|
+ }
|
|
|
+ if got, want := f.available(), int32(1+-3+(1<<31-1)); got != want {
|
|
|
+ t.Fatalf("size = %d; want %d", got, want)
|
|
|
+ }
|
|
|
|
|
|
}
|