clockface: refactorize acceptance test
This commit is contained in:
		@ -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
 | 
				
			||||||
	b := bytes.Buffer{}
 | 
							line Line
 | 
				
			||||||
	SVGWriter(&b, tm)
 | 
						}{
 | 
				
			||||||
 | 
							{simpleTime(0, 0, 0), Line{150, 150, 150, 60}},
 | 
				
			||||||
	svg := Svg{}
 | 
							{simpleTime(0, 0, 30), Line{150, 150, 150, 240}},
 | 
				
			||||||
	xml.Unmarshal(b.Bytes(), &svg)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	x2 := "150.000000"
 | 
					 | 
				
			||||||
	y2 := "60.000000"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, line := range svg.Line {
 | 
					 | 
				
			||||||
		if line.X2 == x2 && line.Y2 == y2 {
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	t.Errorf(
 | 
						for _, c := range cases {
 | 
				
			||||||
		"Expected to find the second hand with x2 of %+v and y2 of %+v, in the SVG output %v",
 | 
							t.Run(testName(c.time), func(t *testing.T) {
 | 
				
			||||||
		x2,
 | 
								b := bytes.Buffer{}
 | 
				
			||||||
		y2,
 | 
								SVGWriter(&b, c.time)
 | 
				
			||||||
		b.String(),
 | 
					
 | 
				
			||||||
	)
 | 
								svg := Svg{}
 | 
				
			||||||
 | 
								xml.Unmarshal(b.Bytes(), &svg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if !containsLine(c.line, svg.Line) {
 | 
				
			||||||
 | 
									t.Errorf(
 | 
				
			||||||
 | 
										"Expected to find the second hand line %+v in the SVG lines %v",
 | 
				
			||||||
 | 
										c.line,
 | 
				
			||||||
 | 
										svg.Line,
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func containsLine(l Line, ls []Line) bool {
 | 
				
			||||||
 | 
						for _, line := range ls {
 | 
				
			||||||
 | 
							if line == l {
 | 
				
			||||||
 | 
								return true
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user