From d1e8e8acb802252dffd8c1c7677863a7bb21c813 Mon Sep 17 00:00:00 2001 From: Xavier Petit <32063953+xpetit@users.noreply.github.com> Date: Sun, 26 Apr 2020 18:38:18 +0200 Subject: [PATCH] Fix test files --- tests/go/test_chunk.go | 3 ++- tests/go/test_fib.go | 3 ++- tests/go/test_foldint.go | 40 ++++++++++++++---------------- tests/go/test_game23.go | 3 ++- tests/go/test_interestingnumber.go | 3 ++- tests/go/test_isanagram.go | 3 ++- tests/go/test_lcm.go | 3 ++- tests/go/test_nauuo.go | 3 ++- tests/go/test_printmemory.go | 7 ++++-- tests/go/test_priorprime.go | 3 ++- tests/go/test_reduceint.go | 36 +++++++++++++-------------- tests/go/test_revivethreenums.go | 3 ++- tests/go/test_sweetproblem.go | 40 ++++++++++++++---------------- tests/go/test_twosum.go | 3 ++- tests/go/test_volumechanger.go | 3 ++- 15 files changed, 82 insertions(+), 74 deletions(-) diff --git a/tests/go/test_chunk.go b/tests/go/test_chunk.go index 309d6474e..b00880761 100644 --- a/tests/go/test_chunk.go +++ b/tests/go/test_chunk.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func randomSize() []int { @@ -36,6 +37,6 @@ func main() { ch: 0, }) for _, args := range table { - z01.Challenge("Chunk", Chunk, correct.Chunk, args.slice, args.ch) + z01.Challenge("Chunk", student.Chunk, correct.Chunk, args.slice, args.ch) } } diff --git a/tests/go/test_fib.go b/tests/go/test_fib.go index 60c3f0ec8..5a4c038ce 100644 --- a/tests/go/test_fib.go +++ b/tests/go/test_fib.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -15,6 +16,6 @@ func main() { } table = append(table, z01.MultRandIntBetween(-100, 150)...) for _, arg := range table { - z01.Challenge("Fib", Fib, correct.Fib, arg) + z01.Challenge("Fib", student.Fib, correct.Fib, arg) } } diff --git a/tests/go/test_foldint.go b/tests/go/test_foldint.go index 3979646e6..a04c1c4ab 100644 --- a/tests/go/test_foldint.go +++ b/tests/go/test_foldint.go @@ -4,13 +4,24 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { - f := []func(int, int) int{Add, Sub, Mul} + f := []func(int, int) int{ + func(accumulator, currentValue int) int { + return accumulator + currentValue + }, + func(accumulator, currentValue int) int { + return accumulator - currentValue + }, + func(accumulator, currentValue int) int { + return currentValue * accumulator + }, + } type node struct { - arr []int + a []int functions []func(int, int) int n int } @@ -19,41 +30,28 @@ func main() { for i := 0; i < 8; i++ { argInt = append(argInt, z01.MultRandIntBetween(0, 50)...) - val := node{ - arr: argInt, + table = append(table, node{ + a: argInt, functions: f, n: z01.RandIntBetween(0, 60), - } - table = append(table, val) + }) } table = append(table, node{ - arr: []int{1, 2, 3}, + a: []int{1, 2, 3}, functions: f, n: 93, }) table = append(table, node{ - arr: []int{0}, + a: []int{0}, functions: f, n: 93, }) for _, v := range table { for _, f := range v.functions { - z01.Challenge("FoldInt", FoldInt, correct.FoldInt, f, v.arr, v.n) + z01.Challenge("FoldInt", student.FoldInt, correct.FoldInt, f, v.a, v.n) } } } - -func Add(accumulator, currentValue int) int { - return accumulator + currentValue -} - -func Sub(accumulator, currentValue int) int { - return accumulator - currentValue -} - -func Mul(accumulator, currentValue int) int { - return currentValue * accumulator -} diff --git a/tests/go/test_game23.go b/tests/go/test_game23.go index 7846289f3..366565d72 100644 --- a/tests/go/test_game23.go +++ b/tests/go/test_game23.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func nd(a, b int) int { @@ -55,6 +56,6 @@ func main() { table = append(table, value) } for _, arg := range table { - z01.Challenge("Game23", Game23, correct.Game23, arg.init, arg.fin) + z01.Challenge("Game23", student.Game23, correct.Game23, arg.init, arg.fin) } } diff --git a/tests/go/test_interestingnumber.go b/tests/go/test_interestingnumber.go index e290d7fea..472852938 100644 --- a/tests/go/test_interestingnumber.go +++ b/tests/go/test_interestingnumber.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -16,6 +17,6 @@ func main() { table = append(table, z01.MultRandIntBetween(1, 1500)...) for _, arg := range table { - z01.Challenge("InterestingNumber", InterestingNumber, correct.InterestingNumber, arg) + z01.Challenge("InterestingNumber", student.InterestingNumber, correct.InterestingNumber, arg) } } diff --git a/tests/go/test_isanagram.go b/tests/go/test_isanagram.go index 385a113ad..0449e8628 100644 --- a/tests/go/test_isanagram.go +++ b/tests/go/test_isanagram.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -33,6 +34,6 @@ func main() { } for _, arg := range table { - z01.Challenge("IsAnagram", IsAnagram, correct.IsAnagram, arg[0], arg[1]) + z01.Challenge("IsAnagram", student.IsAnagram, correct.IsAnagram, arg[0], arg[1]) } } diff --git a/tests/go/test_lcm.go b/tests/go/test_lcm.go index 9c1614af1..1fb3e964a 100644 --- a/tests/go/test_lcm.go +++ b/tests/go/test_lcm.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -23,6 +24,6 @@ func main() { } for _, arg := range table { - z01.Challenge("Lcm", Lcm, correct.Lcm, arg[0], arg[1]) + z01.Challenge("Lcm", student.Lcm, correct.Lcm, arg[0], arg[1]) } } diff --git a/tests/go/test_nauuo.go b/tests/go/test_nauuo.go index 1eeec78c9..4c3e56303 100644 --- a/tests/go/test_nauuo.go +++ b/tests/go/test_nauuo.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -27,6 +28,6 @@ func main() { }) } for _, arg := range table { - z01.Challenge("Nauuo", Nauuo, correct.Nauuo, arg.plus, arg.minus, arg.rand) + z01.Challenge("Nauuo", student.Nauuo, correct.Nauuo, arg.plus, arg.minus, arg.rand) } } diff --git a/tests/go/test_printmemory.go b/tests/go/test_printmemory.go index 3f452f732..2cb04225f 100644 --- a/tests/go/test_printmemory.go +++ b/tests/go/test_printmemory.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -13,8 +14,10 @@ func main() { for i := 0; i < 10; i++ { table[i] = z01.RandIntBetween(0, 1000) } - z01.Challenge("PrintMemory", PrintMemory, correct.PrintMemory, table) + z01.Challenge("PrintMemory", student.PrintMemory, correct.PrintMemory, table) } table2 := [10]int{104, 101, 108, 108, 111, 16, 21, 42} - z01.Challenge("PrintMemory", PrintMemory, correct.PrintMemory, table2) + z01.Challenge("PrintMemory", student.PrintMemory, correct.PrintMemory, table2) } + +// TODO: this can be simplified a lot diff --git a/tests/go/test_priorprime.go b/tests/go/test_priorprime.go index deb8060ba..f9ed788e5 100644 --- a/tests/go/test_priorprime.go +++ b/tests/go/test_priorprime.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -17,6 +18,6 @@ func main() { } table = append(table, z01.MultRandIntBetween(0, 1000)) for _, arg := range table { - z01.Challenge("PriorPrime", PriorPrime, correct.PriorPrime, arg) + z01.Challenge("PriorPrime", student.PriorPrime, correct.PriorPrime, arg) } } diff --git a/tests/go/test_reduceint.go b/tests/go/test_reduceint.go index 247d6c0f0..3d8ad968a 100644 --- a/tests/go/test_reduceint.go +++ b/tests/go/test_reduceint.go @@ -4,42 +4,40 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { - f := []func(int, int) int{Add, Sub, Mul} + f := []func(int, int) int{ + func(accumulator, currentValue int) int { + return accumulator + currentValue + }, + func(accumulator, currentValue int) int { + return accumulator - currentValue + }, + func(accumulator, currentValue int) int { + return currentValue * accumulator + }, + } argInt := []int{} type node struct { - arr []int + a []int functions []func(int, int) int } table := []node{} for i := 0; i < 4; i++ { argInt = z01.MultRandIntBetween(0, 50) - val := node{ - arr: argInt, + table = append(table, node{ + a: argInt, functions: f, - } - table = append(table, val) + }) } for _, v := range table { for _, f := range v.functions { - z01.Challenge("ReduceInt", ReduceInt, correct.ReduceInt, f, v.arr) + z01.Challenge("ReduceInt", student.ReduceInt, correct.ReduceInt, f, v.a) } } } - -func Add(accumulator, currentValue int) int { - return accumulator + currentValue -} - -func Sub(accumulator, currentValue int) int { - return accumulator - currentValue -} - -func Mul(accumulator, currentValue int) int { - return currentValue * accumulator -} diff --git a/tests/go/test_revivethreenums.go b/tests/go/test_revivethreenums.go index 2d4d82cc5..098f6711e 100644 --- a/tests/go/test_revivethreenums.go +++ b/tests/go/test_revivethreenums.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -25,6 +26,6 @@ func main() { }) } for _, arg := range table { - z01.Challenge("Revivethreenums", ReviveThreeNums, correct.ReviveThreeNums, arg[0], arg[1], arg[2], arg[3]) + z01.Challenge("Revivethreenums", student.ReviveThreeNums, correct.ReviveThreeNums, arg[0], arg[1], arg[2], arg[3]) } } diff --git a/tests/go/test_sweetproblem.go b/tests/go/test_sweetproblem.go index f3389e223..70f3d1e15 100644 --- a/tests/go/test_sweetproblem.go +++ b/tests/go/test_sweetproblem.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -13,33 +14,30 @@ func main() { blue int } - table := []node{} - - table = append(table, - node{50, 43, 20}, - node{10, 0, 0}, - node{0, 10, 0}, - node{0, 0, 10}, - node{10, 1, 0}, - node{0, 10, 1}, - node{1, 0, 10}, - node{10, 2, 0}, - node{2, 10, 0}, - node{0, 2, 10}, - node{13, 13, 0}, - node{10, 9, 0}, - node{5, 9, 2}, - ) + table := []node{ + {50, 43, 20}, + {10, 0, 0}, + {0, 10, 0}, + {0, 0, 10}, + {10, 1, 0}, + {0, 10, 1}, + {1, 0, 10}, + {10, 2, 0}, + {2, 10, 0}, + {0, 2, 10}, + {13, 13, 0}, + {10, 9, 0}, + {5, 9, 2}, + } for i := 0; i < 15; i++ { - value := node{ + table = append(table, node{ red: z01.RandIntBetween(0, 30), green: z01.RandIntBetween(0, 30), blue: z01.RandIntBetween(0, 30), - } - table = append(table, value) + }) } for _, arg := range table { - z01.Challenge("SweetProblem", Sweetproblem, correct.Sweetproblem, arg.red, arg.green, arg.blue) + z01.Challenge("SweetProblem", student.Sweetproblem, correct.Sweetproblem, arg.red, arg.green, arg.blue) } } diff --git a/tests/go/test_twosum.go b/tests/go/test_twosum.go index 124c0af0d..344d21627 100644 --- a/tests/go/test_twosum.go +++ b/tests/go/test_twosum.go @@ -6,12 +6,13 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { for i := 0; i < 20; i++ { token := rand.Perm(20) target := rand.Intn(30) - z01.Challenge("TwoSum", TwoSum, correct.TwoSum, token, target) + z01.Challenge("TwoSum", student.TwoSum, correct.TwoSum, token, target) } } diff --git a/tests/go/test_volumechanger.go b/tests/go/test_volumechanger.go index 8688b932d..45b8dc6b9 100644 --- a/tests/go/test_volumechanger.go +++ b/tests/go/test_volumechanger.go @@ -4,6 +4,7 @@ import ( "github.com/01-edu/z01" correct "./correct" + student "./student" ) func main() { @@ -20,6 +21,6 @@ func main() { }) } for _, arg := range table { - z01.Challenge("Volumechanger", Volumechanger, correct.Volumechanger, arg[0], arg[1]) + z01.Challenge("Volumechanger", student.Volumechanger, correct.Volumechanger, arg[0], arg[1]) } }