sheet-historical-data-conve.../exchangeUtility/AggregateDailyToMonthly_test.go

181 lines
3.5 KiB
Go
Raw Permalink Normal View History

2024-11-05 19:59:23 +00:00
package exchangeUtility
import "testing"
func TestMeanMedian_GetMinValue(t *testing.T) {
tables := []struct {
AggregateDailyToMonthly
min float64
}{
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
13, 7, 11, 27, 3,
},
}, 3},
}
for _, table := range tables {
result := table.GetMinValue()
if result != table.min {
t.Errorf("GetMinValue() returned (%v) an incorrect response, supposed to be %v.", result, table.min)
}
}
}
func TestMeanMedian_GetMaxValue(t *testing.T) {
tables := []struct {
AggregateDailyToMonthly
max float64
}{
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
13, 7, 11, 27, 3,
},
}, 27},
}
for _, table := range tables {
result := table.GetMaxValue()
if result != table.max {
t.Errorf("GetMaxValue() returned (%v) an incorrect response, supposed to be %v.", result, table.max)
}
}
}
func TestMeanMedian_CalcRangeValues(t *testing.T) {
tables := []struct {
AggregateDailyToMonthly
r float64
}{
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
3, 4, 2, 6,
},
}, 4},
}
for _, table := range tables {
result := table.CalcRangeValues()
if result != table.r {
t.Errorf("CalcRangeValues() returned (%v) an incorrect response, supposed to be %v.", result, table.r)
}
}
}
func TestMeanMedian_CalcMean(t *testing.T) {
tables := []struct {
AggregateDailyToMonthly
r float64
}{
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
4, 4, 2, 2,
},
}, 3},
}
for _, table := range tables {
result := table.CalcMean()
if result != table.r {
t.Errorf("CalcMean() returned (%v) an incorrect response, supposed to be %v.", result, table.r)
}
}
}
func TestMeanMedian_CalcMode(t *testing.T) {
tables := []struct {
AggregateDailyToMonthly
r float64
}{
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
4, 3, 2, 2, 2,
},
}, 2},
}
for _, table := range tables {
result := table.CalcMode()
if result != table.r {
t.Errorf("CalcMode() returned (%v) an incorrect response, supposed to be %v.", result, table.r)
}
}
}
func TestMeanMedian_CalcMedianOdd(t *testing.T) {
tables := []struct {
AggregateDailyToMonthly
r float64
}{
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
3, 4, 2, 6, 5,
},
}, 4},
}
for _, table := range tables {
result := table.CalcMedian()
if result != table.r {
t.Errorf("CalcMedian() (with odd) returned (%v) an incorrect response, supposed to be %v.", result, table.r)
}
}
}
func TestMeanMedian_CalcMedianEven(t *testing.T) {
tables := []struct {
AggregateDailyToMonthly
r float64
}{
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
3, 4, 2, 6,
},
}, 3.5},
}
for _, table := range tables {
result := table.CalcMedian()
if result != table.r {
t.Errorf("CalcMedian() (with even) returned (%v) an incorrect response, supposed to be %v.", result, table.r)
}
}
}
func TestMeanMedian_IsOdd(t *testing.T) {
tables := []struct {
AggregateDailyToMonthly
r bool
}{
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
1, 2,
},
}, false},
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
1, 1, 1, 4,
},
}, false},
{AggregateDailyToMonthly{
AggregatedNumbers: []float64{
1, 1, 1, 1, 5,
},
}, true},
}
for _, table := range tables {
result := table.IsOdd()
if result != table.r {
t.Errorf("isOdd() returned (%v) an incorrect response: %v, supposed to be %v.", result, table.AggregateDailyToMonthly.AggregatedNumbers, table.r)
}
}
}