Skip to content

Commit ec2fa0a

Browse files
committed
✨ (clockface): add minutesInRadians implementation
1 parent 8915e5f commit ec2fa0a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

clockface_sample/clockface/clockface.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ func secondHandPoint(t time.Time) Point {
3636

3737
return Point{x, y}
3838
}
39+
40+
func minutesInRadians(t time.Time) float64 {
41+
return (secondsInRadians(t) / 60) +
42+
(math.Pi / (30 / float64(t.Minute())))
43+
}

clockface_sample/clockface/clockface_acceptance_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,29 @@ func TestSecondHandAt30Seconds(t *testing.T) {
100100
t.Errorf("got %v, wanted %v", got, want)
101101
}
102102
}
103+
104+
// func TestSVGWriterMinuteHand(t *testing.T) {
105+
// cases := []struct {
106+
// time time.Time
107+
// line Line
108+
// }{
109+
// {
110+
// simpleTime(0, 0, 0),
111+
// Line{150, 150, 150, 70},
112+
// },
113+
// }
114+
115+
// for _, c := range cases {
116+
// t.Run(testName(c.time), func(t *testing.T) {
117+
// b := bytes.Buffer{}
118+
// clockface.SVGWriter(&b, c.time)
119+
120+
// svg := SVG{}
121+
// xml.Unmarshal(b.Bytes(), &svg)
122+
123+
// if !containsLine(c.line, svg.Line) {
124+
// t.Errorf("Expected to find the minute hand line %+v, in the SVG lines %+v", c.line, svg.Line)
125+
// }
126+
// })
127+
// }
128+
// }

clockface_sample/clockface/clockface_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,22 @@ func roughlyEqualPoint(a, b Point) bool {
6262
return roughlyEqualFloat64(a.X, b.X) &&
6363
roughlyEqualFloat64(a.Y, b.Y)
6464
}
65+
66+
func TestMinutesInRadians(t *testing.T) {
67+
cases := []struct {
68+
time time.Time
69+
angle float64
70+
}{
71+
{simpleTime(0, 30, 0), math.Pi},
72+
{simpleTime(0, 0, 7), 7 * (math.Pi / (30 * 60))},
73+
}
74+
75+
for _, c := range cases {
76+
t.Run(testName(c.time), func(t *testing.T) {
77+
got := minutesInRadians(c.time)
78+
if got != c.angle {
79+
t.Fatalf("Wanted %v radians, but got %v", c.angle, got)
80+
}
81+
})
82+
}
83+
}

0 commit comments

Comments
 (0)