Skip to content

Commit

Permalink
Merge pull request #264 from vaskoz/day129
Browse files Browse the repository at this point in the history
Day129
  • Loading branch information
vaskoz committed Dec 29, 2018
2 parents 001b1f6 + 0c643c8 commit e3197fd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ problems from
* [Day 124](https://github.com/vaskoz/dailycodingproblem-go/issues/255)
* [Day 125](https://github.com/vaskoz/dailycodingproblem-go/issues/257)
* [Day 127](https://github.com/vaskoz/dailycodingproblem-go/issues/259)
* [Day 129](https://github.com/vaskoz/dailycodingproblem-go/issues/263)
8 changes: 8 additions & 0 deletions day129/problem.go
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)
}
28 changes: 28 additions & 0 deletions day129/problem_test.go
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)
}
}
}

0 comments on commit e3197fd

Please sign in to comment.