From bacb0023b5c38b394dc6821659b602668bef4c4e Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Tue, 12 Jul 2016 19:38:24 -0700 Subject: [PATCH] removing point, adding tests. --- box_test.go | 21 +++++++++++++++++++++ grid_line_test.go | 27 +++++++++++++++++++++++++++ point.go | 41 ----------------------------------------- 3 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 grid_line_test.go delete mode 100644 point.go diff --git a/box_test.go b/box_test.go index 0ff04d3..84787e8 100644 --- a/box_test.go +++ b/box_test.go @@ -85,3 +85,24 @@ func TestBoxFit(t *testing.T) { assert.Equal(a.Bottom, fac.Bottom) assert.True(math.Abs(c.Aspect()-fac.Aspect()) < 0.02) } + +func TestBoxOuterConstrain(t *testing.T) { + assert := assert.New(t) + + box := Box{0, 0, 100, 100} + canvas := Box{5, 5, 95, 95} + taller := Box{-10, 5, 50, 50} + + c := canvas.OuterConstrain(box, taller) + assert.Equal(15, c.Top, c.String()) + assert.Equal(5, c.Left, c.String()) + assert.Equal(95, c.Right, c.String()) + assert.Equal(95, c.Bottom, c.String()) + + wider := Box{5, 5, 110, 50} + d := canvas.OuterConstrain(box, wider) + assert.Equal(5, d.Top, d.String()) + assert.Equal(5, d.Left, d.String()) + assert.Equal(85, d.Right, d.String()) + assert.Equal(95, d.Bottom, d.String()) +} diff --git a/grid_line_test.go b/grid_line_test.go new file mode 100644 index 0000000..1d4f23a --- /dev/null +++ b/grid_line_test.go @@ -0,0 +1,27 @@ +package chart + +import ( + "testing" + + "github.com/blendlabs/go-assert" +) + +func TestGenerateGridLines(t *testing.T) { + assert := assert.New(t) + + ticks := []Tick{ + Tick{Value: 1.0, Label: "1.0"}, + Tick{Value: 2.0, Label: "2.0"}, + Tick{Value: 3.0, Label: "3.0"}, + Tick{Value: 4.0, Label: "4.0"}, + } + + gl := GenerateGridLines(ticks, true) + assert.Len(gl, 4) + assert.Equal(1.0, gl[0].Value) + assert.Equal(2.0, gl[1].Value) + assert.Equal(3.0, gl[2].Value) + assert.Equal(4.0, gl[3].Value) + + assert.True(gl[0].IsVertical) +} diff --git a/point.go b/point.go deleted file mode 100644 index cfd976f..0000000 --- a/point.go +++ /dev/null @@ -1,41 +0,0 @@ -package chart - -// Points are an array of points. -import ( - "fmt" - "strings" -) - -// Point represents a x,y coordinate. -type Point struct { - X float64 - Y float64 -} - -// Points represents a group of points. -type Points []Point - -// String returns a string representation of the points. -func (p Points) String() string { - var values []string - for _, v := range p { - values = append(values, fmt.Sprintf("%d,%d", int(v.X), int(v.Y))) - } - return strings.Join(values, "\n") -} - -// Len returns the length of the points set. -func (p Points) Len() int { - return len(p) -} - -// Swap swaps two elments. -func (p Points) Swap(i, j int) { - p[i], p[j] = p[j], p[i] -} - -// Less returns if the X value of one element is less than another. -// This is the default sort for charts where you plot by x values in order. -func (p Points) Less(i, j int) bool { - return p[i].X < p[j].X -}