Browse Source

Remove "prog" exercises that already exists in their non-prog version

content-update
Xavier Petit 4 years ago committed by xpetit
parent
commit
2d06c2dd55
  1. 55
      tests/go/solutions/atoibaseprog/main.go
  2. 50
      tests/go/solutions/atoibaseprog/test_atoibaseprog.go
  3. 11
      tests/go/solutions/atoiprog/main.go
  4. 37
      tests/go/solutions/atoiprog/test_atoiprog.go
  5. 47
      tests/go/solutions/capitalizeprog/main.go
  6. 20
      tests/go/solutions/capitalizeprog/test_capitalizeprog.go
  7. 20
      tests/go/solutions/compareprog/main.go
  8. 45
      tests/go/solutions/compareprog/test_compareprog.go
  9. 58
      tests/go/solutions/doopprog/main.go
  10. 43
      tests/go/solutions/doopprog/test_doopprog.go
  11. 9
      tests/go/solutions/firstruneprog/main.go
  12. 20
      tests/go/solutions/firstruneprog/test_firstruneprog.go
  13. 10
      tests/go/solutions/foreachprog/main.go
  14. 51
      tests/go/solutions/foreachprog/test_foreachprog.go
  15. 26
      tests/go/solutions/itoabaseprog/main.go
  16. 20
      tests/go/solutions/itoabaseprog/test_itoabaseprog.go
  17. 10
      tests/go/solutions/itoaprog/main.go
  18. 14
      tests/go/solutions/itoaprog/test_itoaprog.go
  19. 10
      tests/go/solutions/lastruneprog/main.go
  20. 20
      tests/go/solutions/lastruneprog/test_lastruneprog.go
  21. 33
      tests/go/solutions/listremoveifprog/main.go
  22. 105
      tests/go/solutions/listremoveifprog/test_listremoveifprog.go
  23. 24
      tests/go/solutions/listsizeprog/main.go
  24. 60
      tests/go/solutions/listsizeprog/test_listsizeprog.go
  25. 14
      tests/go/solutions/maxprog/main.go
  26. 17
      tests/go/solutions/maxprog/test_maxprog.go
  27. 38
      tests/go/solutions/nruneprog/main.go
  28. 43
      tests/go/solutions/nruneprog/test_nruneprog.go
  29. 10
      tests/go/solutions/printalphabetprog/main.go
  30. 7
      tests/go/solutions/printalphabetprog/test_printalphabetprog.go
  31. 25
      tests/go/solutions/printcombprog/main.go
  32. 7
      tests/go/solutions/printcombprog/test_printcombprog.go
  33. 10
      tests/go/solutions/printdigitsprog/main.go
  34. 7
      tests/go/solutions/printdigitsprog/test_printdigitsprog.go
  35. 10
      tests/go/solutions/printreversealphabetprog/main.go
  36. 7
      tests/go/solutions/printreversealphabetprog/test_printreversealphabetprog.go
  37. 14
      tests/go/solutions/printstrprog/main.go
  38. 11
      tests/go/solutions/printstrprog/test_printstrprog.go
  39. 32
      tests/go/solutions/rot14prog/main.go
  40. 14
      tests/go/solutions/rot14prog/test_rot14prog.go
  41. 10
      tests/go/solutions/sortwordarrprog/main.go
  42. 39
      tests/go/solutions/sortwordarrprog/test_sortwordarrprog.go
  43. 10
      tests/go/solutions/splitprog/main.go
  44. 46
      tests/go/solutions/splitprog/test_splitprog.go
  45. 14
      tests/go/solutions/strlenprog/main.go
  46. 24
      tests/go/solutions/strlenprog/test_strlenprog.go
  47. 14
      tests/go/solutions/strrevprog/main.go
  48. 14
      tests/go/solutions/strrevprog/test_strrevprog.go
  49. 10
      tests/go/solutions/swapprog/main.go
  50. 21
      tests/go/solutions/swapprog/test_swapprog.go

