From 2a6f023fa61f1aea0106a98775e155ac25e83b71 Mon Sep 17 00:00:00 2001 From: Ilya Smyshlyaev Date: Fri, 30 Sep 2022 23:35:21 +0300 Subject: [PATCH] add forgoten tests --- .DS_Store | Bin 8196 -> 6148 bytes consecutive/cons.go | 35 +++++++++++++++++++++++++++ consecutive/cons_test.go | 51 +++++++++++++++++++++++++++++++++++++++ fizzbuzz/.DS_Store | Bin 6148 -> 0 bytes fizzbuzz/FizzBuzz.go | 35 --------------------------- main.go | 6 +++-- missing/missing.go | 2 +- missing/missing_test.go | 50 ++++++++++++++++++++++++++++++++++++++ solutions/solutions.go | 1 + solutions/task.go | 4 +++ solutions/task_store.go | 1 + twonums/twonums.go | 23 ------------------ 12 files changed, 147 insertions(+), 61 deletions(-) create mode 100644 consecutive/cons.go create mode 100644 consecutive/cons_test.go delete mode 100644 fizzbuzz/.DS_Store delete mode 100644 fizzbuzz/FizzBuzz.go create mode 100644 solutions/solutions.go create mode 100644 solutions/task.go create mode 100644 solutions/task_store.go delete mode 100644 twonums/twonums.go diff --git a/.DS_Store b/.DS_Store index bff0db87707986bbf1e3f9762454f78a3e0a213a..5d427e7d4337571a669136ca4457b9ae596e2547 100644 GIT binary patch delta 279 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGjUEV6q~50$jG%ZU^gQp*JK_6jmh#ttjhEL zg8@(p0|PfhGDAK?9z!uhDv(vmP{NSOP{xotSxrEGGK)}@JUc@!P^1_LGl8noJ#+Gt zlXCKtfI5LzFv?E$7bqn)P)L{) z?yAXoBDxz(Bv=-+b8rYUgB%I8j2lR}g8a0x@H_Klei=uQrx_R-7+63w6U5hGvCZ*3 GbC?0ENIw_= literal 8196 zcmeHMJ#W)M7=Et}jiU%DLlGS=z z@Lwt*?hiJqz`Djnp}cjVktqN$hhbUJM;;(;Y>jn|i9%_LHC6V&v?K*Fa@3NpLUI{!wmj41Dk@W*p{C#kCf5vym!@gesz1t7`VO*(vVjG*eGh2BpZxyXa zPLGeBxE+s%jrQPy_;#1`z&+`=-Ftp#+$wGF^C)inQD-0xe6It_!~1^Z@o|HXB5x>d z9W`MUtU{}Felpp+TDGgTYtynl*{jsbcI|p)IxSe|E?l{B*m@d-5q~K!l$gHf&{_3; z)*hpmks;_-og*IhXRIZhkT;w9(yiAY8_DP1hnvgR3c2@NyngT3KA$^-DBw{Se#G@` z;YAInT?)~9i$}-4VSfJT@?f=b*b(@!T4a;h`Fvm$=#UOD+N3)`;UT^LtJL}y4X}$C zK4N&`ln%YG;9r^xr960J!9(DMG)(R14cM1gv;U2-OG&UK=u(XNkh^{H%drl*4C^%D zRe$u$kvS 1 { + + return 1 + + } + + } + + return 0 + +} + +func extremum(A []int) (int, int) { + min := A[0] + max := A[0] + + for i := 0; i < len(A); i++ { + if min > A[i] { + min = A[i] + } + if max < A[i] { + max = A[i] + } + + } + return min, max +} diff --git a/consecutive/cons_test.go b/consecutive/cons_test.go new file mode 100644 index 0000000..e657868 --- /dev/null +++ b/consecutive/cons_test.go @@ -0,0 +1,51 @@ +package consecutive_test + +import ( + "fmt" + "gotest/consecutive" + "testing" +) + +// Структура тестовых данных, input - входной массив, +// output - ожидаеммый вывод + +type testdata struct { + input []int + output int +} + +// Входной, повторения, ожидания + +var test = []testdata{ + {[]int{1, 2, 4, 3, 6, 5}, 1}, + {[]int{1, 2, 3, 5}, 0}, + {[]int{255, 256, 257, 258}, 1}, +} + +func TestCons(t *testing.T) { + + t.Run( + "insert slices", func(t *testing.T) { + for _, data := range test { + // Передаём массив и повторения в функцию и записываем результат в переменную + v := consecutive.Consecutive(data.input) + // Сравниваем вывод с ожиданием + if v != data.output { + t.Error( + "For: ", data.input, + "Expected: ", data.output, + "Got: ", v, + ) + } else { + fmt.Println( + "For: ", data.input, + "Expected: ", data.output, + "Got: ", v, + ) + + } + } + }, + ) + +} diff --git a/fizzbuzz/.DS_Store b/fizzbuzz/.DS_Store deleted file mode 100644 index c26729870f2effd5f35e09cd2582210a79be33e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!Ab)`3{A91rI$T=oG%dkgK^mk9=zxeNG*uavZr1=&7bRgNffIKy-6v_GI`ld zGCT8NXC@+|{ce3D(uv3%ji@vxgzm|%vj{#1s*TahPTuic%j?8I$LQkR7jh?WHt(PF zAMZEg%W5;O5Yc`768J8##t|#sLaz_RUdp2^VI1L7H zW>e-1$JEI{GLQ^>Gr;|!pb=|ebF{4k%1Qv>3~m$HtRGF%w&;oA*qsqWZ+a8 z(An@b^jKY-t$)_Zv$mi;qfr>wXh2}^T>|jJedNkIy}!^#Tn%iF9EE;M2j)e<2uYO; H`~w4@?P*VC diff --git a/fizzbuzz/FizzBuzz.go b/fizzbuzz/FizzBuzz.go deleted file mode 100644 index b1da893..0000000 --- a/fizzbuzz/FizzBuzz.go +++ /dev/null @@ -1,35 +0,0 @@ -package fizzbuzz - -import "fmt" - -func main() { - // for i := 1; i < 101; i++ { - // if i%15 == 0 { - // fmt.Print("FizzBuzz\n") - // } else if i%3 == 0 { - // fmt.Print("Fizz\n") - // } else if i%5 == 0 { - // fmt.Print("Buzz\n") - // } else { - // fmt.Println(i) - // } - // } - - switchFB() -} - -func switchFB() { - for i := 1; i < 101; i++ { - switch { - case i%15 == 0: - fmt.Println("FizzBuzz") - case i%3 == 0: - fmt.Println("Fizz") - case i%5 == 0: - fmt.Println("Buzz") - default: - fmt.Println(i) - } - } - -} diff --git a/main.go b/main.go index 2712b7b..7415f00 100644 --- a/main.go +++ b/main.go @@ -2,11 +2,13 @@ package main import ( "fmt" - "gotest/missing" + "gotest/consecutive" ) func main() { - fmt.Print(missing.FindNumber([]int{1, 3, 5, 2, 6, 7, -9, 8, 4})) + array := []int{1, 2, 4, 3, 6, 5} + + fmt.Println(consecutive.Consecutive(array)) } diff --git a/missing/missing.go b/missing/missing.go index 31611b3..34b568e 100644 --- a/missing/missing.go +++ b/missing/missing.go @@ -9,7 +9,7 @@ func FindNumber(A []int) int { for i := 0; i < len(A); i++ { if A[i] < 0 || A[i] > 100000 { - fmt.Print("array has negative element or longer than expected") + fmt.Print("array has negative element or longer than expected \n") return A[i] } else { elements_sum = elements_sum + A[i] diff --git a/missing/missing_test.go b/missing/missing_test.go index 4142715..8c85807 100644 --- a/missing/missing_test.go +++ b/missing/missing_test.go @@ -1 +1,51 @@ package missing_test + +import ( + "fmt" + "gotest/missing" + "testing" +) + +// Структура тестовых данных, input - входной массив, +// output - ожидаеммый вывод + +type testdata struct { + input []int + output int +} + +// Входной, повторения, ожидания + +var test = []testdata{ + {[]int{1, 2, 4, 3, 6}, 5}, + {[]int{1, 2, 3, 5}, 4}, + {[]int{1, 2, 4, 3, -6}, -6}, +} + +func TestMissing(t *testing.T) { + + t.Run( + "insert slices", func(t *testing.T) { + for _, data := range test { + // Передаём массив и повторения в функцию и записываем результат в переменную + v := missing.FindNumber(data.input) + // Сравниваем вывод с ожиданием + if v != data.output { + t.Error( + "For: ", data.input, + "Expected: ", data.output, + "Got: ", v, + ) + } else { + fmt.Println( + "For: ", data.input, + "Expected: ", data.output, + "Got: ", v, + ) + + } + } + }, + ) + +} diff --git a/solutions/solutions.go b/solutions/solutions.go new file mode 100644 index 0000000..e1e0aea --- /dev/null +++ b/solutions/solutions.go @@ -0,0 +1 @@ +package solutions diff --git a/solutions/task.go b/solutions/task.go new file mode 100644 index 0000000..1d2ba72 --- /dev/null +++ b/solutions/task.go @@ -0,0 +1,4 @@ +package solutions + +type Task struct { +} diff --git a/solutions/task_store.go b/solutions/task_store.go new file mode 100644 index 0000000..e1e0aea --- /dev/null +++ b/solutions/task_store.go @@ -0,0 +1 @@ +package solutions diff --git a/twonums/twonums.go b/twonums/twonums.go deleted file mode 100644 index 7401fa0..0000000 --- a/twonums/twonums.go +++ /dev/null @@ -1,23 +0,0 @@ -package twonums - -import "fmt" - -func main() { - var test_nums []int - test_nums = append(test_nums, 2, 3, 5, 6, 9, 1) - fmt.Print(TwoSum(test_nums, 10)) -} - -func TwoSum(nums []int, target int) []int { - - var result []int - - for i := 0; i < len(nums); i++ { - for j := i + 1; j < len(nums); j++ { - if nums[i]+nums[j] == target { - result = append(result, i, j) - } - } - } - return result -}