diff --git a/src/interfaces/product-entity.interface.go b/src/interfaces/product-entity.interface.go index 6401687..931c0c9 100644 --- a/src/interfaces/product-entity.interface.go +++ b/src/interfaces/product-entity.interface.go @@ -56,3 +56,8 @@ func CreateNewProduct(productBase *ProductBaseStruct, calcSnapShot *CalcSnapshot b.createNewId() return b } + +func Calculate(symbol float64, snapshot *CshPremiumBuySellSnapshot) float64 { + price := symbol + float64(snapshot.Premium) + return price * (1 + float64(snapshot.Tax)/100) +} diff --git a/src/interfaces/product-entity.interface_test.go b/src/interfaces/product-entity.interface_test.go new file mode 100644 index 0000000..661f2dc --- /dev/null +++ b/src/interfaces/product-entity.interface_test.go @@ -0,0 +1,39 @@ +package interfaces + +import ( + "testing" +) + +func TestCalculate(t *testing.T) { + snapshot := &CshPremiumBuySellSnapshot{ + Premium: 10, + Tax: 5, + } + + t.Run("Positive values calculation", func(t *testing.T) { + symbol := 100.0 + expected := 115.5 + result := Calculate(symbol, snapshot) + if result != expected { + t.Errorf("Expected %f, but got %f", expected, result) + } + }) + + t.Run("Negative values calculation", func(t *testing.T) { + symbol := -50.0 + expected := -42.0 + result := Calculate(symbol, snapshot) + if result != expected { + t.Errorf("Expected %f, but got %f", expected, result) + } + }) + + t.Run("Zero values calculation", func(t *testing.T) { + symbol := 0.0 + expected := 10.5 + result := Calculate(symbol, snapshot) + if result != expected { + t.Errorf("Expected %f, but got %f", expected, result) + } + }) +}