Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
mesuutt committed May 14, 2017
1 parent 348e34c commit 1980947
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package main

import (
"testing"
)

// TODO: @mesut. Test with mocking.

var text = "brave"

func TestDisplayCount(t *testing.T) {
displayCount := 2

conf := &Config{
DisplayCount: displayCount,
}

conf.WordTypeFilters = []WordType{VERB, NOUN, ADJECTIVE, ADVERB, UNKNOWN}

tureng := &Tureng{Config: *conf}
result, _ := tureng.Translate(text)

if len(result.Translations) != displayCount {
t.Errorf("Result count should not be greater than %d. %d", displayCount, len(result.Translations))
}
}

func TestTranslate(t *testing.T) {
displayCount := 10

conf := &Config{
DisplayCount: displayCount,
}

conf.WordTypeFilters = []WordType{VERB, NOUN, ADJECTIVE, ADVERB, UNKNOWN}

tureng := &Tureng{Config: *conf}
result, _ := tureng.Translate(text)

if len(result.Translations) == 0 {
t.Errorf("Result count should not be greater than %d. %d", displayCount, len(result.Translations))
}

if result.ResultCount == 0 {
t.Errorf("ResultCount of '%s' translation should be greater than 0", text)
}
}

func TestWordTypeFiltering(t *testing.T) {

conf := &Config{
DisplayCount: 100,
WordTypeFilters: []WordType{VERB}, // Get only verbs
}

tureng := &Tureng{Config: *conf}
result, _ := tureng.Translate(text)

if len(result.Translations) != 6 {
t.Errorf("Translation result count should equal to 6")
}

conf = &Config{
DisplayCount: 100,
WordTypeFilters: []WordType{ADVERB}, // Get only adverbs
}
tureng = &Tureng{Config: *conf}
result, _ = tureng.Translate(text)

if len(result.Translations) != 0 {
t.Errorf("Translation result count should equal to 0")
}
}

func TestGettingSuggestions(t *testing.T) {

conf := &Config{
DisplayCount: 100,
WordTypeFilters: []WordType{NOUN},
}

tureng := &Tureng{Config: *conf}
result, _ := tureng.Translate("happyoooo")

if len(result.Translations) > 0 {
t.Errorf("Translation result count should equal to 0")
}

suggs := tureng.GetSuggestions()
if len(suggs) == 0 {
t.Errorf("Should be at least one suggestion for happyoooo")
}
}

0 comments on commit 1980947

Please sign in to comment.