Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Commit

Permalink
[A] Tools tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nekovalue committed Jul 29, 2021
1 parent a0ddad8 commit 5daa830
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ package tools
func RemoveSliceElementByIndex(s []string, i int) []string {
return append(s[:i], s[i+1:]...)
}

// EqualSlice checks slices to equality
func EqualSlice(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
33 changes: 33 additions & 0 deletions tests/tools_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tests

import (
"github.com/nekovalue/unpckr/pkg/tools"
"testing"
)

func TestRemoveSliceElementByIndex(t *testing.T) {
// Arrange
testTable := []struct {
fakeSlice []string
indexToRemove int
expectedSlice []string
}{
{
fakeSlice: []string{"first", "second", "third"},
indexToRemove: 0,
expectedSlice: []string{"second", "third"},
},
}

// Act
for _, testCase := range testTable {
value := tools.RemoveSliceElementByIndex(testCase.fakeSlice, testCase.indexToRemove)

t.Logf("Calling RemoveSliceElementByIndex(%v, %v)", testCase.fakeSlice, testCase.indexToRemove)

// Assert
if !tools.EqualSlice(value, testCase.expectedSlice) {
t.Errorf("Uncorrect slice. Expected %v, got %v", testCase.expectedSlice, value)
}
}
}

0 comments on commit 5daa830

Please sign in to comment.