55
tests/go/solutions/atoibaseprog/main.go

@ -1,55 +0,0 @@
package main
import "strings"
var m = map[rune]struct{}{}
func uniqueChar(s string) bool {
for _, r := range s {
if _, ok := m[r]; ok {
return false
}
m[r] = struct{}{}
}
return true
}
func validBase(base string) bool {
return len(base) >= 2 && !strings.ContainsAny(base, "+-") && uniqueChar(base)
}
func power(nbr int, pwr int) int {
if pwr == 0 {
return 1
}
if pwr == 1 {
return nbr
}
return nbr * power(nbr, pwr-1)
}
func AtoiBase(s string, base string) int {
var result int
var i int
sign := 1
length := len(s)
if !validBase(base) {
return 0
}
if s[i] == '-' {
sign = -1
}
if s[i] == '-' || s[i] == '+' {
i++
}
for i < len(s) {
result += strings.Index(base, s[i]) * power(len(base), length-1)
i++
length--
}
return result * sign
}
func main() {
}

50
tests/go/solutions/atoibaseprog/test_atoibaseprog.go

@ -1,50 +0,0 @@
package main
import (
"./base"
"github.com/01-edu/z01"
)
// this is the function that creates the TESTS
func main() {
type node struct {
s string
base string
}
table := []node{}
// 5 random pairs of string numbers with valid bases
for i := 0; i < 5; i++ {
validBaseToInput := base.Valid()
val := node{
s: base.StringFrom(validBaseToInput),
base: validBaseToInput,
}
table = append(table, val)
}
// 5 random pairs of string numbers with invalid bases
for i := 0; i < 5; i++ {
invalidBaseToInput := base.Invalid()
val := node{
s: "thisinputshouldnotmatter",
base: invalidBaseToInput,
}
table = append(table, val)
}
table = append(table,
node{s: "125", base: "0123456789"},
node{s: "1111101", base: "01"},
node{s: "7D", base: "0123456789ABCDEF"},
node{s: "uoi", base: "choumi"},
node{s: "bbbbbab", base: "-ab"},
)
for _, arg := range table {
z01.ChallengeMain("atoibaseprog", arg.s, arg.base)
}
z01.ChallengeMain("atoibaseprog")
z01.ChallengeMain("atoibaseprog", "125", "0123456789", "something")
}
// TODO: fix base exercises

11
tests/go/solutions/atoiprog/main.go

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

37
tests/go/solutions/atoiprog/test_atoiprog.go

@ -1,37 +0,0 @@
package main
import (
"strconv"
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
table := make([]string, 30)
for i := range table {
table[i] = strconv.Itoa(z01.RandInt())
}
table = append(table,
strconv.Itoa(z01.MinInt),
strconv.Itoa(z01.MaxInt),
"",
"-",
"+",
"0",
"+0",
"-Invalid123",
"--123",
"-+123",
"++123",
"123-",
"123+",
"123.",
"123.0",
"123a45",
)
for _, arg := range table {
z01.Challenge("AtoiProg", Atoi, correct.Atoi, arg)
}
}

47
tests/go/solutions/capitalizeprog/main.go

@ -1,47 +0,0 @@
package main
import (
"fmt"
"os"
"strings"
)
func isAlphaNumerical(r rune) bool {
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9')
}
func isLowerRune(r rune) bool {
return r >= 'a' && r <= 'z'
}
func toUpperRune(r rune) rune {
if r >= 'a' && r <= 'z' {
return r - 32
}
return r
}
func capitalize(s string) string {
r := []rune(strings.ToLower(s))
if isLowerRune(r[0]) {
r[0] = toUpperRune(r[0])
}
for i := 1; i < len(r); i++ {
if (!isAlphaNumerical(r[i-1])) && (isLowerRune(r[i])) {
r[i] = toUpperRune(r[i])
}
}
return string(r)
}
func main() {
if len(os.Args) == 2 {
fmt.Println(capitalize(os.Args[1]))
} else if len(os.Args) > 2 {
fmt.Println("Too many arguments")
} else {
fmt.Println()
}
}

