Skip to content

Commit af79757

Browse files
committed
✨ (clockface): add secondsInRadians sample
1 parent 1159e99 commit af79757

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

clockface/clockface.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package clockface
2+
3+
import (
4+
"math"
5+
"time"
6+
)
7+
8+
// A Point represents a two-dimensional Cartesian coordinate
9+
type Point struct {
10+
X float64
11+
Y float64
12+
}
13+
14+
// SecondHand is the unit vector of the second hand of an analogue clock at time `t`
15+
// represented as a Point
16+
func SecondHand(t time.Time) Point {
17+
return Point{150, 60}
18+
}
19+
20+
func secondsInRadians(t time.Time) float64 {
21+
return math.Pi
22+
}

clockface/clockface_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package clockface
2+
3+
import (
4+
"math"
5+
"testing"
6+
"time"
7+
)
8+
9+
func TestSecondHandAtMidnight(t *testing.T) {
10+
tm := time.Date(1337, time.January, 1, 0, 0, 0, 0, time.UTC)
11+
12+
want := Point{X: 150, Y: 150 - 90}
13+
got := SecondHand(tm)
14+
15+
if got != want {
16+
t.Errorf("Got %v, wanted %v", got, want)
17+
}
18+
}
19+
20+
// func TestSecondHandAt30Seconds(t *testing.T) {
21+
// tm := time.Date(1337, time.January, 1, 0, 0, 30, 0, time.UTC)
22+
23+
// want := clockface.Point{X: 150, Y: 150 + 90}
24+
// got := clockface.SecondHand(tm)
25+
26+
// if got != want {
27+
// t.Errorf("got %v, wanted %v", got, want)
28+
// }
29+
// }
30+
31+
func TestSecondsInRadians(t *testing.T) {
32+
thirtySeconds := time.Date(312, time.October, 28, 0, 0, 30, 0, time.UTC)
33+
want := math.Pi
34+
got := secondsInRadians(thirtySeconds)
35+
36+
if want != got {
37+
t.Fatalf("Wanted %v radians, but got %v", want, got)
38+
}
39+
}

0 commit comments

Comments
 (0)