Skip to content
This repository has been archived by the owner on May 14, 2023. It is now read-only.

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Sep 24, 2017
1 parent 5afd01b commit 8857f6b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
7 changes: 0 additions & 7 deletions summarize/readability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ package summarize

import (
"encoding/json"
"fmt"
"path/filepath"
"testing"

"github.com/jdkato/prose/internal/util"
"github.com/stretchr/testify/assert"
)

var testdata = filepath.Join("..", "testdata")

func check(expected, observed float64) bool {
return fmt.Sprintf("%0.2f", expected) == fmt.Sprintf("%0.2f", observed)
}

func TestReadability(t *testing.T) {
tests := make([]testCase, 0)
cases := util.ReadDataFile(filepath.Join(testdata, "summarize.json"))
Expand Down
6 changes: 6 additions & 0 deletions summarize/summarize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
"github.com/stretchr/testify/assert"
)

var testdata = filepath.Join("..", "testdata")

func check(expected, observed float64) bool {
return fmt.Sprintf("%0.2f", expected) == fmt.Sprintf("%0.2f", observed)
}

type testCase struct {
Text string
Sentences float64
Expand Down
3 changes: 1 addition & 2 deletions summarize/syllables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/jdkato/prose/internal/util"
"github.com/jdkato/syllables"
"github.com/montanaflynn/stats"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -87,7 +86,7 @@ func BenchmarkSyllablesIn(b *testing.B) {

for n := 0; n < b.N; n++ {
for word := range tests {
syllables.In(word)
Syllables(word)
}
}
}
23 changes: 0 additions & 23 deletions tokenize/regexp_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
package tokenize

import (
"encoding/json"
"path/filepath"
"testing"

"github.com/jdkato/prose/internal/util"
"github.com/stretchr/testify/assert"
)

func getWordData(file string) ([]string, [][]string) {
in := util.ReadDataFile(filepath.Join(testdata, "treebank_sents.json"))
out := util.ReadDataFile(filepath.Join(testdata, file))

input := []string{}
output := [][]string{}

util.CheckError(json.Unmarshal(in, &input))
util.CheckError(json.Unmarshal(out, &output))

return input, output
}

func getWordBenchData() []string {
in := util.ReadDataFile(filepath.Join(testdata, "treebank_sents.json"))
input := []string{}
util.CheckError(json.Unmarshal(in, &input))
return input
}

func TestWordPunctTokenizer(t *testing.T) {
input, output := getWordData("word_punct.json")
wordTokenizer := NewWordPunctTokenizer()
Expand Down
25 changes: 25 additions & 0 deletions tokenize/tokenize_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
package tokenize

import (
"encoding/json"
"fmt"
"path/filepath"
"testing"

"github.com/jdkato/prose/internal/util"
"github.com/stretchr/testify/assert"
)

var testdata = filepath.Join("..", "testdata")

func getWordData(file string) ([]string, [][]string) {
in := util.ReadDataFile(filepath.Join(testdata, "treebank_sents.json"))
out := util.ReadDataFile(filepath.Join(testdata, file))

input := []string{}
output := [][]string{}

util.CheckError(json.Unmarshal(in, &input))
util.CheckError(json.Unmarshal(out, &output))

return input, output
}

func getWordBenchData() []string {
in := util.ReadDataFile(filepath.Join(testdata, "treebank_sents.json"))
input := []string{}
util.CheckError(json.Unmarshal(in, &input))
return input
}

func ExampleNewWordBoundaryTokenizer() {
t := NewWordBoundaryTokenizer()
fmt.Println(t.Tokenize("They'll save and invest more."))
Expand Down
3 changes: 0 additions & 3 deletions tokenize/treebank_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package tokenize

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

var testdata = filepath.Join("..", "testdata")

func TestTreebankWordTokenizer(t *testing.T) {
input, output := getWordData("treebank_words.json")
word := NewTreebankWordTokenizer()
Expand Down
2 changes: 0 additions & 2 deletions transform/title_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/stretchr/testify/assert"
)

var testdata = filepath.Join("..", "testdata")

type testCase struct {
Input string
Expect string
Expand Down
7 changes: 6 additions & 1 deletion transform/transform_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package transform

import "fmt"
import (
"fmt"
"path/filepath"
)

var testdata = filepath.Join("..", "testdata")

func ExampleNewTitleConverter() {
tc := NewTitleConverter(APStyle)
Expand Down

0 comments on commit 8857f6b

Please sign in to comment.