Browse Source

This commit is messy, I merged, moved and modified so many files in a hurry I did not commit all the steps.

So we will have to look at the state of the files before and after this PR if we want to understand things.
I think it will be better afterwards, except for the tests I broke.
content-update
Xavier Petit 4 years ago committed by xpetit
parent
commit
3e90ae6cc7
  1. 12
      tests/go/broken/func/createelem/main.go
  2. 31
      tests/go/broken/func/inverttree/main.go
  3. 26
      tests/go/broken/func/merge/main.go
  4. 5
      tests/go/broken/func/reverse/main.go
  5. 30
      tests/go/broken/func/sametree/main.go
  6. 39
      tests/go/broken/func/sortlist/main.go
  7. 26
      tests/go/func/abort/main.go
  8. 22
      tests/go/func/activebits/main.go
  9. 0
      tests/go/func/addprimesum/correct/main.go
  10. 0
      tests/go/func/addprimesum/main.go
  11. 11
      tests/go/func/advancedsortwordarr/main.go
  12. 15
      tests/go/func/alphacount/main.go
  13. 0
      tests/go/func/alphamirror/correct/main.go
  14. 0
      tests/go/func/alphamirror/main.go
  15. 27
      tests/go/func/any/main.go
  16. 26
      tests/go/func/appendrange/main.go
  17. 9
      tests/go/func/atoi/main.go
  18. 0
      tests/go/func/balancedstring/correct/main.go
  19. 0
      tests/go/func/balancedstring/main.go
  20. 9
      tests/go/func/basicatoi/main.go
  21. 9
      tests/go/func/basicatoi2/main.go
  22. 15
      tests/go/func/basicjoin/main.go
  23. 0
      tests/go/func/boolean/correct/main.go
  24. 0
      tests/go/func/boolean/main.go
  25. 0
      tests/go/func/brackets/correct/main.go
  26. 0
      tests/go/func/brackets/main.go
  27. 0
      tests/go/func/brainfuck/correct/main.go
  28. 0
      tests/go/func/brainfuck/main.go
  29. 39
      tests/go/func/capitalize/main.go
  30. 0
      tests/go/func/cat/correct/main.go
  31. 0
      tests/go/func/cat/correct/quest8.txt
  32. 0
      tests/go/func/cat/correct/quest8T.txt
  33. 0
      tests/go/func/cat/main.go
  34. 23
      tests/go/func/chunk/main.go
  35. 0
      tests/go/func/cleanstr/correct/main.go
  36. 0
      tests/go/func/cleanstr/main.go
  37. 27
      tests/go/func/collatzcountdown/main.go
  38. 0
      tests/go/func/comcheck/correct/main.go
  39. 0
      tests/go/func/comcheck/main.go
  40. 37
      tests/go/func/common/is.go
  41. 17
      tests/go/func/compact/main.go
  42. 10
      tests/go/func/compare/main.go
  43. 12
      tests/go/func/concat/main.go
  44. 10
      tests/go/func/concatparams/main.go
  45. 10
      tests/go/func/correct/abort.go
  46. 10
      tests/go/func/correct/activebits.go
  47. 9
      tests/go/func/correct/advancedsortwordarr.go
  48. 12
      tests/go/func/correct/alphacount.go
  49. 11
      tests/go/func/correct/any.go
  50. 16
      tests/go/func/correct/appendrange.go
  51. 8
      tests/go/func/correct/atoi.go
  52. 8
      tests/go/func/correct/basicatoi.go
  53. 8
      tests/go/func/correct/basicatoi2.go
  54. 8
      tests/go/func/correct/basicjoin.go
  55. 21
      tests/go/func/correct/capitalize.go
  56. 20
      tests/go/func/correct/chunk.go
  57. 20
      tests/go/func/correct/collatzcountdown.go
  58. 14
      tests/go/func/correct/compact.go
  59. 7
      tests/go/func/correct/compare.go
  60. 5
      tests/go/func/correct/concat.go
  61. 7
      tests/go/func/correct/concatparams.go
  62. 12
      tests/go/func/correct/countif.go
  63. 9
      tests/go/func/correct/createelem.go
  64. 6
      tests/go/func/correct/divmod.go
  65. 7
      tests/go/func/correct/doppelganger.go
  66. 23
      tests/go/func/correct/enigma.go
  67. 16
      tests/go/func/correct/fib.go
  68. 14
      tests/go/func/correct/fibonacci.go
  69. 8
      tests/go/func/correct/findnextprime.go
  70. 24
      tests/go/func/correct/findprevprime.go
  71. 6
      tests/go/func/correct/firstrune.go
  72. 11
      tests/go/func/correct/foldint.go
  73. 7
      tests/go/func/correct/foreach.go
  74. 17
      tests/go/func/correct/game23.go
  75. 10
      tests/go/func/correct/halfcontest.go
  76. 7
      tests/go/func/correct/index.go
  77. 19
      tests/go/func/correct/interestingnumber.go
  78. 23
      tests/go/func/correct/inverttree.go
  79. 12
      tests/go/func/correct/isalpha.go
  80. 23
      tests/go/func/correct/isanagram.go
  81. 12
      tests/go/func/correct/islower.go
  82. 11
      tests/go/func/correct/isnegative.go
  83. 12
      tests/go/func/correct/isnumeric.go
  84. 18
      tests/go/func/correct/isprime.go
  85. 12
      tests/go/func/correct/isprintable.go
  86. 20
      tests/go/func/correct/issorted.go
  87. 10
      tests/go/func/correct/isupper.go
  88. 17
      tests/go/func/correct/iterativefactorial.go
  89. 11
      tests/go/func/correct/iterativepower.go
  90. 7
      tests/go/func/correct/itoa.go
  91. 14
      tests/go/func/correct/itoabase.go
  92. 7
      tests/go/func/correct/join.go
  93. 7
      tests/go/func/correct/lastrune.go
  94. 12
      tests/go/func/correct/lcm.go
  95. 15
      tests/go/func/correct/makerange.go
  96. 19
      tests/go/func/correct/map.go
  97. 11
      tests/go/func/correct/max.go
  98. 20
      tests/go/func/correct/merge.go
  99. 28
      tests/go/func/correct/nauuo.go
  100. 9
      tests/go/func/correct/nrune.go
  101. Some files were not shown because too many files changed in this diff diff.show_more

