From 1cd23814d9590880f486f0ed9993216e41733ba9 Mon Sep 17 00:00:00 2001 From: Andinus Date: Tue, 7 Apr 2020 01:34:17 +0530 Subject: Add tests for Sort and SlowSort --- lexical/slowsort_test.go | 19 +++++++++++++++++++ lexical/sort_test.go | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 lexical/slowsort_test.go create mode 100644 lexical/sort_test.go diff --git a/lexical/slowsort_test.go b/lexical/slowsort_test.go new file mode 100644 index 0000000..20e1a3c --- /dev/null +++ b/lexical/slowsort_test.go @@ -0,0 +1,19 @@ +package lexical + +import "testing" + +// TestSlowSort tests the SlowSort func. +func TestSlowSort(t *testing.T) { + words := make(map[string]string) + + words["dcba"] = "abcd" + words["zyx"] = "xyz" + + for word, sorted := range words { + s := SlowSort(word) + if s != sorted { + t.Errorf("Sort func failed, got %s, want %s", + s, sorted) + } + } +} diff --git a/lexical/sort_test.go b/lexical/sort_test.go new file mode 100644 index 0000000..c4a823e --- /dev/null +++ b/lexical/sort_test.go @@ -0,0 +1,19 @@ +package lexical + +import "testing" + +// TestSort tests the Sort func. +func TestSort(t *testing.T) { + words := make(map[string]string) + + words["dcba"] = "abcd" + words["zyx"] = "xyz" + + for word, sorted := range words { + s := Sort(word) + if s != sorted { + t.Errorf("Sort func failed, got %s, want %s", + s, sorted) + } + } +} -- cgit 1.4.1-2-gfad0