From 952c5fb237264e259f1c3dce478d65819cefeb70 Mon Sep 17 00:00:00 2001 From: Divya Pamecha <21123621+Its-Maniaco@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:38:14 +0530 Subject: [PATCH] broke the test in pieces Signed-off-by: Divya Pamecha <21123621+Its-Maniaco@users.noreply.github.com> --- go/sets/set_test.go | 60 +++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/go/sets/set_test.go b/go/sets/set_test.go index 3c8559a256b..ce74efd43bd 100644 --- a/go/sets/set_test.go +++ b/go/sets/set_test.go @@ -22,33 +22,57 @@ import ( "github.com/stretchr/testify/assert" ) -func TestSet(t *testing.T) { +func TestInsert(t *testing.T) { testSet := New[int](1, 2, 3) - - assert.Equal(t, testSet.Len(), 3) - testSet.Insert(4, 5, 6) compareSet := New[int](1, 2, 3, 4, 5, 6) assert.Equal(t, testSet, compareSet) +} - assert.True(t, testSet.Equal(compareSet)) - compareSet.Insert(-1, -2) - assert.False(t, testSet.Equal(compareSet)) - - //tests for Difference func - diffSet := New[int](-1, -2) - assert.Equal(t, diffSet, compareSet.Difference(testSet)) +func TestDelete(t *testing.T) { + testSet := New[int](1, 2, 3, 4, 5, 6) + testSet.Delete(1, 5) + compareSet := New[int](2, 3, 4, 6) + assert.Equal(t, testSet, compareSet) + testSet.Delete(2, 3, 4, 6) + assert.Empty(t, testSet) +} - //tests for Has func +func TestHas(t *testing.T) { + testSet := New[int](1, 2, 3) assert.True(t, testSet.Has(3)) assert.False(t, testSet.Has(-1)) +} + +func TestHasAny(t *testing.T) { + testSet := New[int](1, 2, 3) + assert.True(t, testSet.HasAny(1, 10, 11)) + assert.False(t, testSet.HasAny(-1, 10, 11)) +} - //tests for HasAny func - assert.True(t, testSet.HasAny(1, 10, 11, 12)) - assert.False(t, testSet.HasAny(-1, 10, 11, 12)) +func TestDifference(t *testing.T) { + testSet := New[int](1, 2, 3) + compareSet := New[int](-1, -2, 1, 2, 3) + diffSet := New[int](-1, -2) + assert.Equal(t, diffSet, compareSet.Difference(testSet)) +} - //tests for Delete func - testSet.Delete(1, 2, 3, 4, 5, 6) - assert.Empty(t, testSet) +func TestIntersection(t *testing.T) { + setA := New[int](1, 2, 3) + setB := New[int](1, 2, 8, 9, 10) + expectedSet := New[int](1, 2) + assert.Equal(t, expectedSet, setA.Intersection(setB)) +} +func TestEqual(t *testing.T) { + testSet := New[int](1, 2, 3, 4, 5, 6) + compareSet := New[int](1, 2, 3, 4, 5, 6) + assert.True(t, testSet.Equal(compareSet)) + compareSet.Insert(-1, -2) + assert.False(t, testSet.Equal(compareSet)) +} + +func TestLen(t *testing.T) { + testSet := New[int](1, 2, 3) + assert.Equal(t, testSet.Len(), 3) }