2016-06-26 21:51:17 +00:00
|
|
|
package kcp_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-08-20 18:55:45 +00:00
|
|
|
. "v2ray.com/core/transport/internet/kcp"
|
2017-10-24 14:15:35 +00:00
|
|
|
. "v2ray.com/ext/assert"
|
2016-06-26 21:51:17 +00:00
|
|
|
)
|
|
|
|
|
2016-07-01 09:57:13 +00:00
|
|
|
func TestSendingWindow(t *testing.T) {
|
2017-10-24 14:15:35 +00:00
|
|
|
assert := With(t)
|
2016-07-01 09:57:13 +00:00
|
|
|
|
2016-07-04 15:01:32 +00:00
|
|
|
window := NewSendingWindow(5, nil, nil)
|
2017-12-03 21:53:00 +00:00
|
|
|
window.Push(0)
|
|
|
|
window.Push(1)
|
|
|
|
window.Push(2)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(window.Len(), Equals, 3)
|
2016-07-01 09:57:13 +00:00
|
|
|
|
|
|
|
window.Remove(1)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(window.Len(), Equals, 3)
|
|
|
|
assert(window.FirstNumber(), Equals, uint32(0))
|
2016-07-01 09:57:13 +00:00
|
|
|
|
|
|
|
window.Remove(0)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(window.Len(), Equals, 1)
|
|
|
|
assert(window.FirstNumber(), Equals, uint32(2))
|
2016-07-01 09:57:13 +00:00
|
|
|
|
|
|
|
window.Remove(0)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(window.Len(), Equals, 0)
|
2016-07-01 09:57:13 +00:00
|
|
|
|
2017-12-03 21:53:00 +00:00
|
|
|
window.Push(4)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(window.Len(), Equals, 1)
|
|
|
|
assert(window.FirstNumber(), Equals, uint32(4))
|
2016-07-01 13:54:04 +00:00
|
|
|
|
2017-12-03 21:53:00 +00:00
|
|
|
window.Push(5)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(window.Len(), Equals, 2)
|
2016-07-01 13:54:04 +00:00
|
|
|
|
|
|
|
window.Remove(1)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(window.Len(), Equals, 2)
|
2016-07-01 13:54:04 +00:00
|
|
|
|
|
|
|
window.Remove(0)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(window.Len(), Equals, 0)
|
2016-07-01 09:57:13 +00:00
|
|
|
}
|