Last active
November 23, 2020 18:18
-
-
Save maykonchagas/50ebf215fd9fde3bbb95f3c2ea9f0bbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a "stub" file. It's a little start on your solution. | |
// It's not a complete solution though; you have to write some code. | |
// Package twofer should have a package comment that summarizes what it's about. | |
// https://golang.org/doc/effective_go.html#commentary | |
package twofer | |
import "fmt" | |
// ShareWith should have a comment documenting it. | |
func ShareWith(name string) string { | |
// Write some code here to pass the test suite. | |
// Then remove all the stock comments. | |
// They're here to help you get started but they only clutter a finished solution. | |
// If you leave them in, reviewers may protest! | |
h := "" | |
if h == "Maykon" { | |
fmt.Printf("One for %v, one for me.", h) | |
} else { | |
fmt.Println("One for you, one for me.") | |
} | |
return "" | |
} | |
### two_for_test.go | |
package twofer | |
import "testing" | |
// Define a function ShareWith(string) string. | |
var tests = []struct { | |
name, expected string | |
}{ | |
{"", "One for you, one for me."}, | |
{"Alice", "One for Alice, one for me."}, | |
{"Bob", "One for Bob, one for me."}, | |
} | |
func TestShareWith(t *testing.T) { | |
for _, test := range tests { | |
if observed := ShareWith(test.name); observed != test.expected { | |
t.Fatalf("ShareWith(%s) = \"%v\", want \"%v\"", test.name, observed, test.expected) | |
} | |
} | |
} | |
func BenchmarkShareWith(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
for _, test := range tests { | |
ShareWith(test.name) | |
} | |
} | |
} |
benmezger
commented
Nov 23, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment