From d1d7b0a7e4d9bb99493341e379fb8b56e62e0234 Mon Sep 17 00:00:00 2001 From: Guangwen Feng Date: Mon, 30 Dec 2019 10:47:13 +0800 Subject: [PATCH] test: add unit test case for func TransRate Signed-off-by: Guangwen Feng --- pkg/ratelimiter/ratelimiter_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/ratelimiter/ratelimiter_test.go b/pkg/ratelimiter/ratelimiter_test.go index c06bf8df1..ddc8da25b 100644 --- a/pkg/ratelimiter/ratelimiter_test.go +++ b/pkg/ratelimiter/ratelimiter_test.go @@ -115,3 +115,20 @@ func (suite *RateLimiterSuite) TestRateLimiter_AcquireNonBlocking(c *check.C) { rl.blocking(1000) c.Assert(rl.AcquireNonBlocking(1000), check.Equals, int64(1000)) } + +func (suite *RateLimiterSuite) TestTransRate(c *check.C) { + var cases = []struct { + r int64 + e int64 + }{ + {666, 1000}, + {2048, 3000}, + {123456, 124000}, + {0, 10486000}, + {-233, 10486000}, + } + for _, cc := range cases { + v := TransRate(cc.r) + c.Assert(v, check.Equals, cc.e) + } +}