github.com/zooyer/miskit@v1.0.71/utils/math/math_test.go (about)

     1  /**
     2   * @Author: zzy
     3   * @Email: zhangzhongyuan@didiglobal.com
     4   * @Description:
     5   * @File: math_test.go
     6   * @Package: maths
     7   * @Version: 1.0.0
     8   * @Date: 2021/12/15 8:41 下午
     9   */
    10  
    11  package math
    12  
    13  import (
    14  	"github.com/stretchr/testify/assert"
    15  	"testing"
    16  )
    17  
    18  func TestCeil(t *testing.T) {
    19  	assert.Equal(t, Ceil(1.23456, 0), 2.0)
    20  	assert.Equal(t, Ceil(1.23456, 1), 1.3)
    21  	assert.Equal(t, Ceil(1.23456, 2), 1.24)
    22  	assert.Equal(t, Ceil(1.23456, 3), 1.235)
    23  	assert.Equal(t, Ceil(1.23456, 4), 1.2346)
    24  	assert.Equal(t, Ceil(1.23456, 5), 1.23457)
    25  	assert.Equal(t, Ceil(1.23456, 6), 1.23456)
    26  }
    27  
    28  func TestFloor(t *testing.T) {
    29  	assert.Equal(t, Floor(1.23456, 0), 1.0)
    30  	assert.Equal(t, Floor(1.23456, 1), 1.2)
    31  	assert.Equal(t, Floor(1.23456, 2), 1.23)
    32  	assert.Equal(t, Floor(1.23456, 3), 1.234)
    33  	assert.Equal(t, Floor(1.23456, 4), 1.2345)
    34  	assert.Equal(t, Floor(1.23456, 5), 1.23456)
    35  	assert.Equal(t, Floor(1.23456, 6), 1.23456)
    36  }
    37  
    38  func TestRound(t *testing.T) {
    39  	assert.Equal(t, Round(1.23456, 0), 1.0)
    40  	assert.Equal(t, Round(1.23456, 1), 1.2)
    41  	assert.Equal(t, Round(1.23456, 2), 1.23)
    42  	assert.Equal(t, Round(1.23456, 3), 1.235)
    43  	assert.Equal(t, Round(1.23456, 4), 1.2346)
    44  	assert.Equal(t, Round(1.23456, 5), 1.23456)
    45  	assert.Equal(t, Round(1.23456, 6), 1.23456)
    46  }