20
tests/go/solutions/capitalizeprog/test_capitalizeprog.go

@ -1,20 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
table := append(z01.MultRandASCII(),
"Hello! How are you? How+are+things+4you?",
"Hello! How are you?",
"a",
"z",
"!",
"9a",
"9a LALALA!",
)
for _, arg := range table {
z01.ChallengeMain("capitalizeprog", arg)
}
z01.ChallengeMain("capitalizeprog", "hello", "hihihi")
z01.ChallengeMain("capitalizeprog")
}

20
tests/go/solutions/compareprog/main.go

@ -1,20 +0,0 @@
package main
import (
"fmt"
"os"
"strings"
)
func main() {
if len(os.Args) == 3 {
fmt.Println(compare(os.Args[1], os.Args[2]))
} else {
fmt.Println()
}
}
func compare(s string, toCompare string) int {
result := strings.Compare(s, toCompare)
return result
}

45
tests/go/solutions/compareprog/test_compareprog.go

@ -1,45 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
type node struct {
s string
toCompare string
}
table := []node{}
// the first 7 values are returning 0 for this test
for i := 0; i < 7; i++ {
wordToTest := z01.RandASCII()
val := node{
s: wordToTest,
toCompare: wordToTest,
}
table = append(table, val)
}
// the next 7 values are supposed to return 1 or -1 for this test
for i := 0; i < 7; i++ {
wordToTest := z01.RandASCII()
wrongMatch := z01.RandASCII()
table = append(table, node{
s: wordToTest,
toCompare: wrongMatch,
})
}
// those are the test values from the README examples
table = append(table,
node{s: "Hello!", toCompare: "Hello!"},
node{s: "Salut!", toCompare: "lut!"},
node{s: "Ola!", toCompare: "Ol"},
)
for _, arg := range table {
z01.ChallengeMain("compareprog", arg.s, arg.toCompare)
}
z01.ChallengeMain("compareprog")
z01.ChallengeMain("compareprog", "1 arg", "2args", "3args")
}

58
tests/go/solutions/doopprog/main.go

@ -1,58 +0,0 @@
package main
import (
"fmt"
"os"
"strconv"
)
func main() {
if len(os.Args) == 4 {
var result int
firstArg, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Println(0)
return
}
operator := os.Args[2]
secondArg, err1 := strconv.Atoi(os.Args[3])
if err1 != nil {
fmt.Println(0)
return
}
if secondArg == 0 && operator == "/" {
fmt.Println("No division by 0")
return
} else if secondArg == 0 && operator == "%" {
fmt.Println("No modulo by 0")
return
} else if operator == "+" {
result = firstArg + secondArg
if !((result > firstArg) == (secondArg > 0)) {
fmt.Println(0)
return
}
} else if operator == "-" {
result = firstArg - secondArg
if !((result < firstArg) == (secondArg > 0)) {
fmt.Println(0)
return
}
} else if operator == "/" {
result = firstArg / secondArg
} else if operator == "*" {
result = firstArg * secondArg
if firstArg != 0 && (result/firstArg != secondArg) {
fmt.Println(0)
return
}
} else if operator == "%" {
result = firstArg % secondArg
}
fmt.Println(result)
}
}

43
tests/go/solutions/doopprog/test_doopprog.go

