go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/experiments/cb-feed/pkg/price/price_test.go (about)

     1  package price
     2  
     3  import (
     4  	"testing"
     5  
     6  	"go.charczuk.com/sdk/assert"
     7  )
     8  
     9  func Test_Price_add(t *testing.T) {
    10  	p0 := Parse("50.00")
    11  	p1 := Parse("55.00")
    12  
    13  	res := p0.Add(p1)
    14  	assert.ItsEqual(t, Parse("105.00"), res)
    15  }
    16  
    17  func Test_Price_sub(t *testing.T) {
    18  	p0 := Parse("50.00")
    19  	p1 := Parse("55.00")
    20  
    21  	res := p0.Sub(p1)
    22  	assert.ItsEqual(t, Parse("-5.00"), res)
    23  }
    24  
    25  func Test_Price_mul(t *testing.T) {
    26  	p0 := Parse("5.00")
    27  	p1 := Parse("2.00")
    28  
    29  	res := p0.Mul(p1)
    30  	assert.ItsEqual(t, Parse("10.00"), res)
    31  }
    32  
    33  func Test_Price_div(t *testing.T) {
    34  	p0 := Parse("10.00")
    35  	p1 := Parse("2.00")
    36  
    37  	res := p0.Div(p1)
    38  	assert.ItsEqual(t, Parse("5.00"), res)
    39  }
    40  
    41  func Test_Price_rshift(t *testing.T) {
    42  	p0 := Parse("10.00")
    43  
    44  	res := p0.RightShift(2)
    45  	assert.ItsEqual(t, Parse("40.00"), res)
    46  }
    47  
    48  func Test_Price_lshift(t *testing.T) {
    49  	p0 := Parse("10.00")
    50  
    51  	res := p0.LeftShift(2)
    52  	assert.ItsEqual(t, Parse("2.50"), res)
    53  }