go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/decimal/decimal_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package decimal
     9  
    10  import (
    11  	"testing"
    12  
    13  	"go.charczuk.com/sdk/assert"
    14  )
    15  
    16  func Test_Decimal_add(t *testing.T) {
    17  	d0 := New(3.14)
    18  	d1 := New(6.28)
    19  	d3 := d1.Add(d0)
    20  	assert.ItsEqual(t, 9.42, d3.Float64())
    21  }
    22  
    23  func Test_Decimal_sub(t *testing.T) {
    24  	d0 := New(3)
    25  	d1 := New(7)
    26  	d3 := d1.Sub(d0)
    27  	assert.ItsEqual(t, 4, d3.Float64())
    28  }
    29  
    30  func Test_Decimal_div(t *testing.T) {
    31  	d0 := New(3.14)
    32  	d1 := New(6.28)
    33  	d3 := d1.Div(d0)
    34  	assert.ItsEqual(t, 2, d3.Float64())
    35  }
    36  
    37  func Test_Decimal_div_ltz(t *testing.T) {
    38  	d0 := New(3.14)
    39  	d1 := New(6.28)
    40  	d3 := d0.Div(d1)
    41  	assert.ItsEqual(t, 0.5, d3.Float64())
    42  }
    43  
    44  func Test_Decimal_mul(t *testing.T) {
    45  	d0 := New(2)
    46  	d1 := New(4)
    47  	d3 := d1.Mul(d0)
    48  	assert.ItsEqual(t, 8, d3.Float64())
    49  }
    50  
    51  func Test_Decimal_inv(t *testing.T) {
    52  	d0 := New(2)
    53  	assert.ItsEqual(t, 0.5, d0.Invert().Float64())
    54  }
    55  
    56  func Test_Decimal_abs(t *testing.T) {
    57  	d0 := New(-2)
    58  	assert.ItsEqual(t, 2, d0.Abs().Float64())
    59  
    60  	d1 := New(2)
    61  	assert.ItsEqual(t, 2, d1.Abs().Float64())
    62  }