@ -1,43 +0,0 @@
package main
import (
"strings"
"strconv"
"github.com/01-edu/z01"
)
func main() {
operatorsTable := []string{"+", "-", "*", "/", "%"}
table := []string{}
for i := 0; i < 4; i++ {
firstArg := strconv.Itoa(z01.RandIntBetween(-1000, 1000))
secondArg := strconv.Itoa(z01.RandIntBetween(0, 1000))
for _, operator := range operatorsTable {
table = append(table, firstArg+" "+operator+" "+secondArg)
}
}
table = append(table, "1 + 1")
table = append(table, "hello + 1")
table = append(table, "1 p 1")
table = append(table, "1 # 1")
table = append(table, "1 / 0")
table = append(table, "1 % 0")
table = append(table, "1 * 1")
table = append(table, "1argument")
table = append(table, "2 arguments")
table = append(table, "4 arguments so invalid")
table = append(table, "9223372036854775807 + 1")
table = append(table, "9223372036854775809 - 3")
table = append(table, "9223372036854775807 * 3")
for _, s := range table {
z01.ChallengeMain("doopprog", strings.Fields(s)...)
}
}

9
tests/go/solutions/firstruneprog/main.go

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

20
tests/go/solutions/firstruneprog/test_firstruneprog.go

@ -1,20 +0,0 @@
package main
import (
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
table := append(
z01.MultRandASCII(),
"Hello!",
"Salut!",
"Ola!",
"♥01",
)
for _, arg := range table {
z01.Challenge("FirstRuneProg", FirstRune, correct.FirstRune, arg)
}
}

10
tests/go/solutions/foreachprog/main.go

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

51
tests/go/solutions/foreachprog/test_foreachprog.go

@ -1,51 +0,0 @@
package main
import (
"fmt"
"github.com/01-edu/z01"
correct "./correct"
)
func add0(i int) {
fmt.Println(i)
}
func add1(i int) {
fmt.Println(i + 1)
}
func add2(i int) {
fmt.Println(i + 2)
}
func add3(i int) {
fmt.Println(i + 3)
}
func main() {
functions := []func(int){add0, add1, add2, add3}
type node struct {
f func(int)
a []int
}
table := []node{}
// 15 random slice of random ints with a random function from selection
for i := 0; i < 15; i++ {
function := functions[z01.RandIntBetween(0, len(functions)-1)]
table = append(table, node{
f: function,
a: z01.MultRandIntBetween(-1000000, 1000000),
})
}
table = append(table, node{
f: add0,
a: []int{1, 2, 3, 4, 5, 6},
})
for _, arg := range table {
z01.Challenge("ForEachProg", ForEach, correct.ForEach, arg.f, arg.a)
}
}

26
tests/go/solutions/itoabaseprog/main.go

@ -1,26 +0,0 @@
package main
import (
"fmt"
"strconv"
"strings"
"github.com/01-edu/z01"
student "../../student"
)
func ItoaBase(value, base int) string {
if base < 2 || base > 16 {
return ""
}
return strings.ToUpper(strconv.FormatInt(int64(value), base))
}
func main() {
value := z01.RandIntBetween(-1000000, 1000000)
base := z01.RandIntBetween(2, 16)
fmt.Println(student.ItoaBase(141895, 11))
fmt.Println(ItoaBase(value, base))
}

20
tests/go/solutions/itoabaseprog/test_itoabaseprog.go

@ -1,20 +0,0 @@
package main
import (
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
for i := 0; i < 30; i++ {
value := z01.RandIntBetween(-1000000, 1000000)
base := z01.RandIntBetween(2, 16)
z01.Challenge("ItoaBaseProg", ItoaBase, correct.ItoaBase, value, base)
}
for i := 0; i < 5; i++ {
base := z01.RandIntBetween(2, 16)
z01.Challenge("ItoaBaseProg", ItoaBase, correct.ItoaBase, z01.MaxInt, base)
z01.Challenge("ItoaBaseProg", ItoaBase, correct.ItoaBase, z01.MinInt, base)
}
}

10
tests/go/solutions/itoaprog/main.go

@ -1,10 +0,0 @@
package main
import "strconv"
func Itoa(v int) string {
return strconv.Itoa(v)
}
func main() {
}

14
tests/go/solutions/itoaprog/test_itoaprog.go

@ -1,14 +0,0 @@
package main
import (
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
for i := 0; i < 50; i++ {
arg := z01.RandIntBetween(-2000000000, 2000000000)
z01.Challenge("ItoaProg", Itoa, correct.Itoa, arg)
}
}

