From 61b01c92738b5b3e6b05575ff9746e32a23d5b36 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Wed, 1 Apr 2020 18:58:12 +0100 Subject: [PATCH] ids: Add test for SortIDs --- ids/id_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ids/id_test.go b/ids/id_test.go index d013b24..82f102c 100644 --- a/ids/id_test.go +++ b/ids/id_test.go @@ -5,6 +5,7 @@ package ids import ( "bytes" + "reflect" "testing" ) @@ -174,3 +175,20 @@ func TestIDString(t *testing.T) { }) } } + +func TestSortIDs(t *testing.T) { + ids := []ID{ + NewID([32]byte{'e', 'v', 'a', ' ', 'l', 'a', 'b', 's'}), + NewID([32]byte{'W', 'a', 'l', 'l', 'e', ' ', 'l', 'a', 'b', 's'}), + NewID([32]byte{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}), + } + SortIDs(ids) + expected := []ID{ + NewID([32]byte{'W', 'a', 'l', 'l', 'e', ' ', 'l', 'a', 'b', 's'}), + NewID([32]byte{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'}), + NewID([32]byte{'e', 'v', 'a', ' ', 'l', 'a', 'b', 's'}), + } + if !reflect.DeepEqual(ids, expected) { + t.Fatal("[]ID was not sorted lexographically") + } +}