Skip to content

Commit

Permalink
Fix delAll + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andpol committed Jan 29, 2019
1 parent f6ae270 commit 63eb161
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion check/int32_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func delAt(a []int32, i int) []int32 {
}

func delAll(a []int32, el int32) []int32 {
for i, ok := indexOf(a, el); ok; {
for i, ok := indexOf(a, el); ok; i, ok = indexOf(a, el) {
a = delAt(a, i)
}
return a
Expand Down
76 changes: 76 additions & 0 deletions check/int32_slice_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package check

import (
"reflect"
"testing"
)

// contains() tests

func Test_Contains_ReturnsFalse(t *testing.T) {
if contains([]int32{1, 2, 3}, 4) == true {
t.Error()
}
}

func Test_Contains_ReturnsTrue(t *testing.T) {
if contains([]int32{1, 2, 3}, 2) == false {
t.Error()
}
}

// indexOf() tests

func Test_IndexOf_ValueExists(t *testing.T) {
i, result := indexOf([]int32{1, 2, 3}, 2)
if i != 1 || result != true {
t.Error()
}
}

func Test_IndexOf_ValueDoesntExists(t *testing.T) {
i, result := indexOf([]int32{1, 2, 3}, 4)
if i != -1 || result != false {
t.Error()
}
}

// delAt() tests

func Test_DelAt_ValueExists(t *testing.T) {
if !reflect.DeepEqual(delAt([]int32{1, 2, 3}, 1), []int32{1, 3}) {
t.Error()
}
}

// delAll() tests

func Test_DelAll_Single(t *testing.T) {
if !reflect.DeepEqual(delAll([]int32{1, 2, 3}, 2), []int32{1, 3}) {
t.Error()
}
}

func Test_DelAll_Multiple(t *testing.T) {
if !reflect.DeepEqual(delAll([]int32{1, 2, 3, 2}, 2), []int32{1, 3}) {
t.Error()
}
}

func Test_DelAll_Missing(t *testing.T) {
if !reflect.DeepEqual(delAll([]int32{1, 2, 3}, 4), []int32{1, 2, 3}) {
t.Error()
}
}

func Test_DelAll_Front(t *testing.T) {
if !reflect.DeepEqual(delAll([]int32{1, 2, 3}, 1), []int32{2, 3}) {
t.Error()
}
}

func Test_DelAll_Back(t *testing.T) {
if !reflect.DeepEqual(delAll([]int32{1, 2, 3}, 3), []int32{1, 2}) {
t.Error()
}
}

0 comments on commit 63eb161

Please sign in to comment.