use shopspring/decimal library everywhere
All checks were successful
Generate check / check-generate (push) Has been skipped
Generate check / check-generate (pull_request) Has been skipped
Tests / tests (pull_request) Has been skipped

This commit is contained in:
2025-11-16 23:03:47 +00:00
parent edc1628674
commit a6d56d7441
14 changed files with 421 additions and 282 deletions

View File

@@ -3,11 +3,11 @@ package internal_test
import (
"bytes"
"fmt"
"math/big"
"testing"
"time"
"github.com/nmoniz/any2anexoj/internal"
"github.com/shopspring/decimal"
)
func TestReportLogger_Write(t *testing.T) {
@@ -25,45 +25,45 @@ func TestReportLogger_Write(t *testing.T) {
name: "single item positive",
items: []internal.ReportItem{
{
BuyValue: new(big.Float).SetFloat64(100.0),
SellValue: new(big.Float).SetFloat64(200.0),
BuyValue: decimal.NewFromFloat(100.0),
SellValue: decimal.NewFromFloat(200.0),
SellTimestamp: tNow,
},
},
want: []string{
fmt.Sprintf("%6d - realised +100.000000 on %s\n", 1, tNow.Format(time.RFC3339)),
fmt.Sprintf("%6d: realised 100 on %s\n", 1, tNow.Format(time.RFC3339)),
},
},
{
name: "single item negative",
items: []internal.ReportItem{
{
BuyValue: new(big.Float).SetFloat64(200.0),
SellValue: new(big.Float).SetFloat64(150.0),
BuyValue: decimal.NewFromFloat(200.0),
SellValue: decimal.NewFromFloat(150.0),
SellTimestamp: tNow,
},
},
want: []string{
fmt.Sprintf("%6d - realised -50.000000 on %s\n", 1, tNow.Format(time.RFC3339)),
fmt.Sprintf("%6d: realised -50 on %s\n", 1, tNow.Format(time.RFC3339)),
},
},
{
name: "multiple items",
items: []internal.ReportItem{
{
BuyValue: new(big.Float).SetFloat64(100.0),
SellValue: new(big.Float).SetFloat64(200.0),
BuyValue: decimal.NewFromFloat(100.0),
SellValue: decimal.NewFromFloat(200.0),
SellTimestamp: tNow,
},
{
BuyValue: new(big.Float).SetFloat64(200.0),
SellValue: new(big.Float).SetFloat64(150.0),
BuyValue: decimal.NewFromFloat(200.0),
SellValue: decimal.NewFromFloat(150.0),
SellTimestamp: tNow.Add(1),
},
},
want: []string{
fmt.Sprintf("%6d - realised +100.000000 on %s\n", 1, tNow.Format(time.RFC3339)),
fmt.Sprintf("%6d - realised -50.000000 on %s\n", 2, tNow.Add(1).Format(time.RFC3339)),
fmt.Sprintf("%6d: realised 100 on %s\n", 1, tNow.Format(time.RFC3339)),
fmt.Sprintf("%6d: realised -50 on %s\n", 2, tNow.Add(1).Format(time.RFC3339)),
},
},
}