10
tests/go/solutions/lastruneprog/main.go

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

20
tests/go/solutions/lastruneprog/test_lastruneprog.go

@ -1,20 +0,0 @@
package main
import (
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
table := z01.MultRandASCII()
table = append(table,
"Hello!",
"Salut!",
"Ola!",
z01.RandStr(z01.RandIntBetween(1, 15), z01.RandAlnum()),
)
for _, arg := range table {
z01.Challenge("LastRuneProg", LastRune, correct.LastRune, arg)
}
}

33
tests/go/solutions/listremoveifprog/main.go

@ -1,33 +0,0 @@
package main
type NodeL struct {
Data interface{}
Next *NodeL
}
type List struct {
Head *NodeL
Tail *NodeL
}
// removes all elements that are equal to the data_ref
func ListRemoveIf(l *List, data_ref interface{}) {
temp := l.Head
prev := l.Head
for temp != nil && temp.Data == data_ref {
l.Head = temp.Next
temp = l.Head
}
for temp != nil {
if temp.Data != data_ref {
prev = temp
}
prev.Next = temp.Next
temp = prev.Next
}
}
func main() {
}

105
tests/go/solutions/listremoveifprog/test_listremoveifprog.go

@ -1,105 +0,0 @@
package main
import (
"strconv"
"github.com/01-edu/z01"
correct "./correct"
)
type Node10 = NodeL
type List10 = correct.List
type NodeS10 = correct.NodeL
type ListS10 = List
func listToStringStu12(l *ListS10) string {
var res string
it := l.Head
for it != nil {
switch it.Data.(type) {
case int:
res += strconv.Itoa(it.Data.(int)) + "-> "
case string:
res += it.Data.(string) + "-> "
}
it = it.Next
}
res += "<nil>"
return res
}
func listPushBackTest10(l1 *ListS10, l2 *List10, data interface{}) {
n := &Node10{Data: data}
n1 := &NodeS10{Data: data}
if l1.Head == nil {
l1.Head = n
} else {
iterator := l1.Head
for iterator.Next != nil {
iterator = iterator.Next
}
iterator.Next = n
}
if l2.Head == nil {
l2.Head = n1
} else {
iterator1 := l2.Head
for iterator1.Next != nil {
iterator1 = iterator1.Next
}
iterator1.Next = n1
}
}
func comparFuncList10(l1 *List10, l2 *ListS10, data interface{}) {
for l1.Head != nil || l2.Head != nil {
if (l1.Head == nil && l2.Head != nil) || (l1.Head != nil && l2.Head == nil) {
z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n",
data, listToStringStu12(l2), correct.ListToString(l1.Head), l2.Head, l1.Head)
}
if l1.Head.Data != l2.Head.Data {
z01.Fatalf("\ndata used: %v\nstudent list:%s\nlist:%s\n\nListRemoveIf() == %v instead of %v\n\n",
data, listToStringStu12(l2), correct.ListToString(l1.Head), l2.Head.Data, l1.Head.Data)
}
l1.Head = l1.Head.Next
l2.Head = l2.Head.Next
}
}
// removes all the elements that are equal to a value
func main() {
link1 := &List10{}
link2 := &ListS10{}
table := []correct.NodeTest{}
table = correct.ElementsToTest(table)
table = append(table,
correct.NodeTest{
Data: []interface{}{"hello", "hello1", "hello2", "hello3"},
},
)
for _, arg := range table {
for i := 0; i < len(arg.Data); i++ {
listPushBackTest10(link2, link1, arg.Data[i])
}
aux := len(arg.Data) - 1
index := z01.RandIntBetween(0, aux)
if link1.Head != nil && link2.Head != nil {
cho := arg.Data[index]
ListRemoveIf(link2, cho)
correct.ListRemoveIf(link1, cho)
comparFuncList10(link1, link2, cho)
} else {
ListRemoveIf(link2, 1)
correct.ListRemoveIf(link1, 1)
comparFuncList10(link1, link2, 1)
}
link1 = &List10{}
link2 = &ListS10{}
}
}

