Skip to content

Commit

Permalink
Basic Testing Added
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurboss committed Mar 25, 2024
1 parent ec06952 commit c3701c5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/interfaces/product-entity.interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
39 changes: 39 additions & 0 deletions src/interfaces/product-entity.interface_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}

0 comments on commit c3701c5

Please sign in to comment.