From 376ff4255a38d68e2cf1349b99f89e08d55ee3fc Mon Sep 17 00:00:00 2001 From: Ilya Smyshlyaev Date: Mon, 19 Sep 2022 09:36:01 +0300 Subject: [PATCH] some changes in unique and unique test --- main.go | 7 ----- unique/findunique_test.go | 60 +++++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/main.go b/main.go index a190b89..7905807 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,5 @@ package main -import ( - "fmt" - "gotest/unique" -) - func main() { - var nums = []int{2, 2, 4, 5, 4, 6, 6} - fmt.Println(unique.FindUnique(nums)) } diff --git a/unique/findunique_test.go b/unique/findunique_test.go index 8672f21..bdda445 100644 --- a/unique/findunique_test.go +++ b/unique/findunique_test.go @@ -14,32 +14,56 @@ type testdata struct { output int } -var test = []testdata{ +var odd_test = []testdata{ {[]int{9, 3, 9, 3, 9, 7, 9}, 7}, - {[]int{9, 3, 9, 8, 9, 7, 9}, 3}, + {[]int{9, 3, 9, 8, 9, 3, 9}, 8}, } -func TestRotation(t *testing.T) { +var even_test = []testdata{ + {[]int{9, 3, 9, 3, 9, 7}, 0}, +} + +// сравниваем входные данные с выходными данными, и кидаем ошибки или пишем в терминал +func test(d *testdata, t *testing.T) { + + result := unique.FindUnique(d.input) + + if result != d.output { + t.Error( + "test failed", + "for: ", d.input, + "expected: ", d.output, + "got: ", result, + ) + } else { + fmt.Println( + "test passed", + "for: ", d.input, + "got: ", result, + ) + } +} + +func TestUnique(t *testing.T) { t.Run( - "insert nums", func(t *testing.T) { + "inserting odd nums of elements", func(t *testing.T) { - for _, data := range test { + for _, data := range odd_test { - result := unique.FindUnique(data.input) + test(&data, &testing.T{}) + + } + }, + ) + + t.Run( + "inserting even nums of elements", func(t *testing.T) { + + for _, data := range even_test { + + test(&data, &testing.T{}) - if result != data.output { - t.Error( - "For: ", data.input, - "Expected: ", data.output, - "Got: ", result, - ) - } else { - fmt.Println( - "For: ", data.input, - "Got: ", result, - ) - } } }, )