Skip to content

Commit

Permalink
More tests are added.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Dec 23, 2024
1 parent 1191aad commit 4a12b19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 4 additions & 7 deletions trend/smma.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ type Smma[T helper.Number] struct {

// NewSmma function initializes a new SMMA instance with the default parameters.
func NewSmma[T helper.Number]() *Smma[T] {
return &Smma[T]{
Period: DefaultSmmaPeriod,
}
return NewSmmaWithPeriod[T](DefaultSmmaPeriod)
}

// NewSmmaWithPeriod function initializes a new SMMA instance with the given period.
func NewSmmaWithPeriod[T helper.Number](period int) *Smma[T] {
smma := NewSmma[T]()
smma.Period = period

return smma
return &Smma[T]{
Period: period,
}
}

// Compute function takes a channel of numbers and computes the SMMA over the specified period.
Expand Down
9 changes: 9 additions & 0 deletions trend/smma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ func TestSmma(t *testing.T) {
t.Fatal(err)
}
}

func TestSmmaString(t *testing.T) {
expected := "SMMA(10)"
actual := trend.NewSmmaWithPeriod[float64](10).String()

if actual != expected {
t.Fatalf("actual %v expected %v", actual, expected)
}
}

0 comments on commit 4a12b19

Please sign in to comment.