Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
student "student"
|
|
|
|
|
|
|
|
"github.com/01-edu/public/test-go/lib"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
func main() {
|
|
|
|
arg := [][]string{{"hello", "", "hi", "", "salut", "", ""}}
|
|
|
|
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
n := lib.RandIntBetween(5, 20)
|
|
|
|
|
|
|
|
orig := make([]string, n)
|
|
|
|
|
|
|
|
numPos := lib.RandIntBetween(1, n-1)
|
|
|
|
|
|
|
|
for i := 0; i < numPos; i++ {
|
|
|
|
word := lib.RandWords()
|
|
|
|
randPos := lib.RandIntBetween(0, n-1)
|
|
|
|
orig[randPos] = word
|
|
|
|
}
|
|
|
|
arg = append(arg, orig)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range arg {
|
|
|
|
solSlice := make([]string, len(arg))
|
|
|
|
stuSlice := make([]string, len(arg))
|
|
|
|
|
|
|
|
copy(solSlice, v)
|
|
|
|
copy(stuSlice, v)
|
|
|
|
|
|
|
|
solSize := compact(&solSlice)
|
|
|
|
stuSize := student.Compact(&stuSlice)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(stuSlice, solSlice) {
|
|
|
|
lib.Fatalf("Produced slice: %v, instead of %v\n",
|
|
|
|
stuSlice,
|
|
|
|
solSlice,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if solSize != stuSize {
|
|
|
|
lib.Fatalf("%s(%v) == %v instead of %v\n",
|
|
|
|
"Compact",
|
|
|
|
v,
|
|
|
|
stuSlice,
|
|
|
|
solSlice,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|