clockface: refactorize acceptance test
This commit is contained in:
parent
7b3fb0f91c
commit
b58e2436cd
@ -9,73 +9,61 @@ import (
|
|||||||
|
|
||||||
type Svg struct {
|
type Svg struct {
|
||||||
XMLName xml.Name `xml:"svg"`
|
XMLName xml.Name `xml:"svg"`
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Xmlns string `xml:"xmlns,attr"`
|
Xmlns string `xml:"xmlns,attr"`
|
||||||
Width string `xml:"width,attr"`
|
Width string `xml:"width,attr"`
|
||||||
Height string `xml:"height,attr"`
|
Height string `xml:"height,attr"`
|
||||||
ViewBox string `xml:"viewBox,attr"`
|
ViewBox string `xml:"viewBox,attr"`
|
||||||
Version string `xml:"version,attr"`
|
Version string `xml:"version,attr"`
|
||||||
Circle struct {
|
Circle Circle `xml:"circle"`
|
||||||
Text string `xml:",chardata"`
|
Line []Line `xml:"line"`
|
||||||
Cx string `xml:"cx,attr"`
|
|
||||||
Cy string `xml:"cy,attr"`
|
|
||||||
R string `xml:"r,attr"`
|
|
||||||
Style string `xml:"style,attr"`
|
|
||||||
} `xml:"circle"`
|
|
||||||
Line []struct {
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
X1 string `xml:"x1,attr"`
|
|
||||||
Y1 string `xml:"y1,attr"`
|
|
||||||
X2 string `xml:"x2,attr"`
|
|
||||||
Y2 string `xml:"y2,attr"`
|
|
||||||
Style string `xml:"style,attr"`
|
|
||||||
} `xml:"line"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestSecondHandAtMidnight(t *testing.T) {
|
type Circle struct {
|
||||||
// tm := time.Date(1337, time.January, 1, 0, 0, 0, 0, time.UTC)
|
Cx float64 `xml:"cx,attr"`
|
||||||
//
|
Cy float64 `xml:"cy,attr"`
|
||||||
// want := Point{X: 150, Y: 150 - 90}
|
R float64 `xml:"r,attr"`
|
||||||
// got := SecondHand(tm)
|
}
|
||||||
//
|
|
||||||
// if got != want {
|
|
||||||
// t.Errorf("Got %v, wanted %v", got, want)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestSecondHandAt30Seconds(t *testing.T) {
|
type Line struct {
|
||||||
// tm := time.Date(1337, time.January, 1, 0, 0, 30, 0, time.UTC)
|
X1 float64 `xml:"x1,attr"`
|
||||||
//
|
Y1 float64 `xml:"y1,attr"`
|
||||||
// want := Point{X: 150, Y: 150 + 90}
|
X2 float64 `xml:"x2,attr"`
|
||||||
// got := SecondHand(tm)
|
Y2 float64 `xml:"y2,attr"`
|
||||||
//
|
}
|
||||||
// if got != want {
|
|
||||||
// t.Errorf("Got %v, wanted %v", got, want)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
func TestSVGWriterAtMidnight(t *testing.T) {
|
func TestSVGWriterSecondHand(t *testing.T) {
|
||||||
tm := time.Date(1337, time.January, 1, 0, 0, 0, 0, time.UTC)
|
cases := []struct {
|
||||||
|
time time.Time
|
||||||
|
line Line
|
||||||
|
}{
|
||||||
|
{simpleTime(0, 0, 0), Line{150, 150, 150, 60}},
|
||||||
|
{simpleTime(0, 0, 30), Line{150, 150, 150, 240}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
t.Run(testName(c.time), func(t *testing.T) {
|
||||||
b := bytes.Buffer{}
|
b := bytes.Buffer{}
|
||||||
SVGWriter(&b, tm)
|
SVGWriter(&b, c.time)
|
||||||
|
|
||||||
svg := Svg{}
|
svg := Svg{}
|
||||||
xml.Unmarshal(b.Bytes(), &svg)
|
xml.Unmarshal(b.Bytes(), &svg)
|
||||||
|
|
||||||
x2 := "150.000000"
|
if !containsLine(c.line, svg.Line) {
|
||||||
y2 := "60.000000"
|
|
||||||
|
|
||||||
for _, line := range svg.Line {
|
|
||||||
if line.X2 == x2 && line.Y2 == y2 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"Expected to find the second hand with x2 of %+v and y2 of %+v, in the SVG output %v",
|
"Expected to find the second hand line %+v in the SVG lines %v",
|
||||||
x2,
|
c.line,
|
||||||
y2,
|
svg.Line,
|
||||||
b.String(),
|
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func containsLine(l Line, ls []Line) bool {
|
||||||
|
for _, line := range ls {
|
||||||
|
if line == l {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user