Skip to content

Commit

Permalink
Add tests for Reversed util
Browse files Browse the repository at this point in the history
  • Loading branch information
frankh committed Jan 11, 2018
1 parent 3d39ad1 commit b006c71
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package utils

import (
"bytes"
"testing"
)

func TestEmpty(t *testing.T) {
str := []byte{}

if !bytes.Equal(Reversed(str), []byte{}) {
t.Errorf("Failed on empty slice")
}
}

func TestSingle(t *testing.T) {
str := []byte{1}

if !bytes.Equal(Reversed(str), []byte{1}) {
t.Errorf("Failed on slice with single element")
}
}

func TestReverseOrder(t *testing.T) {
str := []byte{1, 2, 3}

if !bytes.Equal(Reversed(str), []byte{3, 2, 1}) {
t.Errorf("Failed on slice with single element")
}
}

func TestReverseUnordered(t *testing.T) {
str := []byte{1, 2, 1, 3, 1}

if !bytes.Equal(Reversed(str), []byte{1, 3, 1, 2, 1}) {
t.Errorf("Failed on slice with single element")
}
}

0 comments on commit b006c71

Please sign in to comment.