From 59b9bf9b7aa7458dc8c99a8426b319dcb19af1a9 Mon Sep 17 00:00:00 2001 From: Xavier Petit <32063953+xpetit@users.noreply.github.com> Date: Sun, 5 Apr 2020 20:08:56 +0200 Subject: [PATCH] mb:go x$ pwd /Users/x/x/01/public/tests/go mb:go x$ goimports -w . mb:go x$ --- tests/go/activebits_test.go | 3 +- tests/go/any_test.go | 3 +- tests/go/appendrange_test.go | 3 +- tests/go/btreesearchitem_test.go | 3 +- tests/go/btreetransplant_test.go | 3 +- tests/go/enigma_test.go | 3 +- tests/go/join_test.go | 3 +- tests/go/max_test.go | 3 +- tests/go/pilot_test.go | 3 +- tests/go/printalphabet_test.go | 3 +- tests/go/printdigits_test.go | 3 +- tests/go/printprogramname_test.go | 3 +- tests/go/printreversealphabet_test.go | 3 +- tests/go/raid2_test.go | 3 +- tests/go/revparams_test.go | 3 +- tests/go/solutions/anagram/anagram_test.go | 6 +- tests/go/solutions/brainfuck/main.go | 3 +- tests/go/solutions/comparetrees.go | 3 +- tests/go/solutions/findprevprimeprog/main.go | 2 +- tests/go/solutions/inverttree.go | 24 +- .../solutions/inverttree/inverttree_test.go | 242 +++++++++--------- tests/go/solutions/inverttree/main.go | 25 +- tests/go/solutions/itoabaseprog/main.go | 6 +- tests/go/solutions/lcm.go | 20 +- tests/go/solutions/nenokku/main.go | 2 +- tests/go/solutions/nenokku/nenokku_test.go | 10 +- tests/go/solutions/onlyz/onlyz_test.go | 3 +- tests/go/solutions/piglatin/main.go | 1 + tests/go/solutions/pilot/pilot.go | 3 +- .../printalphabetprog_test.go | 3 +- tests/go/solutions/printchessboard.go | 3 +- tests/go/solutions/printchessboard/main.go | 3 +- .../printchessboard/printchessboard_test.go | 3 +- .../printdigitsprog/printdigitsprog_test.go | 3 +- tests/go/solutions/priorprime.go | 2 +- .../solutions/priorprime/priorprime_test.go | 8 +- tests/go/solutions/repeatalpha/main.go | 3 +- tests/go/solutions/robottoorigin/main.go | 3 +- .../robottoorigin/robottoorigin_test.go | 3 +- tests/go/solutions/sametree.go | 34 +-- tests/go/solutions/sametree/main.go | 38 +-- tests/go/solutions/sametree/sametree_test.go | 193 +++++++------- tests/go/solutions/searchreplace/main.go | 3 +- tests/go/solutions/strrevprog/main.go | 3 +- tests/go/solutions/swapbits/swapbits_test.go | 3 +- tests/go/solutions/testConvertBase/main.go | 3 +- tests/go/solutions/twosum.go | 2 +- tests/go/solutions/twosum/main.go | 17 +- tests/go/solutions/twosum/twosum_test.go | 14 +- tests/go/solutions/uniqueoccurences/main.go | 3 +- .../uniqueoccurences/uniqueoccurences_test.go | 3 +- tests/go/solutions/ztail/main.go | 3 +- tests/go/sortparams_test.go | 3 +- tests/go/swapbits_test.go | 3 +- tests/go/ztail_test.go | 3 +- 55 files changed, 397 insertions(+), 360 deletions(-) diff --git a/tests/go/activebits_test.go b/tests/go/activebits_test.go index a487fee6..9a8ccca2 100644 --- a/tests/go/activebits_test.go +++ b/tests/go/activebits_test.go @@ -1,10 +1,11 @@ package student_test import ( + "testing" + solutions "./solutions" student "./student" "github.com/01-edu/z01" - "testing" ) func TestActiveBits(t *testing.T) { diff --git a/tests/go/any_test.go b/tests/go/any_test.go index a5a0b6dd..0af272f1 100644 --- a/tests/go/any_test.go +++ b/tests/go/any_test.go @@ -1,10 +1,11 @@ package student_test import ( + "testing" + solutions "./solutions" student "./student" "github.com/01-edu/z01" - "testing" ) func TestAny(t *testing.T) { diff --git a/tests/go/appendrange_test.go b/tests/go/appendrange_test.go index a793b5b6..d051e72c 100644 --- a/tests/go/appendrange_test.go +++ b/tests/go/appendrange_test.go @@ -1,9 +1,10 @@ package student_test import ( - "github.com/01-edu/z01" "testing" + "github.com/01-edu/z01" + solutions "./solutions" student "./student" ) diff --git a/tests/go/btreesearchitem_test.go b/tests/go/btreesearchitem_test.go index ff7a0ff8..3f9836c6 100644 --- a/tests/go/btreesearchitem_test.go +++ b/tests/go/btreesearchitem_test.go @@ -5,9 +5,10 @@ import ( "github.com/01-edu/z01" + "fmt" + solutions "./solutions" student "./student" - "fmt" ) func errorMessage_search(t *testing.T, fn interface{}, root, a *solutions.TreeNode, b *student.TreeNode, diff --git a/tests/go/btreetransplant_test.go b/tests/go/btreetransplant_test.go index 42cef51f..7f2b8671 100644 --- a/tests/go/btreetransplant_test.go +++ b/tests/go/btreetransplant_test.go @@ -5,9 +5,10 @@ import ( "github.com/01-edu/z01" + "fmt" + solutions "./solutions" student "./student" - "fmt" ) func parentListTransp(root *student.TreeNode) string { diff --git a/tests/go/enigma_test.go b/tests/go/enigma_test.go index 72f4d198..8c192b53 100644 --- a/tests/go/enigma_test.go +++ b/tests/go/enigma_test.go @@ -1,10 +1,11 @@ package student_test import ( + "testing" + solutions "./solutions" student "./student" "github.com/01-edu/z01" - "testing" ) func TestEnigma(t *testing.T) { diff --git a/tests/go/join_test.go b/tests/go/join_test.go index 4c6ea47b..daaa0953 100644 --- a/tests/go/join_test.go +++ b/tests/go/join_test.go @@ -1,10 +1,11 @@ package student_test import ( + "testing" + solutions "./solutions" student "./student" "github.com/01-edu/z01" - "testing" ) func TestJoin(t *testing.T) { diff --git a/tests/go/max_test.go b/tests/go/max_test.go index 61070a03..ebaa3adc 100644 --- a/tests/go/max_test.go +++ b/tests/go/max_test.go @@ -1,10 +1,11 @@ package student_test import ( + "testing" + solutions "./solutions" student "./student" "github.com/01-edu/z01" - "testing" ) func TestMax(t *testing.T) { diff --git a/tests/go/pilot_test.go b/tests/go/pilot_test.go index 9afd696f..4d1302f1 100644 --- a/tests/go/pilot_test.go +++ b/tests/go/pilot_test.go @@ -1,8 +1,9 @@ package student_test import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestPilot(t *testing.T) { diff --git a/tests/go/printalphabet_test.go b/tests/go/printalphabet_test.go index 6e5dab69..18231c59 100644 --- a/tests/go/printalphabet_test.go +++ b/tests/go/printalphabet_test.go @@ -1,8 +1,9 @@ package student_test import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestPrintAlphabet(t *testing.T) { diff --git a/tests/go/printdigits_test.go b/tests/go/printdigits_test.go index dcca6acd..dc3b6d53 100644 --- a/tests/go/printdigits_test.go +++ b/tests/go/printdigits_test.go @@ -1,8 +1,9 @@ package student_test import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestPrintDigits(t *testing.T) { diff --git a/tests/go/printprogramname_test.go b/tests/go/printprogramname_test.go index 7e10bd5c..92ba1494 100644 --- a/tests/go/printprogramname_test.go +++ b/tests/go/printprogramname_test.go @@ -1,9 +1,10 @@ package student_test import ( - "github.com/01-edu/z01" "strings" "testing" + + "github.com/01-edu/z01" ) func TestPrintProgramName(t *testing.T) { diff --git a/tests/go/printreversealphabet_test.go b/tests/go/printreversealphabet_test.go index 1c085ddc..885fc002 100644 --- a/tests/go/printreversealphabet_test.go +++ b/tests/go/printreversealphabet_test.go @@ -1,8 +1,9 @@ package student_test import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestPrintReverseAlphabet(t *testing.T) { diff --git a/tests/go/raid2_test.go b/tests/go/raid2_test.go index 575639bf..cbfba9f1 100644 --- a/tests/go/raid2_test.go +++ b/tests/go/raid2_test.go @@ -1,8 +1,9 @@ package student_test import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestRaid2(t *testing.T) { diff --git a/tests/go/revparams_test.go b/tests/go/revparams_test.go index 5c7a3b08..191394d0 100644 --- a/tests/go/revparams_test.go +++ b/tests/go/revparams_test.go @@ -1,8 +1,9 @@ package student_test import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestRevParams(t *testing.T) { diff --git a/tests/go/solutions/anagram/anagram_test.go b/tests/go/solutions/anagram/anagram_test.go index ec3c8e1b..0439b17f 100644 --- a/tests/go/solutions/anagram/anagram_test.go +++ b/tests/go/solutions/anagram/anagram_test.go @@ -36,7 +36,7 @@ func TestIsAnagram(t *testing.T) { ) for i := 0; i < 15; i++ { - value := node { + value := node{ s: z01.RandStr(z01.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "), t: z01.RandStr(z01.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "), } @@ -44,7 +44,7 @@ func TestIsAnagram(t *testing.T) { table = append(table, value) } - for _, arg := range(table) { + for _, arg := range table { z01.Challenge(t, IsAnagram, solutions.IsAnagram, arg.s, arg.t) } -} \ No newline at end of file +} diff --git a/tests/go/solutions/brainfuck/main.go b/tests/go/solutions/brainfuck/main.go index 30054e85..f12e8864 100644 --- a/tests/go/solutions/brainfuck/main.go +++ b/tests/go/solutions/brainfuck/main.go @@ -1,8 +1,9 @@ package main import ( - "github.com/01-edu/z01" "os" + + "github.com/01-edu/z01" ) const SIZE = 2048 diff --git a/tests/go/solutions/comparetrees.go b/tests/go/solutions/comparetrees.go index 85a95fa9..94a5605a 100644 --- a/tests/go/solutions/comparetrees.go +++ b/tests/go/solutions/comparetrees.go @@ -3,8 +3,9 @@ package solutions import ( - student "../student" "testing" + + student "../student" ) func CompareTrees(root *solutions.TreeNode, rootS *student.TreeNode, t *testing.T) { diff --git a/tests/go/solutions/findprevprimeprog/main.go b/tests/go/solutions/findprevprimeprog/main.go index 8f734a19..0f73dfe7 100644 --- a/tests/go/solutions/findprevprimeprog/main.go +++ b/tests/go/solutions/findprevprimeprog/main.go @@ -1,6 +1,6 @@ package main -func main(){ +func main() { } diff --git a/tests/go/solutions/inverttree.go b/tests/go/solutions/inverttree.go index b5c16763..5f7673ab 100644 --- a/tests/go/solutions/inverttree.go +++ b/tests/go/solutions/inverttree.go @@ -1,23 +1,23 @@ package solutions type TNode struct { - Val int - Left *TNode - Right *TNode + Val int + Left *TNode + Right *TNode } func Invert(root *TNode) { - if root != nil { - temp := root.Left - root.Left = root.Right - root.Right = temp + if root != nil { + temp := root.Left + root.Left = root.Right + root.Right = temp - Invert(root.Left) - Invert(root.Right) - } + Invert(root.Left) + Invert(root.Right) + } } func InvertTree(root *TNode) *TNode { - Invert(root) - return root + Invert(root) + return root } diff --git a/tests/go/solutions/inverttree/inverttree_test.go b/tests/go/solutions/inverttree/inverttree_test.go index cfef1014..d6317afc 100644 --- a/tests/go/solutions/inverttree/inverttree_test.go +++ b/tests/go/solutions/inverttree/inverttree_test.go @@ -4,9 +4,9 @@ import ( "io" // "os" "fmt" - "math/rand" + "math/rand" + "strconv" "testing" - "strconv" // "github.com/01-edu/z01" solutions "../../solutions" @@ -16,116 +16,116 @@ type stuNode = TNode type solNode = solutions.TNode func solInsert(N *solNode, newVal int) { - if N == nil { - return - } else if newVal <= N.Val { - if N.Left == nil { - N.Left = &solNode{Val: newVal, Left: nil, Right: nil} - } else { - solInsert(N.Left, newVal) - } - } else { - if N.Right == nil { - N.Right = &solNode{Val: newVal, Left: nil, Right: nil} - } else { - solInsert(N.Right, newVal) - } - } + if N == nil { + return + } else if newVal <= N.Val { + if N.Left == nil { + N.Left = &solNode{Val: newVal, Left: nil, Right: nil} + } else { + solInsert(N.Left, newVal) + } + } else { + if N.Right == nil { + N.Right = &solNode{Val: newVal, Left: nil, Right: nil} + } else { + solInsert(N.Right, newVal) + } + } } func stuInsert(N *stuNode, newVal int) { - if N == nil { - return - } else if newVal <= N.Val { - if N.Left == nil { - N.Left = &stuNode{Val: newVal, Left: nil, Right: nil} - } else { - stuInsert(N.Left, newVal) - } - } else { - if N.Right == nil { - N.Right = &stuNode{Val: newVal, Left: nil, Right: nil} - } else { - stuInsert(N.Right, newVal) - } - } + if N == nil { + return + } else if newVal <= N.Val { + if N.Left == nil { + N.Left = &stuNode{Val: newVal, Left: nil, Right: nil} + } else { + stuInsert(N.Left, newVal) + } + } else { + if N.Right == nil { + N.Right = &stuNode{Val: newVal, Left: nil, Right: nil} + } else { + stuInsert(N.Right, newVal) + } + } } func IsIdentical(root1 *solNode, root2 *stuNode) int { - if root1 == nil && root2 == nil { - return 1 - } else if root1 == nil && root2 != nil { - return 0 - } else if root2 == nil && root1 != nil { - return 0 - } else { - if root1.Val == root2.Val && IsIdentical(root1.Left, root2.Left) == 1 && IsIdentical(root1.Right, root2.Right) == 1 { - return 1 - } else { - return 0 - } - } - return 1 + if root1 == nil && root2 == nil { + return 1 + } else if root1 == nil && root2 != nil { + return 0 + } else if root2 == nil && root1 != nil { + return 0 + } else { + if root1.Val == root2.Val && IsIdentical(root1.Left, root2.Left) == 1 && IsIdentical(root1.Right, root2.Right) == 1 { + return 1 + } else { + return 0 + } + } + return 1 } func stuPrint(w io.Writer, node *stuNode, ns int, ch rune) { - if node == nil { - return - } - - for i := 0; i < ns; i++ { - fmt.Fprint(w, " ") - } - fmt.Fprintf(w, "%c:%v\n", ch, node.Val) - stuPrint(w, node.Left, ns+2, 'L') - stuPrint(w, node.Right, ns+2, 'R') + if node == nil { + return + } + + for i := 0; i < ns; i++ { + fmt.Fprint(w, " ") + } + fmt.Fprintf(w, "%c:%v\n", ch, node.Val) + stuPrint(w, node.Left, ns+2, 'L') + stuPrint(w, node.Right, ns+2, 'R') } func solPrint(w io.Writer, node *solNode, ns int, ch rune) { - if node == nil { - return - } - - for i := 0; i < ns; i++ { - fmt.Fprint(w, " ") - } - fmt.Fprintf(w, "%c:%v\n", ch, node.Val) - solPrint(w, node.Left, ns+2, 'L') - solPrint(w, node.Right, ns+2, 'R') + if node == nil { + return + } + + for i := 0; i < ns; i++ { + fmt.Fprint(w, " ") + } + fmt.Fprintf(w, "%c:%v\n", ch, node.Val) + solPrint(w, node.Left, ns+2, 'L') + solPrint(w, node.Right, ns+2, 'R') } func returnStuTree(root *stuNode) string { - if (root == nil) { - return "" - } - ans := strconv.Itoa(root.Val) - if (root.Left == nil && root.Right == nil) { - return ans - } - if (root.Left != nil) { - ans += " " + returnStuTree(root.Left) - } - if (root.Right != nil) { - ans += " " + returnStuTree(root.Right) - } - return ans + if root == nil { + return "" + } + ans := strconv.Itoa(root.Val) + if root.Left == nil && root.Right == nil { + return ans + } + if root.Left != nil { + ans += " " + returnStuTree(root.Left) + } + if root.Right != nil { + ans += " " + returnStuTree(root.Right) + } + return ans } -func returnSolTree(root *solNode) string{ - if (root == nil) { - return "" - } - ans := strconv.Itoa(root.Val) - if (root.Left == nil && root.Right == nil) { - return ans - } - if (root.Left != nil) { - ans += " " + returnSolTree(root.Left) - } - if (root.Right != nil) { - ans += " " + returnSolTree(root.Right) - } - return ans +func returnSolTree(root *solNode) string { + if root == nil { + return "" + } + ans := strconv.Itoa(root.Val) + if root.Left == nil && root.Right == nil { + return ans + } + if root.Left != nil { + ans += " " + returnSolTree(root.Left) + } + if root.Right != nil { + ans += " " + returnSolTree(root.Right) + } + return ans } func TestInvertTree(t *testing.T) { @@ -136,32 +136,32 @@ func TestInvertTree(t *testing.T) { TestTree := &stuNode{Val: root, Left: nil, Right: nil} for i := 0; i < 15; i++ { tree = &solNode{Val: root, Left: nil, Right: nil} - temp := tree + temp := tree val1, val2, val3, val4 = rand.Intn(30), rand.Intn(30), rand.Intn(30), rand.Intn(30) - solInsert(tree, val1) - solInsert(tree, val2) - solInsert(tree, val3) - solInsert(tree, val4) - // solPrint(os.Stdout, tree, 0, 'M') - solutions.InvertTree(tree) - // solPrint(os.Stdout, tree, 0, 'M') - - TestTree = &stuNode{Val: root, Left: nil, Right: nil} - tmp := TestTree - stuInsert(TestTree, val1) - stuInsert(TestTree, val2) - stuInsert(TestTree, val3) - stuInsert(TestTree, val4) - // stuPrint(os.Stdout, TestTree, 0, 'M') - InvertTree(TestTree) - // stuPrint(os.Stdout, TestTree, 0, 'M') - - ret := IsIdentical(tree, TestTree) - if ret != 1 { - tree1 := returnSolTree(temp) - tree2 := returnStuTree(tmp) - t.Errorf("\n\"%v\" instead of \"%v\"\n\n", tree1, tree2) - // t.Errorf("\nError\n\n") - } + solInsert(tree, val1) + solInsert(tree, val2) + solInsert(tree, val3) + solInsert(tree, val4) + // solPrint(os.Stdout, tree, 0, 'M') + solutions.InvertTree(tree) + // solPrint(os.Stdout, tree, 0, 'M') + + TestTree = &stuNode{Val: root, Left: nil, Right: nil} + tmp := TestTree + stuInsert(TestTree, val1) + stuInsert(TestTree, val2) + stuInsert(TestTree, val3) + stuInsert(TestTree, val4) + // stuPrint(os.Stdout, TestTree, 0, 'M') + InvertTree(TestTree) + // stuPrint(os.Stdout, TestTree, 0, 'M') + + ret := IsIdentical(tree, TestTree) + if ret != 1 { + tree1 := returnSolTree(temp) + tree2 := returnStuTree(tmp) + t.Errorf("\n\"%v\" instead of \"%v\"\n\n", tree1, tree2) + // t.Errorf("\nError\n\n") + } } } diff --git a/tests/go/solutions/inverttree/main.go b/tests/go/solutions/inverttree/main.go index ae1231e0..424ce69d 100644 --- a/tests/go/solutions/inverttree/main.go +++ b/tests/go/solutions/inverttree/main.go @@ -1,28 +1,27 @@ package main type TNode struct { - Val int - Left *TNode - Right *TNode + Val int + Left *TNode + Right *TNode } func Invert(root *TNode) { - if root != nil { - temp := root.Left - root.Left = root.Right - root.Right = temp + if root != nil { + temp := root.Left + root.Left = root.Right + root.Right = temp - Invert(root.Left) - Invert(root.Right) - } + Invert(root.Left) + Invert(root.Right) + } } func InvertTree(root *TNode) *TNode { - Invert(root) - return root + Invert(root) + return root } func main() { } - diff --git a/tests/go/solutions/itoabaseprog/main.go b/tests/go/solutions/itoabaseprog/main.go index 38143920..8a352d39 100644 --- a/tests/go/solutions/itoabaseprog/main.go +++ b/tests/go/solutions/itoabaseprog/main.go @@ -2,11 +2,13 @@ package main import ( "fmt" - "github.com/01-edu/z01" "strconv" - student "../../student" + "github.com/01-edu/z01" + "strings" + + student "../../student" ) func ItoaBase(value, base int) string { diff --git a/tests/go/solutions/lcm.go b/tests/go/solutions/lcm.go index 3b9e1747..bad0b0a1 100644 --- a/tests/go/solutions/lcm.go +++ b/tests/go/solutions/lcm.go @@ -1,19 +1,19 @@ package solutions -//This solution is the comparing file of the staff -// Because the solution is a function, +// This solution is the comparing file of the staff +// Because the solution is a function, // -//1) here the package is solutions -//2) it does not need an empty func main(){} -//3) its location is 1 level below the folder of the nauuo_test.go file +// 1) here the package is solutions +// 2) it does not need an empty func main(){} +// 3) its location is 1 level below the folder of the nauuo_test.go file func gcd(first, second int) int { - if (second == 0) { - return (first) + if second == 0 { + return first } - return (gcd(second, first % second)) + return gcd(second, first%second) } func Lcm(first, second int) int { - return (first / gcd(second, first % second) * second) -} \ No newline at end of file + return first / gcd(second, first%second) * second +} diff --git a/tests/go/solutions/nenokku/main.go b/tests/go/solutions/nenokku/main.go index cd578e48..6d02e68c 100644 --- a/tests/go/solutions/nenokku/main.go +++ b/tests/go/solutions/nenokku/main.go @@ -1,8 +1,8 @@ package main import ( - "os" "fmt" + "os" "strings" ) diff --git a/tests/go/solutions/nenokku/nenokku_test.go b/tests/go/solutions/nenokku/nenokku_test.go index e9f1e7ac..973c50ee 100644 --- a/tests/go/solutions/nenokku/nenokku_test.go +++ b/tests/go/solutions/nenokku/nenokku_test.go @@ -2,6 +2,7 @@ package main import ( "testing" + "github.com/01-edu/z01" ) @@ -27,13 +28,13 @@ func TestNenokku(t *testing.T) { }, ) - sets := [][]string { + sets := [][]string{ []string{"An", "array", "variable", "denotes", "the", "entire", "array"}, []string{"This", "means", "that", "when", "you", "assign", "or", "pass"}, []string{"To", "avoid", "the", "copy", "you", "could", "pass"}, []string{"struct", "but", "with", "indexed", "rather", "than", "named", "fields"}, } - ops := []string { + ops := []string{ "?", "x", "A", } @@ -44,13 +45,12 @@ func TestNenokku(t *testing.T) { for j := 0; j < nOps; j++ { k := z01.RandIntBetween(0, len(ops)-1) s := z01.RandIntBetween(0, len(sets[index])-1) - result = append(result, ops[k] + " " + sets[index][s]) + result = append(result, ops[k]+" "+sets[index][s]) } table = append(table, node{result}) } - - for _, arg := range table { + for _, arg := range table { z01.ChallengeMainExam(t, arg.operations...) } } diff --git a/tests/go/solutions/onlyz/onlyz_test.go b/tests/go/solutions/onlyz/onlyz_test.go index e8817ccb..ae6b26c0 100644 --- a/tests/go/solutions/onlyz/onlyz_test.go +++ b/tests/go/solutions/onlyz/onlyz_test.go @@ -1,8 +1,9 @@ package main import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestOnlyz(t *testing.T) { diff --git a/tests/go/solutions/piglatin/main.go b/tests/go/solutions/piglatin/main.go index bebe8449..8d44b494 100644 --- a/tests/go/solutions/piglatin/main.go +++ b/tests/go/solutions/piglatin/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "github.com/01-edu/z01" ) diff --git a/tests/go/solutions/pilot/pilot.go b/tests/go/solutions/pilot/pilot.go index b2b856ab..2fd76e10 100644 --- a/tests/go/solutions/pilot/pilot.go +++ b/tests/go/solutions/pilot/pilot.go @@ -1,8 +1,9 @@ package main import ( - student ".." "fmt" + + student ".." ) func main() { diff --git a/tests/go/solutions/printalphabetprog/printalphabetprog_test.go b/tests/go/solutions/printalphabetprog/printalphabetprog_test.go index 8a06582b..32b138e1 100644 --- a/tests/go/solutions/printalphabetprog/printalphabetprog_test.go +++ b/tests/go/solutions/printalphabetprog/printalphabetprog_test.go @@ -1,8 +1,9 @@ package main import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestPrintAlphabetProg(t *testing.T) { diff --git a/tests/go/solutions/printchessboard.go b/tests/go/solutions/printchessboard.go index f51b7177..2bd97df8 100644 --- a/tests/go/solutions/printchessboard.go +++ b/tests/go/solutions/printchessboard.go @@ -1,9 +1,10 @@ package solutions import ( - "github.com/01-edu/z01" "os" "strconv" + + "github.com/01-edu/z01" ) func printLineCh(str string) { diff --git a/tests/go/solutions/printchessboard/main.go b/tests/go/solutions/printchessboard/main.go index 6e92e5e9..0a683c33 100644 --- a/tests/go/solutions/printchessboard/main.go +++ b/tests/go/solutions/printchessboard/main.go @@ -1,9 +1,10 @@ package main import ( - "github.com/01-edu/z01" "os" "strconv" + + "github.com/01-edu/z01" ) func printLine(str string) { diff --git a/tests/go/solutions/printchessboard/printchessboard_test.go b/tests/go/solutions/printchessboard/printchessboard_test.go index 7bed560e..bbf56585 100644 --- a/tests/go/solutions/printchessboard/printchessboard_test.go +++ b/tests/go/solutions/printchessboard/printchessboard_test.go @@ -1,9 +1,10 @@ package main import ( - "github.com/01-edu/z01" "strconv" "testing" + + "github.com/01-edu/z01" ) func TestPrintChessBoard(t *testing.T) { diff --git a/tests/go/solutions/printdigitsprog/printdigitsprog_test.go b/tests/go/solutions/printdigitsprog/printdigitsprog_test.go index 30893310..5d97f630 100644 --- a/tests/go/solutions/printdigitsprog/printdigitsprog_test.go +++ b/tests/go/solutions/printdigitsprog/printdigitsprog_test.go @@ -1,8 +1,9 @@ package main import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestPrintDigitsProg(t *testing.T) { diff --git a/tests/go/solutions/priorprime.go b/tests/go/solutions/priorprime.go index 4dc85fe5..13733644 100644 --- a/tests/go/solutions/priorprime.go +++ b/tests/go/solutions/priorprime.go @@ -22,4 +22,4 @@ func Priorprime(x int) int { } } return ans -} \ No newline at end of file +} diff --git a/tests/go/solutions/priorprime/priorprime_test.go b/tests/go/solutions/priorprime/priorprime_test.go index 40361455..2884f51a 100644 --- a/tests/go/solutions/priorprime/priorprime_test.go +++ b/tests/go/solutions/priorprime/priorprime_test.go @@ -15,7 +15,7 @@ func TestPriorprime(t *testing.T) { // (note: a node is not always necessary but in this case it makes the writing of the test easier) type node struct { - first int + first int } // Declaration of an empty array of type node{} @@ -31,8 +31,8 @@ func TestPriorprime(t *testing.T) { node{13}, node{10}, node{0}, - node{1}, - node{2}, + node{1}, + node{2}, ) // If we were to leave the table as it is, a student could just do a program with 4 ifs and get @@ -40,7 +40,7 @@ func TestPriorprime(t *testing.T) { for i := 0; i < 15; i++ { value := node{ - first: z01.RandIntBetween(0, 1000), + first: z01.RandIntBetween(0, 1000), //this z01.RandIntBetween function allows the randomization of //the int for each value in a desired range. //Note that they are many others of those functions for other types of data diff --git a/tests/go/solutions/repeatalpha/main.go b/tests/go/solutions/repeatalpha/main.go index 93a477db..4bb03806 100644 --- a/tests/go/solutions/repeatalpha/main.go +++ b/tests/go/solutions/repeatalpha/main.go @@ -1,8 +1,9 @@ package main import ( - "github.com/01-edu/z01" "os" + + "github.com/01-edu/z01" ) func toLowerCase(a rune) rune { diff --git a/tests/go/solutions/robottoorigin/main.go b/tests/go/solutions/robottoorigin/main.go index 3b83f849..07ee2f4c 100644 --- a/tests/go/solutions/robottoorigin/main.go +++ b/tests/go/solutions/robottoorigin/main.go @@ -1,8 +1,9 @@ package main import ( - "github.com/01-edu/z01" "os" + + "github.com/01-edu/z01" ) func solve(str string) bool { diff --git a/tests/go/solutions/robottoorigin/robottoorigin_test.go b/tests/go/solutions/robottoorigin/robottoorigin_test.go index 0bbae6f4..3ee7b719 100644 --- a/tests/go/solutions/robottoorigin/robottoorigin_test.go +++ b/tests/go/solutions/robottoorigin/robottoorigin_test.go @@ -2,6 +2,7 @@ package main import ( "testing" + "github.com/01-edu/z01" ) @@ -21,4 +22,4 @@ func TestRobotToOrigin(t *testing.T) { for _, arg := range table { z01.ChallengeMainExam(t, arg) } -} \ No newline at end of file +} diff --git a/tests/go/solutions/sametree.go b/tests/go/solutions/sametree.go index 9b3cb742..85da3585 100644 --- a/tests/go/solutions/sametree.go +++ b/tests/go/solutions/sametree.go @@ -1,27 +1,27 @@ package solutions type TreeNodeL struct { - Left *TreeNodeL - Val int - Right *TreeNodeL + Left *TreeNodeL + Val int + Right *TreeNodeL } func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { - if (p == nil && q == nil) { - return true - } - if (checkIfEq(p, q) == true) { - return true - } - return false + if p == nil && q == nil { + return true + } + if checkIfEq(p, q) == true { + return true + } + return false } func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool { - if (t1 == nil && t2 == nil) { - return true - } - if (t1 == nil || t2 == nil) { - return false; - } - return (t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)) + if t1 == nil && t2 == nil { + return true + } + if t1 == nil || t2 == nil { + return false + } + return (t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)) } diff --git a/tests/go/solutions/sametree/main.go b/tests/go/solutions/sametree/main.go index f56483bc..5ba2b18c 100644 --- a/tests/go/solutions/sametree/main.go +++ b/tests/go/solutions/sametree/main.go @@ -1,31 +1,31 @@ package main type TreeNodeL struct { - Left *TreeNodeL - Val int - Right *TreeNodeL + Left *TreeNodeL + Val int + Right *TreeNodeL } func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { - if (p == nil && q == nil) { - return true - } - if (checkIfEq(p, q) == true) { - return true - } - return false + if p == nil && q == nil { + return true + } + if checkIfEq(p, q) == true { + return true + } + return false } func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool { - if (t1 == nil && t2 == nil) { - return true - } - if (t1 == nil || t2 == nil) { - return false; - } - return (t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)) + if t1 == nil && t2 == nil { + return true + } + if t1 == nil || t2 == nil { + return false + } + return (t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)) } func main() { - -} \ No newline at end of file + +} diff --git a/tests/go/solutions/sametree/sametree_test.go b/tests/go/solutions/sametree/sametree_test.go index 4b7daa1d..ffb28c97 100644 --- a/tests/go/solutions/sametree/sametree_test.go +++ b/tests/go/solutions/sametree/sametree_test.go @@ -1,124 +1,123 @@ package main import ( - "testing" - "math/rand" - "strconv" - "github.com/01-edu/z01" - solutions "../../solutions" + "math/rand" + "strconv" + "testing" + + solutions "../../solutions" + "github.com/01-edu/z01" ) type stuTreeNode = TreeNodeL type solTreeNode = solutions.TreeNodeL func insertStu(t *stuTreeNode, v int) *stuTreeNode { - if t == nil { - return &stuTreeNode{Left: nil, Val: v, Right: nil} - } - if v < t.Val { - t.Left = insertStu(t.Left, v) - return t - } - t.Right = insertStu(t.Right, v) - return t + if t == nil { + return &stuTreeNode{Left: nil, Val: v, Right: nil} + } + if v < t.Val { + t.Left = insertStu(t.Left, v) + return t + } + t.Right = insertStu(t.Right, v) + return t } func insertSol(t *solTreeNode, v int) *solTreeNode { - if t == nil { - return &solTreeNode{Left: nil, Val: v, Right: nil} - } - if v < t.Val { - t.Left = insertSol(t.Left, v) - return t - } - t.Right = insertSol(t.Right, v) - return t + if t == nil { + return &solTreeNode{Left: nil, Val: v, Right: nil} + } + if v < t.Val { + t.Left = insertSol(t.Left, v) + return t + } + t.Right = insertSol(t.Right, v) + return t } func New(n, k int) (*solTreeNode, *stuTreeNode, *solTreeNode) { - var cop *solTreeNode - var stu *stuTreeNode - var sol *solTreeNode - for _, v := range rand.Perm(n) { - cop = insertSol(cop, (1+v)*k) - stu = insertStu(stu, (1+v)*k) - sol = insertSol(sol, (1+v)*k) - } - return cop, stu, sol + var cop *solTreeNode + var stu *stuTreeNode + var sol *solTreeNode + for _, v := range rand.Perm(n) { + cop = insertSol(cop, (1+v)*k) + stu = insertStu(stu, (1+v)*k) + sol = insertSol(sol, (1+v)*k) + } + return cop, stu, sol } -func returnSolTree(root *solTreeNode) string{ - if (root == nil) { - return "" - } - ans := strconv.Itoa(root.Val) - if (root.Left == nil && root.Right == nil) { - return ans - } - if (root.Left != nil) { - ans += " " + returnSolTree(root.Left) - } - if (root.Right != nil) { - ans += " " + returnSolTree(root.Right) - } - return ans +func returnSolTree(root *solTreeNode) string { + if root == nil { + return "" + } + ans := strconv.Itoa(root.Val) + if root.Left == nil && root.Right == nil { + return ans + } + if root.Left != nil { + ans += " " + returnSolTree(root.Left) + } + if root.Right != nil { + ans += " " + returnSolTree(root.Right) + } + return ans } func returnStuTree(root *stuTreeNode) string { - if (root == nil) { - return "" - } - ans := strconv.Itoa(root.Val) - if (root.Left == nil && root.Right == nil) { - return ans - } - if (root.Left != nil) { - ans += " " + returnStuTree(root.Left) - } - if (root.Right != nil) { - ans += " " + returnStuTree(root.Right) - } - return ans + if root == nil { + return "" + } + ans := strconv.Itoa(root.Val) + if root.Left == nil && root.Right == nil { + return ans + } + if root.Left != nil { + ans += " " + returnStuTree(root.Left) + } + if root.Right != nil { + ans += " " + returnStuTree(root.Right) + } + return ans } - func compareResults(t *testing.T, stuResult, solResult bool, solTree1, solTree2 *solTreeNode) { - if stuResult != solResult { - tree1 := returnSolTree(solTree1) - tree2 := returnSolTree(solTree2) - t.Errorf("\nIsSameTree(\"%v\", \"%v\") == \"%v\" instead of \"%v\"\n\n", tree1, tree2, stuResult, solResult) - } + if stuResult != solResult { + tree1 := returnSolTree(solTree1) + tree2 := returnSolTree(solTree2) + t.Errorf("\nIsSameTree(\"%v\", \"%v\") == \"%v\" instead of \"%v\"\n\n", tree1, tree2, stuResult, solResult) + } } func TestMerge(t *testing.T) { - type node struct { - n int - k int - } - - table := []node{} - for i := 0; i < 15; i++ { - value := node{z01.RandIntBetween(10, 15), z01.RandIntBetween(1, 10)} - table = append(table, value) - } - - // Check for different trees - for _, arg := range table { - cop1, stuTree1, solTree1 := New(arg.n, arg.k) - cop2, stuTree2, solTree2 := New(arg.n, arg.k) - stuResult := IsSameTree(stuTree1, stuTree2) - solResult := solutions.IsSameTree(solTree1, solTree2) - - compareResults(t, stuResult, solResult, cop1, cop2) - } - - // Check for same trees - for _, arg := range table { - cop1, stuTree1, solTree1 := New(arg.n, arg.k) - stuResult := IsSameTree(stuTree1, stuTree1) - solResult := solutions.IsSameTree(solTree1, solTree1) - - compareResults(t, stuResult, solResult, cop1, cop1) - } + type node struct { + n int + k int + } + + table := []node{} + for i := 0; i < 15; i++ { + value := node{z01.RandIntBetween(10, 15), z01.RandIntBetween(1, 10)} + table = append(table, value) + } + + // Check for different trees + for _, arg := range table { + cop1, stuTree1, solTree1 := New(arg.n, arg.k) + cop2, stuTree2, solTree2 := New(arg.n, arg.k) + stuResult := IsSameTree(stuTree1, stuTree2) + solResult := solutions.IsSameTree(solTree1, solTree2) + + compareResults(t, stuResult, solResult, cop1, cop2) + } + + // Check for same trees + for _, arg := range table { + cop1, stuTree1, solTree1 := New(arg.n, arg.k) + stuResult := IsSameTree(stuTree1, stuTree1) + solResult := solutions.IsSameTree(solTree1, solTree1) + + compareResults(t, stuResult, solResult, cop1, cop1) + } } - diff --git a/tests/go/solutions/searchreplace/main.go b/tests/go/solutions/searchreplace/main.go index add14b57..0c325790 100644 --- a/tests/go/solutions/searchreplace/main.go +++ b/tests/go/solutions/searchreplace/main.go @@ -1,8 +1,9 @@ package main import ( - "github.com/01-edu/z01" "os" + + "github.com/01-edu/z01" ) func main() { diff --git a/tests/go/solutions/strrevprog/main.go b/tests/go/solutions/strrevprog/main.go index 9f29cd8d..f0731d69 100644 --- a/tests/go/solutions/strrevprog/main.go +++ b/tests/go/solutions/strrevprog/main.go @@ -1,9 +1,10 @@ package main import ( - solutions ".." "fmt" "os" + + solutions ".." ) func main() { diff --git a/tests/go/solutions/swapbits/swapbits_test.go b/tests/go/solutions/swapbits/swapbits_test.go index ae7dbb04..819ca6cf 100644 --- a/tests/go/solutions/swapbits/swapbits_test.go +++ b/tests/go/solutions/swapbits/swapbits_test.go @@ -1,10 +1,11 @@ package main import ( - "github.com/01-edu/z01" "reflect" "testing" + "github.com/01-edu/z01" + solutions "../../solutions" ) diff --git a/tests/go/solutions/testConvertBase/main.go b/tests/go/solutions/testConvertBase/main.go index cdfd9753..044a835b 100644 --- a/tests/go/solutions/testConvertBase/main.go +++ b/tests/go/solutions/testConvertBase/main.go @@ -1,8 +1,9 @@ package main import ( - solutions "../../solutions" "fmt" + + solutions "../../solutions" ) func main() { diff --git a/tests/go/solutions/twosum.go b/tests/go/solutions/twosum.go index 3b8c86c8..667cd230 100644 --- a/tests/go/solutions/twosum.go +++ b/tests/go/solutions/twosum.go @@ -3,7 +3,7 @@ package solutions func TwoSum(nums []int, target int) []int { for i := 0; i < len(nums); i++ { for j := i + 1; j < len(nums); j++ { - if (nums[i] + nums[j] == target) { + if nums[i]+nums[j] == target { return []int{i, j} } } diff --git a/tests/go/solutions/twosum/main.go b/tests/go/solutions/twosum/main.go index 19f60b13..524586e7 100644 --- a/tests/go/solutions/twosum/main.go +++ b/tests/go/solutions/twosum/main.go @@ -1,17 +1,16 @@ package main func TwoSum(nums []int, target int) []int { - for i := 0; i < len(nums); i++ { - for j := i + 1; j < len(nums); j++ { - if (nums[i] + nums[j] == target) { - return []int{i, j} - } - } - } - return nil + for i := 0; i < len(nums); i++ { + for j := i + 1; j < len(nums); j++ { + if nums[i]+nums[j] == target { + return []int{i, j} + } + } + } + return nil } func main() { } - diff --git a/tests/go/solutions/twosum/twosum_test.go b/tests/go/solutions/twosum/twosum_test.go index 00835f3c..2439577c 100644 --- a/tests/go/solutions/twosum/twosum_test.go +++ b/tests/go/solutions/twosum/twosum_test.go @@ -1,17 +1,17 @@ package main import ( - "math/rand" + "math/rand" "testing" - "github.com/01-edu/z01" solutions "../../solutions" + "github.com/01-edu/z01" ) func TestTwoSum(t *testing.T) { - for i := 0; i < 20; i++ { - token := rand.Perm(20) - target := rand.Intn(30) - z01.Challenge(t, TwoSum, solutions.TwoSum, token, target) - } + for i := 0; i < 20; i++ { + token := rand.Perm(20) + target := rand.Intn(30) + z01.Challenge(t, TwoSum, solutions.TwoSum, token, target) + } } diff --git a/tests/go/solutions/uniqueoccurences/main.go b/tests/go/solutions/uniqueoccurences/main.go index ee9c33dc..354815ac 100644 --- a/tests/go/solutions/uniqueoccurences/main.go +++ b/tests/go/solutions/uniqueoccurences/main.go @@ -1,8 +1,9 @@ package main import ( - "github.com/01-edu/z01" "os" + + "github.com/01-edu/z01" ) func solve(str string) bool { diff --git a/tests/go/solutions/uniqueoccurences/uniqueoccurences_test.go b/tests/go/solutions/uniqueoccurences/uniqueoccurences_test.go index 82cfe297..db40bf37 100644 --- a/tests/go/solutions/uniqueoccurences/uniqueoccurences_test.go +++ b/tests/go/solutions/uniqueoccurences/uniqueoccurences_test.go @@ -2,6 +2,7 @@ package main import ( "testing" + "github.com/01-edu/z01" ) @@ -23,4 +24,4 @@ func TestUniqueOccurences(t *testing.T) { for _, arg := range table { z01.ChallengeMainExam(t, arg) } -} \ No newline at end of file +} diff --git a/tests/go/solutions/ztail/main.go b/tests/go/solutions/ztail/main.go index e1334667..c9755421 100644 --- a/tests/go/solutions/ztail/main.go +++ b/tests/go/solutions/ztail/main.go @@ -2,9 +2,10 @@ package main import ( "fmt" - "github.com/01-edu/z01" "os" "strconv" + + "github.com/01-edu/z01" ) func numberOfBytes(args []string) (int, []string) { diff --git a/tests/go/sortparams_test.go b/tests/go/sortparams_test.go index cba6348c..bb7e547c 100644 --- a/tests/go/sortparams_test.go +++ b/tests/go/sortparams_test.go @@ -1,8 +1,9 @@ package student_test import ( - "github.com/01-edu/z01" "testing" + + "github.com/01-edu/z01" ) func TestSortParams(t *testing.T) { diff --git a/tests/go/swapbits_test.go b/tests/go/swapbits_test.go index 7d03ed26..821b02c7 100644 --- a/tests/go/swapbits_test.go +++ b/tests/go/swapbits_test.go @@ -1,10 +1,11 @@ package student_test import ( - "github.com/01-edu/z01" "reflect" "testing" + "github.com/01-edu/z01" + solutions "./solutions" student "./student" ) diff --git a/tests/go/ztail_test.go b/tests/go/ztail_test.go index b88804eb..53fba308 100644 --- a/tests/go/ztail_test.go +++ b/tests/go/ztail_test.go @@ -1,9 +1,10 @@ package student_test import ( - "github.com/01-edu/z01" "strings" "testing" + + "github.com/01-edu/z01" ) //Compares only the stdout of each program