12
tests/go/func/test_createelem.go → tests/go/broken/func/createelem/main.go

@ -1,10 +1,12 @@
package main
import (
"../lib"
"./correct"
"./student"
)
type Node struct {
Data int
}
func CreateElem(n *Node, value int) {
n.Data = value
}
// the structs from the other packages
// struct just for the first exercise

31
tests/go/func/test_inverttree.go → tests/go/broken/func/inverttree/main.go

@ -1,14 +1,27 @@
package main
package correct
import (
"fmt"
"io"
"math/rand"
"strconv"
type TNode struct {
Val int
Left *TNode
Right *TNode
}
func Invert(root *TNode) {
if root != nil {
temp := root.Left
root.Left = root.Right
root.Right = temp
Invert(root.Left)
Invert(root.Right)
}
}
func InvertTree(root *TNode) *TNode {
Invert(root)
return root
}
"../lib"
"./correct"
)
type stuNode = TNode
type solNode = correct.TNode

26
tests/go/func/test_merge.go → tests/go/broken/func/merge/main.go

@ -1,12 +1,24 @@
package main
package correct
import (
"math/rand"
"strconv"
type TreeNodeM struct {
Left *TreeNodeM
Val int
Right *TreeNodeM
}
func MergeTrees(t1 *TreeNodeM, t2 *TreeNodeM) *TreeNodeM {
if t1 == nil {
return t2
}
if t2 == nil {
return t1
}
t1.Val += t2.Val
t1.Left = MergeTrees(t1.Left, t2.Left)
t1.Right = MergeTrees(t1.Right, t2.Right)
return t1
}
"../lib"
"./correct"
)
type stuTreeNode = TreeNodeM
type solTreeNode = correct.TreeNodeM

5
tests/go/func/test_reverse.go → tests/go/broken/func/reverse/main.go

@ -1,9 +1,4 @@
package main
import (
"../lib"
"./correct"
)
type stuNode = NodeAddL
type solNode = correct.NodeAddL

30
tests/go/func/test_sametree.go → tests/go/broken/func/sametree/main.go

@ -1,12 +1,28 @@
package main
package correct
import (
"math/rand"
"strconv"
type TreeNodeL struct {
Left *TreeNodeL
Val int
Right *TreeNodeL
}
func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool {
if p == nil && q == nil {
return true
}
return checkIfEq(p, q)
}
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)
}
"../lib"
"./correct"
)
type stuTreeNode = TreeNodeL
type solTreeNode = correct.TreeNodeL

39
tests/go/func/test_sortlist.go → tests/go/broken/func/sortlist/main.go

@ -1,12 +1,37 @@
package main
package correct
import (
"strconv"
type Nodelist struct {
Data int
Next *Nodelist
}
func SortList(l *Nodelist, cmp func(a, b int) bool) *Nodelist {
head := l
if head == nil {
return nil
}
head.Next = SortList(head.Next, cmp)
if head.Next != nil && cmp(head.Data, head.Next.Data) {
head = moveValue(head, cmp)
}
return head
}
func moveValue(l *Nodelist, cmp func(a, b int) bool) *Nodelist {
p := l
n := l.Next
ret := n
for n != nil && cmp(l.Data, n.Data) {
p = n
n = n.Next
}
p.Next = l
l.Next = n
return ret
}
"../lib"
"./correct"
"./student"
)
func listToString4(n *correct.Nodelist) (res string) {
it := n

26
tests/go/func/abort/main.go

@ -0,0 +1,26 @@
package main
import (
"sort"
"github.com/01-edu/public/tests/go/lib"
"./student"
)
// Receives 5 ints and returns the number in the middle
func abort(a, b, c, d, e int) int {
arg := []int{a, b, c, d, e}
sort.Ints(arg)
return arg[2]
}
func main() {
arg := lib.MultRandInt()
arg = append(arg, lib.RandInt())
for i := 0; i < 15; i++ {
lib.Challenge("Abort", student.Abort, abort, arg[0], arg[1], arg[2], arg[3], arg[4])
arg = lib.MultRandInt()
arg = append(arg, lib.RandInt())
}
}

22
tests/go/func/activebits/main.go

@ -0,0 +1,22 @@
package main
import "./student"
// Function that return the number of active bits in the number passed as the argument
func activeBits(n int) (total int) {
for ; n > 1; n = n / 2 {
total += n % 2
}
total += n
return
}
func main() {
args := []int{lib.RandIntBetween(2, 20)}
args = append(args, lib.MultRandIntBetween(2, 20)...)
args = append(args, lib.MultRandIntBetween(2, 20)...)
for _, v := range args {
lib.Challenge("ActiveBits", student.ActiveBits, activeBits, v)
}
}

0
tests/go/prog/correct/addprimesum/main.go → tests/go/func/addprimesum/correct/main.go

0
tests/go/prog/test_addprimesum.go → tests/go/func/addprimesum/main.go

11
tests/go/func/test_advancedsortwordarr.go → tests/go/func/advancedsortwordarr/main.go

@ -2,13 +2,18 @@ package main
import (
"reflect"
"sort"
"strings"
"../lib"
"./correct"
"./student"
)
func advancedSortWordArr(a []string, f func(a, b string) int) {
sort.Slice(a, func(i, j int) bool {
return f(a[i], a[j]) < 0
})
}
func main() {
table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}}
@ -23,7 +28,7 @@ func main() {
copy(cp_sol, org)
copy(cp_stu, org)
correct.AdvancedSortWordArr(cp_sol, strings.Compare)
advancedSortWordArr(cp_sol, strings.Compare)
student.AdvancedSortWordArr(cp_stu, strings.Compare)
if !reflect.DeepEqual(cp_stu, cp_sol) {

15
tests/go/func/test_alphacount.go → tests/go/func/alphacount/main.go

@ -1,11 +1,20 @@
package main
import (
"../lib"
"./correct"
"unicode"
"./student"
)
func alphaCount(s string) (i int) {
for _, r := range s {
if unicode.IsLetter(r) {
i++
}
}
return i
}
func main() {
table := []string{
" ",
@ -18,6 +27,6 @@ func main() {
}
for _, arg := range table {
lib.Challenge("AlphaCount", student.AlphaCount, correct.AlphaCount, arg)
lib.Challenge("AlphaCount", student.AlphaCount, alphaCount, arg)
}
}

0
tests/go/prog/correct/alphamirror/main.go → tests/go/func/alphamirror/correct/main.go

0
tests/go/prog/test_alphamirror.go → tests/go/func/alphamirror/main.go

27
tests/go/func/test_any.go → tests/go/func/any/main.go

@ -1,13 +1,22 @@
package main
import (
"../lib"
"./correct"
"../common"
"./student"
)
func any(f func(string) bool, arr []string) bool {
for _, el := range arr {
if f(el) {
return true
}
}
return false
}
func main() {
functions := []func(string) bool{correct.IsNumeric, correct.IsLower, correct.IsUpper}
functions := []func(string) bool{common.IsNumeric, common.IsLower, common.IsUpper}
type node struct {
f func(string) bool
@ -25,36 +34,36 @@ func main() {
}
for i := 0; i < 5; i++ {
table = append(table, node{
f: correct.IsNumeric,
f: common.IsNumeric,
a: lib.MultRandDigit(),
})
}
for i := 0; i < 5; i++ {
table = append(table, node{
f: correct.IsLower,
f: common.IsLower,
a: lib.MultRandLower(),
})
}
for i := 0; i < 5; i++ {
table = append(table, node{
f: correct.IsUpper,
f: common.IsUpper,
a: lib.MultRandUpper(),
})
}
table = append(table,
node{
f: correct.IsNumeric,
f: common.IsNumeric,
a: []string{"Hello", "how", "are", "you"},
},
node{
f: correct.IsNumeric,
f: common.IsNumeric,
a: []string{"This", "is", "4", "you"},
},
)
for _, arg := range table {
lib.Challenge("Any", student.Any, correct.Any, arg.f, arg.a)
lib.Challenge("Any", student.Any, any, arg.f, arg.a)
}
}

26
tests/go/func/test_makerange.go → tests/go/func/appendrange/main.go

@ -1,17 +1,27 @@
package main
import (
"../lib"
"./correct"
"./student"
)
import "./student"
func appendRange(min, max int) []int {
size := max - min
answer := []int{}
if size <= 0 {
return nil
}
for i := min; i < max; i++ {
answer = append(answer, i)
}
return answer
}
func main() {
type node struct {
min int
max int
}
table := []node{}
// 15 random pairs of ints for a Valid Range
@ -24,6 +34,7 @@ func main() {
}
table = append(table, val)
}
// 15 random pairs of ints with ||invalid range||
for i := 0; i < 15; i++ {
minVal := lib.RandIntBetween(-10000000, 1000000)
@ -41,7 +52,8 @@ func main() {
node{min: 5, max: 10},
node{min: 10, max: 5},
)
for _, arg := range table {
lib.Challenge("MakeRange", student.MakeRange, correct.MakeRange, arg.min, arg.max)
lib.Challenge("AppendRange", student.AppendRange, appendRange, arg.min, arg.max)
}
}

9
tests/go/func/test_atoi.go → tests/go/func/atoi/main.go

@ -3,11 +3,14 @@ package main
import (
"strconv"
"../lib"
"./correct"
"./student"
)
func atoi(s string) int {
n, _ := strconv.Atoi(s)
return n
}
func main() {
table := make([]string, 30)
for i := range table {
@ -32,6 +35,6 @@ func main() {
"123a45",
)
for _, arg := range table {
lib.Challenge("Atoi", student.Atoi, correct.Atoi, arg)
lib.Challenge("Atoi", student.Atoi, atoi, arg)
}
}

0
tests/go/prog/correct/balancedstring/main.go → tests/go/func/balancedstring/correct/main.go

0
tests/go/prog/test_balancedstring.go → tests/go/func/balancedstring/main.go

9
tests/go/func/test_basicatoi.go → tests/go/func/basicatoi/main.go

@ -3,11 +3,14 @@ package main
import (
"strconv"
"../lib"
"./correct"
"./student"
)
func basicAtoi(s string) int {
n, _ := strconv.Atoi(s)
return n
}
func main() {
table := make([]string, 30)
for i := range table {
@ -22,6 +25,6 @@ func main() {
"000000",
)
for _, arg := range table {
lib.Challenge("BasicAtoi", student.BasicAtoi, correct.BasicAtoi, arg)
lib.Challenge("BasicAtoi", student.BasicAtoi, basicAtoi, arg)
}
}

9
tests/go/func/test_basicatoi2.go → tests/go/func/basicatoi2/main.go

@ -3,11 +3,14 @@ package main
import (
"strconv"
"../lib"
"./correct"
"./student"
)
func basicAtoi2(s string) int {
n, _ := strconv.Atoi(s)
return n
}
func main() {
table := make([]string, 30)
for i := range table {
@ -26,6 +29,6 @@ func main() {
"123.0",
)
for _, arg := range table {
lib.Challenge("BasicAtoi2", student.BasicAtoi2, correct.BasicAtoi2, arg)
lib.Challenge("BasicAtoi2", student.BasicAtoi2, basicAtoi2, arg)
}
}

15
tests/go/func/test_basicjoin.go → tests/go/func/basicjoin/main.go

@ -1,10 +1,13 @@
package main
import (
"../lib"
"./correct"
"./student"
)
import "./student"
func basicJoin(a []string) (b string) {
for _, s := range a {
b += s
}
return b
}
func main() {
table := [][]string{}
@ -17,6 +20,6 @@ func main() {
[]string{"Hello!", " How are you?", "well and yourself?"},
)
for _, arg := range table {
lib.Challenge("BasicJoin", student.BasicJoin, correct.BasicJoin, arg)
lib.Challenge("BasicJoin", student.BasicJoin, basicJoin, arg)
}
}

0
tests/go/prog/correct/boolean/main.go → tests/go/func/boolean/correct/main.go

0
tests/go/prog/test_boolean.go → tests/go/func/boolean/main.go

0
tests/go/prog/correct/brackets/main.go → tests/go/func/brackets/correct/main.go

0
tests/go/prog/test_brackets.go → tests/go/func/brackets/main.go

0
tests/go/prog/correct/brainfuck/main.go → tests/go/func/brainfuck/correct/main.go

0
tests/go/prog/test_brainfuck.go → tests/go/func/brainfuck/main.go

39
tests/go/func/capitalize/main.go

@ -0,0 +1,39 @@
package main
import (
"strings"
"unicode"
"./student"
)
func capitalize(s string) string {
r := []rune(strings.ToLower(s))
if unicode.IsLower(r[0]) {
r[0] = unicode.ToUpper(r[0])
}
for i := 1; i < len(r); i++ {
if !unicode.Is(unicode.ASCII_Hex_Digit, r[i-1]) && unicode.IsLower(r[i]) {
r[i] = unicode.ToUpper(r[i])
}
}
return string(r)
}
func main() {
table := append(
lib.MultRandASCII(),
"Hello! How are you? How+are+things+4you?",
"Hello! How are you?",
"a",
"z",
"!",
"9a",
"9a LALALA!",
)
for _, arg := range table {
lib.Challenge("Capitalize", student.Capitalize, capitalize, arg)
}
}

0
tests/go/prog/correct/cat/main.go → tests/go/func/cat/correct/main.go

0
tests/go/prog/correct/cat/quest8.txt → tests/go/func/cat/correct/quest8.txt

0
tests/go/prog/correct/cat/quest8T.txt → tests/go/func/cat/correct/quest8T.txt

0
tests/go/prog/test_cat.go → tests/go/func/cat/main.go

23
tests/go/func/test_chunk.go → tests/go/func/chunk/main.go

@ -1,11 +1,28 @@
package main
import (
"../lib"
"./correct"
"fmt"
"./student"
)
func chunk(a []int, ch int) {
slice := []int{}
if ch <= 0 {
fmt.Println()
return
}
result := make([][]int, 0, len(a)/ch+1)
for len(a) >= ch {
slice, a = a[:ch], a[ch:]
result = append(result, slice)
}
if len(a) > 0 {
result = append(result, a[:len(a)])
}
fmt.Println(result)
}
func randomSize() []int {
randSlice := []int{}
for i := 0; i <= lib.RandIntBetween(0, 20); i++ {
@ -36,6 +53,6 @@ func main() {
ch: 0,
})
for _, args := range table {
lib.Challenge("Chunk", student.Chunk, correct.Chunk, args.slice, args.ch)
lib.Challenge("Chunk", student.Chunk, chunk, args.slice, args.ch)
}
}

0
tests/go/prog/correct/cleanstr/main.go → tests/go/func/cleanstr/correct/main.go

0
tests/go/prog/test_cleanstr.go → tests/go/func/cleanstr/main.go

27
tests/go/func/test_collatzcountdown.go → tests/go/func/collatzcountdown/main.go

@ -1,10 +1,25 @@
package main
import (
"../lib"
"./correct"
"./student"
)
import "./student"
func collatzCountdown(start int) int {
if start <= 0 {
return -1
}
steps := 0
for start != 1 {
if start%2 == 0 {
start = start / 2
} else {
start = 3*start + 1
}
steps++
}
return steps
}
func main() {
args := []int{lib.RandIntBetween(-6, 20)}
@ -14,6 +29,6 @@ func main() {
}
for _, v := range args {
lib.Challenge("CollatzCountdown", student.CollatzCountdown, correct.CollatzCountdown, v)
lib.Challenge("CollatzCountdown", student.CollatzCountdown, collatzCountdown, v)
}
}

0
tests/go/prog/correct/comcheck/main.go → tests/go/func/comcheck/correct/main.go

0
tests/go/prog/test_comcheck.go → tests/go/func/comcheck/main.go

37
tests/go/func/common/is.go

@ -0,0 +1,37 @@
package common
import (
"math/big"
"unicode"
)
func IsNumeric(s string) bool {
for _, r := range s {
if !unicode.IsDigit(r) {
return false
}
}
return true
}
func IsLower(s string) bool {
for _, r := range s {
if !unicode.IsLower(r) {
return false
}
}
return true
}
func IsUpper(s string) bool {
for _, r := range s {
if !(r >= 'A' && r <= 'Z') {
return false
}
}
return true
}
func IsPrime(i int) bool {
return big.NewInt(int64(i)).ProbablyPrime(0)
}

17
tests/go/func/test_compact.go → tests/go/func/compact/main.go

@ -3,11 +3,22 @@ package main
import (
"reflect"
"../lib"
"./correct"
"./student"
)
func compact(slice *[]string) int {
count := 0
var compacted []string
for _, v := range *slice {
if v != "" {
count++
compacted = append(compacted, v)
}
}
*slice = compacted
return count
}
func main() {
arg := [][]string{{"hello", "", "hi", "", "salut", "", ""}}
@ -33,7 +44,7 @@ func main() {
copy(sli_sol, v)
copy(sli_stu, v)
sol_size := correct.Compact(&sli_sol)
sol_size := compact(&sli_sol)
stu_size := student.Compact(&sli_stu)
if !reflect.DeepEqual(sli_stu, sli_sol) {

10
tests/go/func/test_compare.go → tests/go/func/compare/main.go

@ -1,11 +1,15 @@
package main
import (
"../lib"
"./correct"
"strings"
"./student"
)
func compare(a, b string) int {
return strings.Compare(a, b)
}
func main() {
type node struct {
s string
@ -44,6 +48,6 @@ func main() {
)
for _, arg := range table {
lib.Challenge("Compare", student.Compare, correct.Compare, arg.s, arg.toCompare)
lib.Challenge("Compare", student.Compare, compare, arg.s, arg.toCompare)
}
}

12
tests/go/func/test_concat.go → tests/go/func/concat/main.go

@ -1,10 +1,10 @@
package main
import (
"../lib"
"./correct"
"./student"
)
import "./student"
func concat(a, b string) string {
return a + b
}
func main() {
table := [][]string{}
@ -18,6 +18,6 @@ func main() {
[]string{"Hello!", " How are you?"},
)
for _, arg := range table {
lib.Challenge("Concat", student.Concat, correct.Concat, arg[0], arg[1])
lib.Challenge("Concat", student.Concat, concat, arg[0], arg[1])
}
}

10
tests/go/func/test_concatparams.go → tests/go/func/concatparams/main.go

@ -1,11 +1,15 @@
package main
import (
"../lib"
"./correct"
"strings"
"./student"
)
func concatParams(args []string) string {
return strings.Join(args, "\n")
}
func main() {
table := [][]string{{"Hello", "how", "are", "you?"}}
@ -14,6 +18,6 @@ func main() {
table = append(table, lib.MultRandASCII())
}
for _, arg := range table {
lib.Challenge("ConcatParams", student.ConcatParams, correct.ConcatParams, arg)
lib.Challenge("ConcatParams", student.ConcatParams, concatParams, arg)
}
}

10
tests/go/func/correct/abort.go

@ -1,10 +0,0 @@
package correct
import "sort"
// Receives 5 ints and returns the number in the middle
func Abort(a, b, c, d, e int) int {
arg := []int{a, b, c, d, e}
sort.Ints(arg)
return arg[2]
}

10
tests/go/func/correct/activebits.go

@ -1,10 +0,0 @@
package correct
// Function that return the number of active bits in the number passed as the argument
func ActiveBits(n int) (total int) {
for ; n > 1; n = n / 2 {
total += n % 2
}
total += n
return
}

9
tests/go/func/correct/advancedsortwordarr.go

@ -1,9 +0,0 @@
package correct
import "sort"
func AdvancedSortWordArr(a []string, f func(a, b string) int) {
sort.Slice(a, func(i, j int) bool {
return f(a[i], a[j]) < 0
})
}

12
tests/go/func/correct/alphacount.go

@ -1,12 +0,0 @@
package correct
import "unicode"
func AlphaCount(s string) (i int) {
for _, r := range s {
if unicode.IsLetter(r) {
i++
}
}
return i
}

11
tests/go/func/correct/any.go

@ -1,11 +0,0 @@
package correct
func Any(f func(string) bool, arr []string) bool {
for _, el := range arr {
if f(el) {
return true
}
}
return false
}

16
tests/go/func/correct/appendrange.go

@ -1,16 +0,0 @@
package correct
func AppendRange(min, max int) []int {
size := max - min
answer := []int{}
if size <= 0 {
return nil
}
for i := min; i < max; i++ {
answer = append(answer, i)
}
return answer
}

8
tests/go/func/correct/atoi.go

@ -1,8 +0,0 @@
package correct
import "strconv"
func Atoi(s string) int {
n, _ := strconv.Atoi(s)
return n
}

8
tests/go/func/correct/basicatoi.go

@ -1,8 +0,0 @@
package correct
import "strconv"
func BasicAtoi(s string) int {
n, _ := strconv.Atoi(s)
return n
}

8
tests/go/func/correct/basicatoi2.go

@ -1,8 +0,0 @@
package correct
import "strconv"
func BasicAtoi2(s string) int {
n, _ := strconv.Atoi(s)
return n
}

8
tests/go/func/correct/basicjoin.go

@ -1,8 +0,0 @@
package correct
func BasicJoin(a []string) (b string) {
for _, s := range a {
b += s
}
return b
}

21
tests/go/func/correct/capitalize.go

@ -1,21 +0,0 @@
package correct
import (
"strings"
"unicode"
)
func Capitalize(s string) string {
r := []rune(strings.ToLower(s))
if unicode.IsLower(r[0]) {
r[0] = unicode.ToUpper(r[0])
}
for i := 1; i < len(r); i++ {
if !unicode.Is(unicode.ASCII_Hex_Digit, r[i-1]) && unicode.IsLower(r[i]) {
r[i] = unicode.ToUpper(r[i])
}
}
return string(r)
}

20
tests/go/func/correct/chunk.go

@ -1,20 +0,0 @@
package correct
import "fmt"
func Chunk(a []int, ch int) {
slice := []int{}
if ch <= 0 {
fmt.Println()
return
}
result := make([][]int, 0, len(a)/ch+1)
for len(a) >= ch {
slice, a = a[:ch], a[ch:]
result = append(result, slice)
}
if len(a) > 0 {
result = append(result, a[:len(a)])
}
fmt.Println(result)
}

20
tests/go/func/correct/collatzcountdown.go

@ -1,20 +0,0 @@
package correct
func CollatzCountdown(start int) int {
if start <= 0 {
return -1
}
steps := 0
for start != 1 {
if start%2 == 0 {
start = start / 2
} else {
start = 3*start + 1
}
steps++
}
return steps
}

14
tests/go/func/correct/compact.go

@ -1,14 +0,0 @@
package correct
func Compact(slice *[]string) int {
count := 0
var compacted []string
for _, v := range *slice {
if v != "" {
count++
compacted = append(compacted, v)
}
}
*slice = compacted
return count
}

7
tests/go/func/correct/compare.go

@ -1,7 +0,0 @@
package correct
import "strings"
func Compare(a, b string) int {
return strings.Compare(a, b)
}

5
tests/go/func/correct/concat.go

@ -1,5 +0,0 @@
package correct
func Concat(a, b string) string {
return a + b
}

7
tests/go/func/correct/concatparams.go

@ -1,7 +0,0 @@
package correct
import "strings"
func ConcatParams(args []string) string {
return strings.Join(args, "\n")
}

12
tests/go/func/correct/countif.go

@ -1,12 +0,0 @@
package correct
func CountIf(f func(string) bool, arr []string) int {
counter := 0
for _, el := range arr {
if f(el) {
counter++
}
}
return counter
}

9
tests/go/func/correct/createelem.go

@ -1,9 +0,0 @@
package correct
type Node struct {
Data int
}
func CreateElem(n *Node, value int) {
n.Data = value
}

6
tests/go/func/correct/divmod.go

@ -1,6 +0,0 @@
package correct
func DivMod(a, b int, div, mod *int) {
*div = a / b
*mod = a % b
}

7
tests/go/func/correct/doppelganger.go

@ -1,7 +0,0 @@
package correct
import "strings"
func DoppelGanger(s, substr string) int {
return strings.LastIndex(s, substr)
}

23
tests/go/func/correct/enigma.go

@ -1,23 +0,0 @@
package correct
// this function will put a in c; c in d; d in b and b in a
func Enigma(a ***int, b *int, c *******int, d ****int) {
valc := *******c
*******c = ***a
vald := ****d
****d = valc
valb := *b
*b = vald
***a = valb
}
// Helper function used in the test for checking the function Enigma()
func Decript(a ***int, b *int, c *******int, d ****int) {
vala := ***a
***a = *******c
valb := *b
*b = vala
vald := ****d
****d = valb
*******c = vald
}

16
tests/go/func/correct/fib.go

@ -1,16 +0,0 @@
package correct
func Fib(n int) int {
if n <= 0 {
return 0
}
t1 := 0
t2 := 1
for i := 2; i <= n; i++ {
t1 += t2
tmp := t1
t1 = t2
t2 = tmp
}
return t2
}

14
tests/go/func/correct/fibonacci.go

@ -1,14 +0,0 @@
package correct
func Fibonacci(value int) int {
if value < 0 {
return -1
}
if value == 0 {
return 0
}
if value == 1 {
return 1
}
return Fibonacci(value-1) + Fibonacci(value-2)
}

8
tests/go/func/correct/findnextprime.go

@ -1,8 +0,0 @@
package correct
func FindNextPrime(nb int) int {
if isPrime(nb) {
return nb
}
return FindNextPrime(nb + 1)
}

24
tests/go/func/correct/findprevprime.go

@ -1,24 +0,0 @@
package correct
func isPrime(nb int) bool {
if nb <= 0 || nb == 1 {
return false
}
for i := 2; i <= nb/2; i++ {
if nb%i == 0 {
return false
}
}
return true
}
func FindPrevPrime(nb int) int {
if nb < 2 {
return 0
}
if isPrime(nb) {
return nb
}
return FindPrevPrime(nb - 1)
}

6
tests/go/func/correct/firstrune.go

@ -1,6 +0,0 @@
package correct
func FirstRune(s string) rune {
runes := []rune(s)
return runes[0]
}

11
tests/go/func/correct/foldint.go

@ -1,11 +0,0 @@
package correct
import "fmt"
func FoldInt(f func(int, int) int, a []int, n int) {
result := n
for _, v := range a {
result = f(result, v)
}
fmt.Println(result)
}

7
tests/go/func/correct/foreach.go

@ -1,7 +0,0 @@
package correct
func ForEach(f func(int), a []int) {
for _, el := range a {
f(el)
}
}

17
tests/go/func/correct/game23.go

@ -1,17 +0,0 @@
package correct
func Game23(a, b int) int {
if a > b {
return -1
}
if a == b {
return 0
}
if Game23(a*2, b) != -1 {
return 1 + Game23(a*2, b)
}
if Game23(a*3, b) != -1 {
return 1 + Game23(a*3, b)
}
return -1
}

10
tests/go/func/correct/halfcontest.go

@ -1,10 +0,0 @@
package correct
func HalfContest(h1, m1, h2, m2 int) int {
t1 := h1*60 + m1
t2 := h2*60 + m2
t2 = (t2 + t1) / 2
h2 = t2 / 60
m2 = t2 % 60
return h2*100 + m2
}

7
tests/go/func/correct/index.go

@ -1,7 +0,0 @@
package correct
import "strings"
func Index(s string, substr string) int {
return strings.Index(s, substr)
}

19
tests/go/func/correct/interestingnumber.go

@ -1,19 +0,0 @@
package correct
func isInteresting(n int) bool {
s := 0
for n > 0 {
s += n % 10
n /= 10
}
return s%7 == 0
}
func InterestingNumber(n int) int {
for {
if isInteresting(n) {
return n
}
n++
}
}

23
tests/go/func/correct/inverttree.go

@ -1,23 +0,0 @@
package correct
type TNode struct {
Val int
Left *TNode
Right *TNode
}
func Invert(root *TNode) {
if root != nil {
temp := root.Left
root.Left = root.Right
root.Right = temp
Invert(root.Left)
Invert(root.Right)
}
}
func InvertTree(root *TNode) *TNode {
Invert(root)
return root
}

12
tests/go/func/correct/isalpha.go

@ -1,12 +0,0 @@
package correct
import "unicode"
func IsAlpha(s string) bool {
for _, r := range s {
if !unicode.Is(unicode.Hex_Digit, r) {
return false
}
}
return true
}

23
tests/go/func/correct/isanagram.go

@ -1,23 +0,0 @@
package correct
func IsAnagram(s, t string) bool {
alph := make([]int, 26)
for i := 0; i < len(s); i++ {
if s[i] < 'a' || s[i] > 'z' {
continue
}
alph[s[i]-'a']++
}
for i := 0; i < len(t); i++ {
if t[i] < 'a' || t[i] > 'z' {
continue
}
alph[t[i]-'a']--
}
for i := 0; i < 26; i++ {
if alph[i] != 0 {
return false
}
}
return true
}

12
tests/go/func/correct/islower.go

@ -1,12 +0,0 @@
package correct
import "unicode"
func IsLower(s string) bool {
for _, r := range s {
if !unicode.IsLower(r) {
return false
}
}
return true
}

11
tests/go/func/correct/isnegative.go

@ -1,11 +0,0 @@
package correct
import "fmt"
func IsNegative(n int) {
if n < 0 {
fmt.Println("T")
} else {
fmt.Println("F")
}
}

12
tests/go/func/correct/isnumeric.go

@ -1,12 +0,0 @@
package correct
import "unicode"
func IsNumeric(s string) bool {
for _, r := range s {
if !unicode.IsDigit(r) {
return false
}
}
return true
}

18
tests/go/func/correct/isprime.go

@ -1,18 +0,0 @@
package correct
import "math"
func IsPrime(value int) bool {
if value < 2 {
return false
}
limit := int(math.Floor(math.Sqrt(float64(value))))
i := 2
for i <= limit {
if value%i == 0 {
return false
}
i++
}
return true
}

12
tests/go/func/correct/isprintable.go

@ -1,12 +0,0 @@
package correct
import "unicode"
func IsPrintable(s string) bool {
for _, r := range s {
if !unicode.IsPrint(r) {
return false
}
}
return true
}

20
tests/go/func/correct/issorted.go

@ -1,20 +0,0 @@
package correct
func IsSorted(f func(int, int) int, arr []int) bool {
ascendingOrdered := true
descendingOrdered := true
for i := 1; i < len(arr); i++ {
if !(f(arr[i-1], arr[i]) >= 0) {
ascendingOrdered = false
}
}
for i := 1; i < len(arr); i++ {
if !(f(arr[i-1], arr[i]) <= 0) {
descendingOrdered = false
}
}
return ascendingOrdered || descendingOrdered
}

10
tests/go/func/correct/isupper.go

@ -1,10 +0,0 @@
package correct
func IsUpper(s string) bool {
for _, r := range s {
if !(r >= 'A' && r <= 'Z') {
return false
}
}
return true
}

17
tests/go/func/correct/iterativefactorial.go

@ -1,17 +0,0 @@
package correct
import "math/bits"
func IterativeFactorial(nb int) int {
limit := 12
if bits.UintSize == 64 {
limit = 20
}
if nb < 0 || nb > limit {
return 0
}
if nb == 0 {
return 1
}
return nb * IterativeFactorial(nb-1)
}

11
tests/go/func/correct/iterativepower.go

@ -1,11 +0,0 @@
package correct
import "math"
func IterativePower(nb int, power int) int {
if power < 0 {
return 0
}
result := math.Pow(float64(nb), float64(power))
return int(result)
}

7
tests/go/func/correct/itoa.go

@ -1,7 +0,0 @@
package correct
import "strconv"
func Itoa(i int) string {
return strconv.Itoa(i)
}

14
tests/go/func/correct/itoabase.go

@ -1,14 +0,0 @@
package correct
import (
"strconv"
"strings"
)
func ItoaBase(value, base int) string {
if base < 2 || base > 16 {
return ""
}
return strings.ToUpper(strconv.FormatInt(int64(value), base))
}

7
tests/go/func/correct/join.go

@ -1,7 +0,0 @@
package correct
import "strings"
func Join(elems []string, sep string) string {
return strings.Join(elems, sep)
}

7
tests/go/func/correct/lastrune.go

@ -1,7 +0,0 @@
package correct
func LastRune(s string) rune {
runes := []rune(s)
index := len(runes) - 1
return runes[index]
}

12
tests/go/func/correct/lcm.go

@ -1,12 +0,0 @@
package correct
func gcd(first, second int) int {
if second == 0 {
return first
}
return gcd(second, first%second)
}
func Lcm(first, second int) int {
return first / gcd(second, first%second) * second
}

15
tests/go/func/correct/makerange.go

@ -1,15 +0,0 @@
package correct
func MakeRange(min, max int) []int {
size := max - min
if size <= 0 {
return nil
}
answer := make([]int, size)
for i := range answer {
answer[i] = min
min++
}
return answer
}

19
tests/go/func/correct/map.go

@ -1,19 +0,0 @@
package correct
func IsPositive(value int) bool {
return value > 0
}
func IsNegative0(value int) bool {
return value < 0
}
func Map(f func(int) bool, arr []int) []bool {
arrBool := make([]bool, len(arr))
for i, el := range arr {
arrBool[i] = f(el)
}
return arrBool
}

11
tests/go/func/correct/max.go

@ -1,11 +0,0 @@
package correct
import "sort"
func Max(a []int) int {
if len(a) == 0 {
return 0
}
sort.Ints(a)
return a[len(a)-1]
}

20
tests/go/func/correct/merge.go

@ -1,20 +0,0 @@
package correct
type TreeNodeM struct {
Left *TreeNodeM
Val int
Right *TreeNodeM
}
func MergeTrees(t1 *TreeNodeM, t2 *TreeNodeM) *TreeNodeM {
if t1 == nil {
return t2
}
if t2 == nil {
return t1
}
t1.Val += t2.Val
t1.Left = MergeTrees(t1.Left, t2.Left)
t1.Right = MergeTrees(t1.Right, t2.Right)
return t1
}

28
tests/go/func/correct/nauuo.go

@ -1,28 +0,0 @@
package correct
func Nauuo(plus, minus, rand int) string {
if rand == 0 {
if plus > minus {
return "+"
}
if plus < minus {
return "-"
}
if plus == minus {
return "0"
}
}
if plus > minus+rand {
return "+"
}
if plus+rand < minus {
return "-"
}
if plus+rand >= minus && plus-rand <= minus {
return "?"
}
if minus+rand >= plus && minus-rand <= plus {
return "?"
}
return "?"
}

9
tests/go/func/correct/nrune.go

@ -1,9 +0,0 @@
package correct
func NRune(s string, n int) rune {
if n > len(s) || n < 1 {
return 0
}
runes := []rune(s)
return runes[n-1]
}

Some files were not shown because too many files changed in this diff diff.show_more

Loading…
Cancel
Save