From 8652c9de687f2e15cc0f576279df0a8f9ed0c1fb Mon Sep 17 00:00:00 2001 From: Divya Pamecha <21123621+Its-Maniaco@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:55:57 +0530 Subject: [PATCH 1/5] unit test for go/sets/set.go Signed-off-by: Divya Pamecha <21123621+Its-Maniaco@users.noreply.github.com> --- go/sets/set_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 go/sets/set_test.go diff --git a/go/sets/set_test.go b/go/sets/set_test.go new file mode 100644 index 00000000000..ae13be52dcd --- /dev/null +++ b/go/sets/set_test.go @@ -0,0 +1,38 @@ +package sets + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSet(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)) + + //tests for Has func + assert.True(t, testSet.Has(3)) + assert.False(t, testSet.Has(-1)) + + //tests for HasAny func + assert.True(t, testSet.HasAny(1, 10, 11, 12)) + assert.False(t, testSet.HasAny(-1, 10, 11, 12)) + + //tests for Delete func + testSet.Delete(1, 2, 3, 4, 5, 6) + assert.Empty(t, testSet) + +} From 08aec55406aaa63eea6fafa529cf155623d4bdd7 Mon Sep 17 00:00:00 2001 From: Maniaco <21123621+Its-Maniaco@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:51:37 +0530 Subject: [PATCH 2/5] Update set_test.go with License Header Signed-off-by: Maniaco <21123621+Its-Maniaco@users.noreply.github.com> --- go/sets/set_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/go/sets/set_test.go b/go/sets/set_test.go index ae13be52dcd..5807604e2f6 100644 --- a/go/sets/set_test.go +++ b/go/sets/set_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2023 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package sets import ( From 1d298d82e7055054b7ce83fdb3c599be81156c9f Mon Sep 17 00:00:00 2001 From: Maniaco <21123621+Its-Maniaco@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:14:25 +0530 Subject: [PATCH 3/5] Update set_test.go Signed-off-by: Maniaco <21123621+Its-Maniaco@users.noreply.github.com> --- go/sets/set_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/sets/set_test.go b/go/sets/set_test.go index 5807604e2f6..3c8559a256b 100644 --- a/go/sets/set_test.go +++ b/go/sets/set_test.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2024 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 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 4/5] 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) } From bf77227626db3473c8586392969f3935bcdecd9a Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 25 Jan 2024 17:42:47 +0530 Subject: [PATCH 5/5] test: add test for List function as well Signed-off-by: Manan Gupta --- go/sets/set_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/go/sets/set_test.go b/go/sets/set_test.go index ce74efd43bd..db453727d6c 100644 --- a/go/sets/set_test.go +++ b/go/sets/set_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestInsert(t *testing.T) { @@ -76,3 +77,9 @@ func TestLen(t *testing.T) { testSet := New[int](1, 2, 3) assert.Equal(t, testSet.Len(), 3) } + +func TestList(t *testing.T) { + testSet := New[string]("a string", "testing", "Capital", "34") + list := List(testSet) + require.EqualValues(t, []string{"34", "Capital", "a string", "testing"}, list) +}