-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from vaskoz/day129
Day129
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package day129 | ||
|
||
import "math" | ||
|
||
// Sqrt is a wrapper for math.Sqrt in the standard library. | ||
func Sqrt(n float64) float64 { | ||
return math.Sqrt(n) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package day129 | ||
|
||
import "testing" | ||
|
||
var testcases = []struct { | ||
n, expected float64 | ||
}{ | ||
{9.0, 3.0}, | ||
{36.0, 6.0}, | ||
{81.0, 9.0}, | ||
} | ||
|
||
func TestSqrt(t *testing.T) { | ||
t.Parallel() | ||
for _, tc := range testcases { | ||
if result := Sqrt(tc.n); result != tc.expected { | ||
t.Errorf("Expected %v got %v", tc.expected, result) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkSqrt(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
for _, tc := range testcases { | ||
Sqrt(tc.n) | ||
} | ||
} | ||
} |