24
tests/go/solutions/listsizeprog/main.go

@ -1,24 +0,0 @@
package main
type NodeL struct {
Data interface{}
Next *NodeL
}
type List struct {
Head *NodeL
Tail *NodeL
}
func ListSize(l *List) int {
count := 0
iterator := l.Head
for iterator != nil {
count++
iterator = iterator.Next
}
return count
}
func main() {
}

60
tests/go/solutions/listsizeprog/test_listsizeprog.go

@ -1,60 +0,0 @@
package main
import (
"github.com/01-edu/z01"
correct "./correct"
)
type Node2 = NodeL
type List2 = correct.List
type NodeS2 = correct.NodeL
type ListS2 = List
func listPushBackTest2(l *ListS2, l1 *List2, data interface{}) {
n := &Node2{Data: data}
n1 := &NodeS2{Data: data}
if l.Head == nil {
l.Head = n
} else {
iterator := l.Head
for iterator.Next != nil {
iterator = iterator.Next
}
iterator.Next = n
}
if l1.Head == nil {
l1.Head = n1
} else {
iterator1 := l1.Head
for iterator1.Next != nil {
iterator1 = iterator1.Next
}
iterator1.Next = n1
}
}
func main() {
link := &List2{}
link2 := &ListS2{}
table := []correct.NodeTest{}
table = correct.ElementsToTest(table)
table = append(table,
correct.NodeTest{
Data: []interface{}{"Hello", "man", "how are you"},
},
)
for _, arg := range table {
for i := 0; i < len(arg.Data); i++ {
listPushBackTest2(link2, link, arg.Data[i])
}
aux := correct.ListSize(link)
aux2 := ListSize(link2)
if aux != aux2 {
z01.Fatalf("ListSize(%v) == %d instead of %d\n", correct.ListToString(link.Head), aux2, aux)
}
link = &List2{}
link2 = &ListS2{}
}
}

14
tests/go/solutions/maxprog/main.go

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

17
tests/go/solutions/maxprog/test_maxprog.go

@ -1,17 +0,0 @@
package main
import (
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
args := []int{z01.RandInt()}
limit := z01.RandIntBetween(20, 50)
for i := 0; i < limit; i++ {
args = append(args, z01.RandInt())
}
z01.Challenge("MaxProg", Max, correct.Max, args)
}

38
tests/go/solutions/nruneprog/main.go

@ -1,38 +0,0 @@
package main
import (
"fmt"
"os"
"strconv"
correct ".."
)
func NRune(s string, n int) rune {
if n > len(s) || n < 1 {
return 0
}
runes := []rune(s)
return runes[n-1]
}
func main() {
if len(os.Args) != 3 {
return
}
val, err := strconv.Atoi(os.Args[2])
if err != nil {
fmt.Printf("\"%s\" is not an integer value\n", os.Args[2])
return
}
rune := correct.NRune(os.Args[1], val)
if rune == 0 {
fmt.Printf("Invalid position: \"%d\" in \"%s\"\n", val, os.Args[1])
return
}
fmt.Printf("%c\n", rune)
}

43
tests/go/solutions/nruneprog/test_nruneprog.go

@ -1,43 +0,0 @@
package main
import (
"math/rand"
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
type node struct {
word string
n int
}
table := []node{}
for i := 0; i < 30; i++ {
wordToInput := z01.RandASCII()
val := node{
word: wordToInput,
n: rand.Intn(len(wordToInput)) + 1,
}
table = append(table, val)
}
table = append(table,
node{word: "Hello!", n: 3},
node{word: "Salut!", n: 2},
node{word: "Ola!", n: 4},
node{word: "♥01!", n: 1},
node{word: "Not", n: 6},
node{word: "Also not", n: 9},
node{word: "Tree house", n: 5},
node{word: "Whatever", n: 0},
node{word: "Whatshisname", n: -2},
)
for _, arg := range table {
z01.Challenge("NRuneProg", NRune, correct.NRune, arg.word, arg.n)
}
}

10
tests/go/solutions/printalphabetprog/main.go

@ -1,10 +0,0 @@
package main
import "fmt"
func main() {
for r := 'a'; r <= 'z'; r++ {
fmt.Print(r)
}
fmt.Println()
}

7
tests/go/solutions/printalphabetprog/test_printalphabetprog.go

@ -1,7 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
z01.ChallengeMain("printalphabetprog")
}

25
tests/go/solutions/printcombprog/main.go

@ -1,25 +0,0 @@
package main
import "github.com/01-edu/z01"
func printComb() {
for i := '0'; i <= '7'; i++ {
for j := i + 1; j <= '8'; j++ {
for k := j + 1; k <= '9'; k++ {
z01.PrintRune(i)
z01.PrintRune(j)
z01.PrintRune(k)
if i < '7' {
z01.PrintRune(',')
z01.PrintRune(' ')
} else {
z01.PrintRune('\n')
}
}
}
}
}
func main() {
printComb()
}

7
tests/go/solutions/printcombprog/test_printcombprog.go

@ -1,7 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
z01.ChallengeMain("printcombprog")
}

10
tests/go/solutions/printdigitsprog/main.go

@ -1,10 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
for i := '0'; i <= '9'; i++ {
z01.PrintRune(i)
}
z01.PrintRune('\n')
}

7
tests/go/solutions/printdigitsprog/test_printdigitsprog.go

@ -1,7 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
z01.ChallengeMain("printdigitsprog")
}

10
tests/go/solutions/printreversealphabetprog/main.go

@ -1,10 +0,0 @@
package main
import "fmt"
func main() {
for r := 'z'; r >= 'a'; r-- {
fmt.Print(r)
}
fmt.Println()
}

7
tests/go/solutions/printreversealphabetprog/test_printreversealphabetprog.go

@ -1,7 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
z01.ChallengeMain("printreversealphabetprog")
}

14
tests/go/solutions/printstrprog/main.go

@ -1,14 +0,0 @@
package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) != 2 {
return
}
fmt.Println(os.Args[1])
}

11
tests/go/solutions/printstrprog/test_printstrprog.go

@ -1,11 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
table := z01.MultRandASCII()
for _, arg := range table {
z01.ChallengeMain("printstrprog", arg)
}
z01.ChallengeMain("printstrprog", "Hello World!")
}

32
tests/go/solutions/rot14prog/main.go

@ -1,32 +0,0 @@
package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) != 2 {
return
}
var result string
for _, r := range os.Args[1] {
if r >= 'a' && r <= 'z' {
if r >= 'm' {
r -= 12
} else {
r += 14
}
} else if r >= 'A' && r <= 'Z' {
if r >= 'M' {
r -= 12
} else {
r += 14
}
}
result += string(r)
}
fmt.Println(result)
}

14
tests/go/solutions/rot14prog/test_rot14prog.go

@ -1,14 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
table := append(z01.MultRandWords(),
z01.MultRandWords()...,
)
for _, arg := range table {
z01.ChallengeMain("rot14prog", arg)
}
z01.ChallengeMain("rot14prog", "", "something", "something1")
}

10
tests/go/solutions/sortwordarrprog/main.go

@ -1,10 +0,0 @@
package main
import "sort"
func SortWordArr(a []string) {
sort.Strings(a)
}
func main() {
}

39
tests/go/solutions/sortwordarrprog/test_sortwordarrprog.go

@ -1,39 +0,0 @@
package main
import (
"reflect"
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
table := [][]string{{"a", "A", "1", "b", "B", "2", "c", "C", "3"}}
for i := 0; i < 15; i++ {
table = append(table, z01.MultRandWords())
}
for _, org := range table {
// copy for using the solution function
cp_sol := make([]string, len(org))
// copy for using the student function
cp_stu := make([]string, len(org))
copy(cp_sol, org)
copy(cp_stu, org)
correct.SortWordArr(cp_sol)
SortWordArr(cp_stu)
if !reflect.DeepEqual(cp_stu, cp_sol) {
z01.Fatalf("%s(%v) == %v instead of %v\n",
"SortWordArr",
org,
cp_stu,
cp_sol,
)
}
}
}

10
tests/go/solutions/splitprog/main.go

@ -1,10 +0,0 @@
package main
import "strings"
func Split(s, sep string) []string {
return strings.Split(s, sep)
}
func main() {
}

46
tests/go/solutions/splitprog/test_splitprog.go

@ -1,46 +0,0 @@
package main
import (
"math/rand"
"strings"
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
separators := []string{
"!=HA=!",
"!==!",
" ",
"|=choumi=|",
"|<=>|",
z01.RandStr(3, z01.RuneRange('A', 'Z')),
"<<==123==>>",
"[<>abc<>]",
}
type node struct {
str string
sep string
}
table := []node{}
// 15 random slice of strings
for i := 0; i < 15; i++ {
separator := separators[rand.Intn(len(separators))]
val := node{
str: strings.Join(z01.MultRandAlnum(), separator),
sep: separator,
}
table = append(table, val)
}
table = append(table,
node{str: "HelloHAhowHAareHAyou?", sep: "HA"})
for _, arg := range table {
z01.Challenge("SplitProg", Split, correct.Split, arg.str, arg.sep)
}
}

14
tests/go/solutions/strlenprog/main.go

@ -1,14 +0,0 @@
package main
func StrLen(str string) int {
len := 0
strConverted := []rune(str)
for i := range strConverted {
len = i + 1
}
return len
}
func main() {
}

24
tests/go/solutions/strlenprog/test_strlenprog.go

@ -1,24 +0,0 @@
package main
import (
"github.com/01-edu/z01"
correct "./correct"
)
func main() {
randomStringCharset := "a b c d e f g h ijklmnopqrstuvwxyz A B C D E FGHIJKLMNOPRSTUVWXYZ"
table := []string{}
for i := 0; i < 10; i++ {
randomLenghtOfWord := z01.RandIntBetween(1, 20)
randomStrRandomLenght := z01.RandStr(randomLenghtOfWord, randomStringCharset)
table = append(table, randomStrRandomLenght)
}
table = append(table, "Héllo!")
table = append(table, randomStringCharset)
for _, s := range table {
z01.Challenge("StrLenProg", StrLen, correct.StrLen, s)
}
}

14
tests/go/solutions/strrevprog/main.go

@ -1,14 +0,0 @@
package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) != 2 {
return
}
fmt.Println(correct.StrRev(os.Args[1]))
}

14
tests/go/solutions/strrevprog/test_strrevprog.go

@ -1,14 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
table := append(z01.MultRandASCII(),
"Hello!",
"Bonjour!",
"Hola!",
)
for _, arg := range table {
z01.ChallengeMain("strrevprog", arg)
}
}

10
tests/go/solutions/swapprog/main.go

@ -1,10 +0,0 @@
package main
func Swap(a, b *int) {
temp := *a
*a = *b
*b = temp
}
func main() {
}

21
tests/go/solutions/swapprog/test_swapprog.go

@ -1,21 +0,0 @@
package main
import "github.com/01-edu/z01"
func main() {
i := 0
for i < 30 {
a := z01.RandInt()
b := z01.RandInt()
aCopy := a
bCopy := b
Swap(&a, &b)
if a != bCopy {
z01.Fatalf("Swap(%d, %d), a == %d instead of %d", aCopy, bCopy, a, bCopy)
}
if b != aCopy {
z01.Fatalf("Swap(%d, %d), b == %d instead of %d", aCopy, bCopy, b, aCopy)
}
i++
}
}
Loading…
Cancel
Save