mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.1 KiB
58 lines
1.1 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
5 years ago
|
"strings"
|
||
|
|
||
5 years ago
|
student "student"
|
||
|
|
||
|
"lib"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func index(s string, substr string) int {
|
||
|
return strings.Index(s, substr)
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
type node struct {
|
||
|
s string
|
||
|
toFind string
|
||
|
}
|
||
|
|
||
|
table := []node{}
|
||
|
|
||
|
// the first 15 values are valid for this test
|
||
|
for i := 0; i < 15; i++ {
|
||
5 years ago
|
wordToTest := lib.RandASCII()
|
||
|
firstLetterIndex := lib.RandIntBetween(0, (len(wordToTest)-1)/2)
|
||
|
lastLetterIndex := lib.RandIntBetween(firstLetterIndex, len(wordToTest)-1)
|
||
5 years ago
|
|
||
|
val := node{
|
||
|
s: wordToTest,
|
||
|
toFind: wordToTest[firstLetterIndex:lastLetterIndex],
|
||
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
|
||
|
// the next 15 values are supposed to be invalid for this test
|
||
|
for i := 0; i < 15; i++ {
|
||
5 years ago
|
wordToTest := lib.RandASCII()
|
||
|
wrongMatch := lib.RandASCII()
|
||
5 years ago
|
|
||
|
val := node{
|
||
|
s: wordToTest,
|
||
|
toFind: wrongMatch,
|
||
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
// those are the test values from the README examples
|
||
|
table = append(table,
|
||
|
node{s: "Hello!", toFind: "l"},
|
||
|
node{s: "Salut!", toFind: "alu"},
|
||
|
node{s: "Ola!", toFind: "hOl"},
|
||
|
)
|
||
|
|
||
|
for _, arg := range table {
|
||
5 years ago
|
lib.Challenge("Index", student.Index, index, arg.s, arg.toFind)
|
||
5 years ago
|
}
|
||
|
}
|