Skip to content

Commit

Permalink
fixed simple cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
knoxfighter committed May 5, 2020
1 parent 5633f29 commit 4402264
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"strings"
)

var dictionary map[string][]Word
//var dictionary map[string][]Word
var dictionary = make(map[string][]Word)
var dictionaryCached bool

// check if a file exists
Expand Down
57 changes: 40 additions & 17 deletions cache_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
package fwew_lib

import (
"fmt"
"log"
"reflect"
"testing"
)

func Test_cacheDict(t *testing.T) {
// cache dict and test only one entry

log.Println("huhu")
fmt.Println("buh!")

//4 en 'ampi ˈʔ·am.p·i '<0><1>amp<2>i vtr. touch ASG; http://naviteri.org/2012/11/renu-ayinanfyaya-the-senses-paradigm/ (27 November 2012) 1 'am-pi '.amp.i
// 4 de 'ampi ˈʔ·am.p·i '<0><1>amp<2>i vtr. berühren ASG; http://naviteri.org/2012/11/renu-ayinanfyaya-the-senses-paradigm/ (27 November 2012) 1 'am-pi '.amp.i
word := Word{
ID: "32",
ID: "4",
LangCode: "de",
Navi: "'awve",
IPA: "ˈʔaw.vɛ",
InfixLocations: "NULL",
PartOfSpeech: "adj.",
Definition: "erste/r/s",
Source: "ASG",
Navi: "'ampi",
IPA: "ˈʔ·am.p·i",
InfixLocations: "'<0><1>amp<2>i",
PartOfSpeech: "vtr.",
Definition: "berühren",
Source: "ASG; http://naviteri.org/2012/11/renu-ayinanfyaya-the-senses-paradigm/ (27 November 2012)",
Stressed: "1",
Syllables: "'aw-ve",
InfixDots: "NULL",
Syllables: "'am-pi",
InfixDots: "'.amp.i",
Affixes: nil,
Attempt: "",
}
Expand All @@ -33,7 +29,34 @@ func Test_cacheDict(t *testing.T) {
if err != nil {
t.Errorf("Error caching Dictionary!!")
}
if !reflect.DeepEqual(dictionary["de"][8], word) {
t.Errorf("Read wrong word from cache: expected \"%s\", but got \"%s\"", word, dictionary["de"][8])
entry := dictionary["de"][0]
if !word.Equals(entry) {
t.Errorf("Read wrong word from cache:\n"+
"Id: \"%s\" == \"%s\"\n"+
"LangCode: \"%s\" == \"%s\"\n"+
"Navi: \"%s\" == \"%s\"\n"+
"Attempt: \"%s\" == \"%s\"\n"+
"IPA: \"%s\" == \"%s\"\n"+
"InfixLocations: \"%s\" == \"%s\"\n"+
"PartOfSpeech: \"%s\" == \"%s\"\n"+
"Definition: \"%s\" == \"%s\"\n"+
"Source: \"%s\" == \"%s\"\n"+
"Stressed: \"%s\" == \"%s\"\n"+
"Syllables: \"%s\" == \"%s\"\n"+
"InfixDots: \"%s\" == \"%s\"\n"+
"Affixes: \"%s\" == \"%s\"",
word.ID, entry.ID,
word.LangCode, entry.LangCode,
word.Navi, entry.Navi,
word.Attempt, entry.Attempt,
word.IPA, entry.IPA,
word.InfixLocations, entry.InfixLocations,
word.PartOfSpeech, entry.PartOfSpeech,
word.Definition, entry.Definition,
word.Source, entry.Source,
word.Stressed, entry.Stressed,
word.Syllables, entry.Syllables,
word.InfixDots, entry.InfixDots,
word.Affixes, entry.Affixes)
}
}
2 changes: 1 addition & 1 deletion txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func init() {
texts["name"] = "fwew"
texts["tip"] = "type \"/help\" or \"/commands\" for more info"
texts["author"] = "Tirea Aean"
Version.DictBuild = SHA1Hash(texts["dictionary"])
Version.DictBuild = SHA1Hash(findDictionaryFile())
texts["header"] = fmt.Sprintf("%s\n%s\n", Version, texts["tip"])
texts["languages"] = "de, en, et, fr, hu, nl, pl, ru, sv"
texts["POSFilters"] = "allvtr.n.num.pn.adv.adj.vin.v.inter.part.svin.adp.adv., n.vtrm.vim.conj.pn., sbd.n., intj.intj."
Expand Down
29 changes: 29 additions & 0 deletions word.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,32 @@ func CloneWordStruct(w Word) Word {
}
return nw
}

func (w *Word) Equals(other Word) bool {
//ID string
// LangCode string
// Navi string
// IPA string
// InfixLocations string
// PartOfSpeech string
// Definition string
// Source string
// Stressed string
// Syllables string
// InfixDots string
//
// Affixes map[string][]string
// Attempt string
return w.ID == other.ID &&
w.LangCode == other.LangCode &&
w.Navi == other.Navi &&
w.IPA == other.IPA &&
w.InfixLocations == other.InfixLocations &&
w.PartOfSpeech == other.PartOfSpeech &&
w.Definition == other.Definition &&
w.Source == other.Source &&
w.Stressed == other.Stressed &&
w.Syllables == other.Syllables &&
w.InfixDots == other.InfixDots &&
w.Attempt == other.Attempt
}

0 comments on commit 4402264

Please sign in to comment.