github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/utils/math_test.go (about)

     1  // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
     2  
     3  package utils
     4  
     5  import (
     6  	. "github.com/pingcap/check"
     7  )
     8  
     9  type testMathSuite struct{}
    10  
    11  var _ = Suite(&testMathSuite{})
    12  
    13  func (*testMathSuite) TestMinInt(c *C) {
    14  	c.Assert(MinInt(1, 2), Equals, 1)
    15  	c.Assert(MinInt(2, 1), Equals, 1)
    16  	c.Assert(MinInt(4, 2, 1, 3), Equals, 1)
    17  	c.Assert(MinInt(1, 1), Equals, 1)
    18  }
    19  
    20  func (*testMathSuite) TestMaxInt(c *C) {
    21  	c.Assert(MaxInt(1, 2), Equals, 2)
    22  	c.Assert(MaxInt(2, 1), Equals, 2)
    23  	c.Assert(MaxInt(4, 2, 1, 3), Equals, 4)
    24  	c.Assert(MaxInt(1, 1), Equals, 1)
    25  }
    26  
    27  func (*testMathSuite) TestClampInt(c *C) {
    28  	c.Assert(ClampInt(100, 1, 3), Equals, 3)
    29  	c.Assert(ClampInt(2, 1, 3), Equals, 2)
    30  	c.Assert(ClampInt(0, 1, 3), Equals, 1)
    31  	c.Assert(ClampInt(0, 1, 1), Equals, 1)
    32  	c.Assert(ClampInt(100, 1, 1), Equals, 1)
    33  }
    34  
    35  func (*testMathSuite) TestMinInt64(c *C) {
    36  	c.Assert(MinInt(1, 2), Equals, 1)
    37  	c.Assert(MinInt(2, 1), Equals, 1)
    38  	c.Assert(MinInt(4, 2, 1, 3), Equals, 1)
    39  	c.Assert(MinInt(1, 1), Equals, 1)
    40  }
    41  
    42  func (*testMathSuite) TestNextPowerOfTwo(c *C) {
    43  	c.Assert(NextPowerOfTwo(1), Equals, int64(1))
    44  	c.Assert(NextPowerOfTwo(3), Equals, int64(4))
    45  	c.Assert(NextPowerOfTwo(255), Equals, int64(256))
    46  	c.Assert(NextPowerOfTwo(1024), Equals, int64(1024))
    47  	c.Assert(NextPowerOfTwo(0xabcd1234), Equals, int64(0x100000000))
    48  }