-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
for those two functions we need test cases (each)!
example! try it out to understand!
cat <<EOF > ankit.go
package main
import "fmt"
func Sum(x int, y int) int {
return x + y
}
func main() {
Sum(5, 5)
fmt.Println(Sum(5, 5))
}
EOF
cat <<EOF > ankit_test.go
package main
import "testing"
func TestSum(t *testing.T) {
type test struct {
number1 int
number2 int
want int
}
tests := []test{
{number1: 5, number2: 2, want: 7},
{number1: 6, number2: 9, want: 15},
{number1: 7, number2: 112, want: 119},
}
for _, tc := range tests {
total := Sum(tc.number1, tc.number2)
if total != tc.want {
t.Errorf("Sum was incorrect, got: %d, want: %d.", total, tc.want)
}
}
}
EOF
go mod init ankit
go mod tidy
go run ankit.go
go test -v
we want to test those two functions w/ proper test cases
e.g. input: []string{"Kind", "Name", "Name"}
expected output: []string{"Kind", "Name"}
func removeDuplicateStr(results []string) []string {
allKeys := make(map[string]bool)
list := []string{}
for _, item := range results {
if _, value := allKeys[item]; !value {
allKeys[item] = true
list = append(list, item)
}
}
return list
}
func GetAllRegexMatches(scanText, regexPattern string) []string {
re := regexp.MustCompile(regexPattern)
return re.FindAllString(scanText, -1)
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels