Skip to content

Commit

Permalink
Add commend and testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
toomore committed May 3, 2015
1 parent ad4b66b commit 71db3c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func CountCountineFloat64(data []float64) (int, bool) {
return counter, data[len(data)-1] > 0
}

// CalDiff 計算兩序列的差
func CalDiff(listA, listB []float64) []float64 {
var length int
var result []float64
Expand Down
17 changes: 17 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,20 @@ func TestCountCountine(t *testing.T) {
t.Error("Should be `1 false`")
}
}

func TestCalDiff(t *testing.T) {
var sampleA = []float64{10.0, 11.1, 12.2, 13.3}
var sampleB = []float64{12.2, 11.1, 10.0}
var result = CalDiff(sampleA, sampleB)
if result[2] != float64(13.3)-float64(10.0) {
t.Error("Wrong cal.")
}
}

func BenchmarkCalDiff(b *testing.B) {
var sampleA = []float64{10.0, 11.1, 12.2, 13.3}
var sampleB = []float64{12.2, 11.1, 10.0}
for i := 0; i < b.N; i++ {
CalDiff(sampleA, sampleB)
}
}

0 comments on commit 71db3c5

Please sign in to comment.