Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed Aug 8, 2021
1 parent ae846cf commit 4531e0d
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 12 deletions.
30 changes: 27 additions & 3 deletions uint16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slicer

import (
"encoding/json"
"github.com/matryer/is"
"testing"
)

Expand All @@ -27,6 +28,28 @@ func TestUint16Add(t *testing.T) {
}
}

func TestUint16Length(t *testing.T) {
is := is.New(t)
s := Uint16()
s.Add(1)
s.Add(2)

is.Equal(s.Length(), 2)
}
func TestUint16Deduplicate(t *testing.T) {
is := is.New(t)
s := Uint16()
s.Add(1)
s.Add(2)
s.Add(2)
s.Add(2)

is.Equal(s.Length(), 4)
is.Equal(s.AsSlice(), []uint16{1, 2, 2, 2})
s.Deduplicate()
is.Equal(s.Length(), 2)
is.Equal(s.AsSlice(), []uint16{1, 2})
}
func TestUint16AddUnique(t *testing.T) {

s := Uint16()
Expand Down Expand Up @@ -148,12 +171,13 @@ func TestOptionalUint16Slice(t *testing.T) {

// TestUint16Sort tests that the slicer can be sorted
func TestUint16Sort(t *testing.T) {
is := is.New(t)
data := []uint16{5, 4, 3, 2, 1}
s := Uint16(data)
s.Sort()
result := s.Join(",")
expected := "1,2,3,4,5"
if expected != result {
t.Errorf("Expected '%s', but got '%s'", expected, result)
}
is.Equal(result, expected)
s.Clear()
is.Equal(s.Join(""), "")
}
32 changes: 29 additions & 3 deletions uint32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slicer

import (
"encoding/json"
"github.com/matryer/is"
"testing"
)

Expand Down Expand Up @@ -67,6 +68,30 @@ func TestUint32AddSlice(t *testing.T) {
}
}

func TestUint32Length(t *testing.T) {
is := is.New(t)
s := Uint32()
s.Add(1)
s.Add(2)

is.Equal(s.Length(), 2)
}

func TestUint32Deduplicate(t *testing.T) {
is := is.New(t)
s := Uint32()
s.Add(1)
s.Add(2)
s.Add(2)
s.Add(2)

is.Equal(s.Length(), 4)
is.Equal(s.AsSlice(), []uint32{1, 2, 2, 2})
s.Deduplicate()
is.Equal(s.Length(), 2)
is.Equal(s.AsSlice(), []uint32{1, 2})

}
func TestUint32AddSlicer(t *testing.T) {

s := Uint32()
Expand Down Expand Up @@ -149,12 +174,13 @@ func TestOptionalUint32Slice(t *testing.T) {

// TestUint32Sort tests that the slicer can be sorted
func TestUint32Sort(t *testing.T) {
is := is.New(t)
data := []uint32{5, 4, 3, 2, 1}
s := Uint32(data)
s.Sort()
result := s.Join(",")
expected := "1,2,3,4,5"
if expected != result {
t.Errorf("Expected '%s', but got '%s'", expected, result)
}
is.Equal(expected, result)
s.Clear()
is.Equal(s.Join(""), "")
}
30 changes: 27 additions & 3 deletions uint64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slicer

import (
"encoding/json"
"github.com/matryer/is"
"testing"
)

Expand Down Expand Up @@ -145,15 +146,38 @@ func TestOptionalUint64Slice(t *testing.T) {
t.Errorf("Expected '%d', but got '%d'", expected, result)
}
}
func TestUint64Deduplicate(t *testing.T) {
is := is.New(t)
s := Uint64()
s.Add(1)
s.Add(2)
s.Add(2)
s.Add(2)

is.Equal(s.Length(), 4)
is.Equal(s.AsSlice(), []uint64{1, 2, 2, 2})
s.Deduplicate()
is.Equal(s.Length(), 2)
is.Equal(s.AsSlice(), []uint64{1, 2})
}
func TestUint64Length(t *testing.T) {
is := is.New(t)
s := Uint64()
s.Add(1)
s.Add(2)

is.Equal(s.Length(), 2)
}

// TestUint64Sort tests that the slicer can be sorted
func TestUint64Sort(t *testing.T) {
is := is.New(t)
data := []uint64{5, 4, 3, 2, 1}
s := Uint64(data)
s.Sort()
result := s.Join(",")
expected := "1,2,3,4,5"
if expected != result {
t.Errorf("Expected '%s', but got '%s'", expected, result)
}
is.Equal(expected, result)
s.Clear()
is.Equal(s.Join(""), "")
}
26 changes: 26 additions & 0 deletions uint8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ func TestUint8Add(t *testing.T) {

}

func TestUint8Length(t *testing.T) {
is := is.New(t)
s := Uint8()
s.Add(1)
s.Add(2)

is.Equal(s.Length(), 2)
}

func TestUint8AddUnique(t *testing.T) {
is := is.New(t)
s := Uint8()
Expand All @@ -37,6 +46,21 @@ func TestUint8AddUnique(t *testing.T) {
is.Equal(s.AsSlice(), []uint8{1, 2})
}

func TestUint8Deduplicate(t *testing.T) {
is := is.New(t)
s := Uint8()
s.Add(1)
s.Add(2)
s.Add(2)
s.Add(2)

is.Equal(s.Length(), 4)
is.Equal(s.AsSlice(), []uint8{1, 2, 2, 2})
s.Deduplicate()
is.Equal(s.Length(), 2)
is.Equal(s.AsSlice(), []uint8{1, 2})
}

func TestUint8AddSlice(t *testing.T) {
is := is.New(t)

Expand Down Expand Up @@ -135,4 +159,6 @@ func TestUint8Sort(t *testing.T) {
result := s.Join(",")
expected := "1,2,3,4,5"
is.Equal(result, expected)
s.Clear()
is.Equal(s.Join(""), "")
}
31 changes: 28 additions & 3 deletions uint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slicer

import (
"encoding/json"
"github.com/matryer/is"
"testing"
)

Expand All @@ -26,6 +27,29 @@ func TestUintAdd(t *testing.T) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestUintDeduplicate(t *testing.T) {
is := is.New(t)
s := Uint()
s.Add(1)
s.Add(2)
s.Add(2)
s.Add(2)

is.Equal(s.Length(), 4)
is.Equal(s.AsSlice(), []uint{1, 2, 2, 2})
s.Deduplicate()
is.Equal(s.Length(), 2)
is.Equal(s.AsSlice(), []uint{1, 2})
}

func TestUintLength(t *testing.T) {
is := is.New(t)
s := Uint()
s.Add(1)
s.Add(2)

is.Equal(s.Length(), 2)
}

func TestUintAddUnique(t *testing.T) {

Expand Down Expand Up @@ -127,12 +151,13 @@ func TestOptionalUintSlice(t *testing.T) {

// TestUintSort tests that the slicer can be sorted
func TestUintSort(t *testing.T) {
is := is.New(t)
data := []uint{5, 4, 3, 2, 1}
s := Uint(data)
s.Sort()
result := s.Join(",")
expected := "1,2,3,4,5"
if expected != result {
t.Errorf("Expected '%s', but got '%s'", expected, result)
}
is.Equal(expected, result)
s.Clear()
is.Equal(s.Join(""), "")
}

0 comments on commit 4531e0d

Please sign in to comment.