Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
schwartzm committed Jun 26, 2019
1 parent 40d405f commit 0bb3fa5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions wordfrequency/wordfrequency_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package wordfrequency

import (
"bytes"
"fmt"
"reflect"
"testing"
)

func TestGetWordFrequency(t *testing.T) {
input := bytes.NewBufferString(
"hello WORLD Hello world World hello cats HELLO cats dogs")

/* NOTE: DeepEqual nuance: Can't compare [4]Word with
* []Word, because Array != Slice.
* See https://play.golang.org/p/aDPIwjDq5bJ
* Also, order of expect slice is important. Keep as is.
*/
expect := []Word{Word{"hello", 4}, Word{"world", 3},
Word{"cats", 2}, Word{"dogs", 1}}

actual, err := GetWordFrequency(input, SORT_DESC, 3)

if err != nil {
fmt.Println(err)
}

if !reflect.DeepEqual(expect, actual.Words) {
t.Errorf("Expected %v; got %v\n", expect, actual.Words)
}
}

0 comments on commit 0bb3fa5

Please sign in to comment.