Something went wrong. Try again.
PoC API allowing to add/retrieve synonyms.
Something went wrong. Try again.
synonym-api synonyms_test.go
1.2 kB · 59 lines
Go
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960package main
import "testing"
// todo: test graph logic:// 1. add nodes -> retrieve synonyms (direct neighbors)// 2. add nodes -> retrive synonyms transistively (2. level neighbors)
func TestSimpleSynonymRetrieval(t *testing.T) { // arrange g := Graph{} word := "test" word2 := "test2"
g.ConnectNodes(word, word2)
// act synonyms, err := g.GetDirectNeighbours(word)
// assert if err != nil { t.Error("should not throw an error") }
if len(synonyms) != 1 { t.Error("should contain exactly one synonym") }
if synonyms[0] != word2 { t.Errorf("registered synonym should be '%s'", word2) }}
func TestTransiveSynonymRetrieval(t *testing.T) { // arrange g := Graph{} word := "test" word2 := "test2" word3 := "test3"
g.ConnectNodes(word, word2) g.ConnectNodes(word2, word3)
// act synonyms, err := g.GetDirectAndSecondLevelNeighbours(word)
// assert if err != nil { t.Error("should not throw an error") }
if len(synonyms) != 2 { t.Errorf("should contain exactly two synonym, found %d", len(synonyms)) }
if synonyms[0] != word2 && synonyms[1] != word3 { t.Errorf("registered synonym should be '%s'", word2) }}