Skip to content

Commit d2fe51b

Browse files
committed
Mode calculation fix and tests
1 parent 4dd27fe commit d2fe51b

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

mode.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func Mode(input Float64Data) (mode []float64, err error) {
2525
case cnt > maxCnt:
2626
mode = append(mode[:0], c[i-1])
2727
maxCnt, cnt = cnt, 1
28+
default:
29+
cnt = 1
2830
}
2931
}
3032
switch {

mode_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ func TestMode(t *testing.T) {
1616
{[]float64{5, 5, 3, 3, 4, 2, 1}, []float64{3, 5}},
1717
{[]float64{1}, []float64{1}},
1818
{[]float64{-50, -46.325, -46.325, -.87, 1, 2.1122, 3.20, 5, 15, 15, 15.0001}, []float64{-46.325, 15}},
19+
{[]float64{1, 2, 3, 4, 4, 4, 4, 4, 5, 3, 6, 7, 5, 0, 8, 8, 7, 6, 9, 9}, []float64{4}},
20+
{[]float64{76, 76, 110, 76, 76, 76, 76, 119, 76, 76, 76, 76, 31, 31, 31, 31, 83, 83, 83, 78, 78, 78, 78, 78, 78, 78, 78}, []float64{76}},
1921
} {
2022
got, err := Mode(c.in)
2123
if err != nil {

0 commit comments

Comments
 (0)