From 7c3982fe3d8ab0c9eea9ab5d2aced51e45d447bc Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Thu, 5 Apr 2018 00:47:39 -0700 Subject: [PATCH] fixing tests --- bar_chart_test.go | 2 +- grid_line_test.go | 2 +- market_hours_range_test.go | 2 +- matrix/regression_test.go | 2 +- seq/buffer_test.go | 2 +- seq/linear_test.go | 6 +++--- seq/random.go | 2 +- seq/random_test.go | 2 +- seq/sequence_test.go | 2 +- seq/time_test.go | 9 +++++---- text_test.go | 10 +++++----- tick_test.go | 4 ++-- util/math_test.go | 2 +- value_test.go | 6 +++--- xaxis_test.go | 4 ++-- yaxis_test.go | 4 ++-- 16 files changed, 31 insertions(+), 30 deletions(-) diff --git a/bar_chart_test.go b/bar_chart_test.go index 14dc231..32ce674 100644 --- a/bar_chart_test.go +++ b/bar_chart_test.go @@ -242,7 +242,7 @@ func TestBarChartGetAxesTicks(t *testing.T) { bc.YAxis.Style.Show = true ticks = bc.getAxesTicks(r, yr, yf) - assert.Len(ticks, 2) + assert.Len(2, ticks) } func TestBarChartCalculateEffectiveBarSpacing(t *testing.T) { diff --git a/grid_line_test.go b/grid_line_test.go index cbaedec..584d18d 100644 --- a/grid_line_test.go +++ b/grid_line_test.go @@ -17,7 +17,7 @@ func TestGenerateGridLines(t *testing.T) { } gl := GenerateGridLines(ticks, Style{}, Style{}) - assert.Len(gl, 2) + assert.Len(2, gl) assert.Equal(2.0, gl[0].Value) assert.Equal(3.0, gl[1].Value) diff --git a/market_hours_range_test.go b/market_hours_range_test.go index 26ff06b..564ea83 100644 --- a/market_hours_range_test.go +++ b/market_hours_range_test.go @@ -67,7 +67,7 @@ func TestMarketHoursRangeGetTicks(t *testing.T) { ticks := ra.GetTicks(r, defaults, TimeValueFormatter) assert.NotEmpty(ticks) - assert.Len(ticks, 5) + assert.Len(5, ticks) assert.NotEqual(util.Time.ToFloat64(ra.Min), ticks[0].Value) assert.NotEmpty(ticks[0].Label) } diff --git a/matrix/regression_test.go b/matrix/regression_test.go index 5bd282b..10caa28 100644 --- a/matrix/regression_test.go +++ b/matrix/regression_test.go @@ -14,7 +14,7 @@ func TestPoly(t *testing.T) { c, err := Poly(xGiven, yGiven, degree) assert.Nil(err) - assert.Len(c, 3) + assert.Len(3, c) assert.InDelta(c[0], 0.999999999, DefaultEpsilon) assert.InDelta(c[1], 2, DefaultEpsilon) diff --git a/seq/buffer_test.go b/seq/buffer_test.go index fb177d2..17685c4 100644 --- a/seq/buffer_test.go +++ b/seq/buffer_test.go @@ -132,7 +132,7 @@ func TestBufferArray(t *testing.T) { buffer.Enqueue(5) contents := buffer.Array() - assert.Len(contents, 5) + assert.Len(5, contents) assert.Equal(1, contents[0]) assert.Equal(2, contents[1]) assert.Equal(3, contents[2]) diff --git a/seq/linear_test.go b/seq/linear_test.go index f90b179..5e93e8c 100644 --- a/seq/linear_test.go +++ b/seq/linear_test.go @@ -10,7 +10,7 @@ func TestRange(t *testing.T) { assert := assert.New(t) values := Range(1, 100) - assert.Len(values, 100) + assert.Len(100, values) assert.Equal(1, values[0]) assert.Equal(100, values[99]) } @@ -20,7 +20,7 @@ func TestRangeWithStep(t *testing.T) { values := RangeWithStep(0, 100, 5) assert.Equal(100, values[20]) - assert.Len(values, 21) + assert.Len(21, values) } func TestRangeReversed(t *testing.T) { @@ -42,7 +42,7 @@ func TestValuesRegression(t *testing.T) { assert.Equal(100, linearProvider.Len()) values := Seq{Provider: linearProvider}.Array() - assert.Len(values, 100) + assert.Len(100, values) assert.Equal(1.0, values[0]) assert.Equal(100, values[99]) } diff --git a/seq/random.go b/seq/random.go index 3d0768f..ea65084 100644 --- a/seq/random.go +++ b/seq/random.go @@ -11,7 +11,7 @@ func RandomValues(count int) []float64 { return Seq{NewRandom().WithLen(count)}.Array() } -// RandomValuesWithAverage returns an array of random values with a given average. +// RandomValuesWithMax returns an array of random values with a given average. func RandomValuesWithMax(count int, max float64) []float64 { return Seq{NewRandom().WithMax(max).WithLen(count)}.Array() } diff --git a/seq/random_test.go b/seq/random_test.go index 8fd8602..d51e4a6 100644 --- a/seq/random_test.go +++ b/seq/random_test.go @@ -15,6 +15,6 @@ func TestRandomRegression(t *testing.T) { randomSequence := New(randomProvider) randomValues := randomSequence.Array() - assert.Len(randomValues, 4096) + assert.Len(4096, randomValues) assert.InDelta(128, randomSequence.Average(), 10.0) } diff --git a/seq/sequence_test.go b/seq/sequence_test.go index a1b8dd6..09f89e1 100644 --- a/seq/sequence_test.go +++ b/seq/sequence_test.go @@ -88,7 +88,7 @@ func TestSequenceNormalize(t *testing.T) { normalized := Values(1, 2, 3, 4, 5).Normalize().Array() assert.NotEmpty(normalized) - assert.Len(normalized, 5) + assert.Len(5, normalized) assert.Equal(0, normalized[0]) assert.Equal(0.25, normalized[1]) assert.Equal(1, normalized[4]) diff --git a/seq/time_test.go b/seq/time_test.go index e33a74e..9d6876d 100644 --- a/seq/time_test.go +++ b/seq/time_test.go @@ -13,7 +13,7 @@ func TestTimeMarketHours(t *testing.T) { today := time.Date(2016, 07, 01, 12, 0, 0, 0, util.Date.Eastern()) mh := Time.MarketHours(today, today, util.NYSEOpen(), util.NYSEClose(), util.Date.IsNYSEHoliday) - assert.Len(mh, 8) + assert.Len(8, mh) assert.Equal(util.Date.Eastern(), mh[0].Location()) } @@ -21,7 +21,7 @@ func TestTimeMarketHourQuarters(t *testing.T) { assert := assert.New(t) today := time.Date(2016, 07, 01, 12, 0, 0, 0, util.Date.Eastern()) mh := Time.MarketHourQuarters(today, today, util.NYSEOpen(), util.NYSEClose(), util.Date.IsNYSEHoliday) - assert.Len(mh, 4) + assert.Len(4, mh) assert.Equal(9, mh[0].Hour()) assert.Equal(30, mh[0].Minute()) assert.Equal(util.Date.Eastern(), mh[0].Location()) @@ -42,7 +42,7 @@ func TestTimeHours(t *testing.T) { seq := Time.Hours(today, 24) end := Time.End(seq) - assert.Len(seq, 24) + assert.Len(24, seq) assert.Equal(2016, end.Year()) assert.Equal(07, int(end.Month())) assert.Equal(02, end.Day()) @@ -73,7 +73,8 @@ func TestSequenceHoursFill(t *testing.T) { } filledTimes, filledValues := Time.HoursFilled(xdata, ydata) - assert.Len(filledTimes, util.Date.DiffHours(Time.Start(xdata), Time.End(xdata))+1) + expected := util.Date.DiffHours(Time.Start(xdata), Time.End(xdata)) + 1 + assert.Len(expected, filledTimes) assert.Equal(len(filledValues), len(filledTimes)) assert.NotZero(filledValues[0]) diff --git a/text_test.go b/text_test.go index 41034c4..e7ab72b 100644 --- a/text_test.go +++ b/text_test.go @@ -18,7 +18,7 @@ func TestTextWrapWord(t *testing.T) { output := Text.WrapFitWord(r, "this is a test string", 100, basicTextStyle) assert.NotEmpty(output) - assert.Len(output, 3) + assert.Len(3, output) for _, line := range output { basicTextStyle.WriteToRenderer(r) @@ -30,16 +30,16 @@ func TestTextWrapWord(t *testing.T) { assert.Equal("string", output[2]) output = Text.WrapFitWord(r, "foo", 100, basicTextStyle) - assert.Len(output, 1) + assert.Len(1, output) assert.Equal("foo", output[0]) // test that it handles newlines. output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring", 100, basicTextStyle) - assert.Len(output, 5) + assert.Len(5, output) // test that it handles newlines and long lines. output = Text.WrapFitWord(r, "this\nis\na\ntest\nstring that is very long", 100, basicTextStyle) - assert.Len(output, 8) + assert.Len(8, output) } func TestTextWrapRune(t *testing.T) { @@ -54,7 +54,7 @@ func TestTextWrapRune(t *testing.T) { output := Text.WrapFitRune(r, "this is a test string", 150, basicTextStyle) assert.NotEmpty(output) - assert.Len(output, 2) + assert.Len(2, output) assert.Equal("this is a t", output[0]) assert.Equal("est string", output[1]) } diff --git a/tick_test.go b/tick_test.go index 9802150..b8b6441 100644 --- a/tick_test.go +++ b/tick_test.go @@ -26,7 +26,7 @@ func TestGenerateContinuousTicks(t *testing.T) { ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf) assert.NotEmpty(ticks) - assert.Len(ticks, 11) + assert.Len(11, ticks) assert.Equal(0.0, ticks[0].Value) assert.Equal(10, ticks[len(ticks)-1].Value) } @@ -52,7 +52,7 @@ func TestGenerateContinuousTicksDescending(t *testing.T) { ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf) assert.NotEmpty(ticks) - assert.Len(ticks, 11) + assert.Len(11, ticks) assert.Equal(10.0, ticks[0].Value) assert.Equal(9.0, ticks[1].Value) assert.Equal(1.0, ticks[len(ticks)-2].Value) diff --git a/util/math_test.go b/util/math_test.go index 6a2e392..8306ae2 100644 --- a/util/math_test.go +++ b/util/math_test.go @@ -99,7 +99,7 @@ func TestNormalize(t *testing.T) { values := []float64{10, 9, 8, 7, 6} normalized := Math.Normalize(values...) - assert.Len(normalized, 5) + assert.Len(5, normalized) assert.Equal(0.25, normalized[0]) assert.Equal(0.1499, normalized[4]) } diff --git a/value_test.go b/value_test.go index ed7a96f..aeb1ae9 100644 --- a/value_test.go +++ b/value_test.go @@ -20,7 +20,7 @@ func TestValuesValues(t *testing.T) { } values := Values(vs).Values() - assert.Len(values, 7) + assert.Len(7, values) assert.Equal(10, values[0]) assert.Equal(9, values[1]) assert.Equal(8, values[2]) @@ -44,7 +44,7 @@ func TestValuesValuesNormalized(t *testing.T) { } values := Values(vs).ValuesNormalized() - assert.Len(values, 7) + assert.Len(7, values) assert.Equal(0.2127, values[0]) assert.Equal(0.0425, values[6]) } @@ -63,7 +63,7 @@ func TestValuesNormalize(t *testing.T) { } values := Values(vs).Normalize() - assert.Len(values, 7) + assert.Len(7, values) assert.Equal(0.2127, values[0].Value) assert.Equal(0.0425, values[6].Value) } diff --git a/xaxis_test.go b/xaxis_test.go index 516be73..e6a7fe1 100644 --- a/xaxis_test.go +++ b/xaxis_test.go @@ -23,7 +23,7 @@ func TestXAxisGetTicks(t *testing.T) { } vf := FloatValueFormatter ticks := xa.GetTicks(r, xr, styleDefaults, vf) - assert.Len(ticks, 16) + assert.Len(16, ticks) } func TestXAxisGetTicksWithUserDefaults(t *testing.T) { @@ -45,7 +45,7 @@ func TestXAxisGetTicksWithUserDefaults(t *testing.T) { } vf := FloatValueFormatter ticks := xa.GetTicks(r, xr, styleDefaults, vf) - assert.Len(ticks, 1) + assert.Len(1, ticks) } func TestXAxisMeasure(t *testing.T) { diff --git a/yaxis_test.go b/yaxis_test.go index 9b903ba..938ccc8 100644 --- a/yaxis_test.go +++ b/yaxis_test.go @@ -23,7 +23,7 @@ func TestYAxisGetTicks(t *testing.T) { } vf := FloatValueFormatter ticks := ya.GetTicks(r, yr, styleDefaults, vf) - assert.Len(ticks, 32) + assert.Len(32, ticks) } func TestYAxisGetTicksWithUserDefaults(t *testing.T) { @@ -45,7 +45,7 @@ func TestYAxisGetTicksWithUserDefaults(t *testing.T) { } vf := FloatValueFormatter ticks := ya.GetTicks(r, yr, styleDefaults, vf) - assert.Len(ticks, 1) + assert.Len(1, ticks) } func TestYAxisMeasure(t *testing.T) {