From c18d944f6f53152ddcda3c707571f17307054e48 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Tue, 11 Jun 2019 23:34:28 -0400 Subject: tests for most of query.go --- svc/query_test.go | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/svc/query_test.go b/svc/query_test.go index 9fe6496..687b102 100644 --- a/svc/query_test.go +++ b/svc/query_test.go @@ -9,6 +9,36 @@ import ( "github.com/getwtxt/registry" ) +func Test_dedupe(t *testing.T) { + t.Run("Simple Deduplication Test", func(t *testing.T) { + start := []string{ + "first", + "second", + "third", + "third", + } + finish := dedupe(start) + if reflect.DeepEqual(start, finish) { + t.Errorf("Deduplication didn't occur\n") + } + if len(finish) != 3 { + t.Errorf("Ending length not what was expected\n") + } + }) +} + +func Benchmark_dedupe(b *testing.B) { + start := []string{ + "first", + "second", + "third", + "third", + } + for i := 0; i < b.N; i++ { + dedupe(start) + } +} + func Test_parseQueryOut(t *testing.T) { initTestConf() @@ -71,7 +101,53 @@ func Benchmark_parseQueryOut(b *testing.B) { for i := 0; i < b.N; i++ { parseQueryOut(data) } +} +func Test_joinQueryOuts(t *testing.T) { + first := []string{ + "one", + "two", + "three", + } + second := []string{ + "three", + "four", + "five", + "six", + } + t.Run("Joining two string slices", func(t *testing.T) { + third := joinQueryOuts(first, second) + if len(third) != (len(first) + len(second) - 1) { + t.Errorf("Was not combined or deduplicated properly\n") + } + fourth := make([]string, 6) + for i := 0; i < len(first); i++ { + fourth[i] = first[i] + } + for i := 1; i < len(second); i++ { + fourth[2+i] = second[i] + } + if !reflect.DeepEqual(fourth, third) { + t.Errorf("Output not deeply equal to manual construction\n") + } + }) +} + +func Benchmark_joinQueryOuts(b *testing.B) { + first := []string{ + "one", + "two", + "three", + } + second := []string{ + "three", + "four", + "five", + "six", + } + for i := 0; i < b.N; i++ { + joinQueryOuts(first, second) + } } func Test_compositeStatusQuery(t *testing.T) { -- cgit 1.4.1-2-gfad0