sending_test.go 881 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package kcp_test
  2. import (
  3. "testing"
  4. "v2ray.com/core/testing/assert"
  5. . "v2ray.com/core/transport/internet/kcp"
  6. )
  7. func TestSendingWindow(t *testing.T) {
  8. assert := assert.On(t)
  9. window := NewSendingWindow(5, nil, nil)
  10. window.Push(0, []byte{})
  11. window.Push(1, []byte{})
  12. window.Push(2, []byte{})
  13. assert.Int(window.Len()).Equals(3)
  14. window.Remove(1)
  15. assert.Int(window.Len()).Equals(3)
  16. assert.Uint32(window.FirstNumber()).Equals(0)
  17. window.Remove(0)
  18. assert.Int(window.Len()).Equals(1)
  19. assert.Uint32(window.FirstNumber()).Equals(2)
  20. window.Remove(0)
  21. assert.Int(window.Len()).Equals(0)
  22. window.Push(4, []byte{})
  23. assert.Int(window.Len()).Equals(1)
  24. assert.Uint32(window.FirstNumber()).Equals(4)
  25. window.Push(5, []byte{})
  26. assert.Int(window.Len()).Equals(2)
  27. window.Remove(1)
  28. assert.Int(window.Len()).Equals(2)
  29. window.Remove(0)
  30. assert.Int(window.Len()).Equals(0)
  31. }