Upstream montanaflynn/stats state of the touched files before e61f9a13db
This commit is contained in:
1 parent
85d956c08c
commit
bc246e8d16
2 files changed
+7
-53
No files matched your search
+7
-26
@@ -32,20 +32,10 @@ func Quartile(input Float64Data) (Quartiles, error) {
|
|||||||
c2 = c1 + 1
|
c2 = c1 + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty halves make Median return ErrEmptyInput; propagate it instead of
|
// Find the Medians with the cutoff points
|
||||||
// returning NaN quartiles.
|
Q1, _ := Median(copy[:c1])
|
||||||
Q1, err := Median(copy[:c1])
|
Q2, _ := Median(copy)
|
||||||
if err != nil {
|
Q3, _ := Median(copy[c2:])
|
||||||
return Quartiles{}, err
|
|
||||||
}
|
|
||||||
Q2, err := Median(copy)
|
|
||||||
if err != nil {
|
|
||||||
return Quartiles{}, err
|
|
||||||
}
|
|
||||||
Q3, err := Median(copy[c2:])
|
|
||||||
if err != nil {
|
|
||||||
return Quartiles{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return Quartiles{Q1, Q2, Q3}, nil
|
return Quartiles{Q1, Q2, Q3}, nil
|
||||||
|
|
||||||
@@ -56,10 +46,7 @@ func InterQuartileRange(input Float64Data) (float64, error) {
|
|||||||
if input.Len() == 0 {
|
if input.Len() == 0 {
|
||||||
return math.NaN(), EmptyInputErr
|
return math.NaN(), EmptyInputErr
|
||||||
}
|
}
|
||||||
qs, err := Quartile(input)
|
qs, _ := Quartile(input)
|
||||||
if err != nil {
|
|
||||||
return math.NaN(), err
|
|
||||||
}
|
|
||||||
iqr := qs.Q3 - qs.Q1
|
iqr := qs.Q3 - qs.Q1
|
||||||
return iqr, nil
|
return iqr, nil
|
||||||
}
|
}
|
||||||
@@ -69,10 +56,7 @@ func Midhinge(input Float64Data) (float64, error) {
|
|||||||
if input.Len() == 0 {
|
if input.Len() == 0 {
|
||||||
return math.NaN(), EmptyInputErr
|
return math.NaN(), EmptyInputErr
|
||||||
}
|
}
|
||||||
qs, err := Quartile(input)
|
qs, _ := Quartile(input)
|
||||||
if err != nil {
|
|
||||||
return math.NaN(), err
|
|
||||||
}
|
|
||||||
mh := (qs.Q1 + qs.Q3) / 2
|
mh := (qs.Q1 + qs.Q3) / 2
|
||||||
return mh, nil
|
return mh, nil
|
||||||
}
|
}
|
||||||
@@ -84,10 +68,7 @@ func Trimean(input Float64Data) (float64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c := sortedCopy(input)
|
c := sortedCopy(input)
|
||||||
q, err := Quartile(c)
|
q, _ := Quartile(c)
|
||||||
if err != nil {
|
|
||||||
return math.NaN(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
return (q.Q1 + (q.Q2 * 2) + q.Q3) / 4, nil
|
return (q.Q1 + (q.Q2 * 2) + q.Q3) / 4, nil
|
||||||
}
|
}
|
||||||
@@ -41,18 +41,6 @@ func TestQuartile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuartileSingleElement(t *testing.T) {
|
|
||||||
// A single element has no halves, so Quartile must error rather than
|
|
||||||
// return NaN with a nil error.
|
|
||||||
quartiles, err := stats.Quartile([]float64{1})
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("Single element slice should have returned an error")
|
|
||||||
}
|
|
||||||
if quartiles != (stats.Quartiles{}) {
|
|
||||||
t.Errorf("Errored result should be the zero Quartiles value, got %+v", quartiles)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInterQuartileRange(t *testing.T) {
|
func TestInterQuartileRange(t *testing.T) {
|
||||||
s1 := []float64{102, 104, 105, 107, 108, 109, 110, 112, 115, 116, 118}
|
s1 := []float64{102, 104, 105, 107, 108, 109, 110, 112, 115, 116, 118}
|
||||||
iqr, _ := stats.InterQuartileRange(s1)
|
iqr, _ := stats.InterQuartileRange(s1)
|
||||||
@@ -65,11 +53,6 @@ func TestInterQuartileRange(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Empty slice should have returned an error")
|
t.Errorf("Empty slice should have returned an error")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stats.InterQuartileRange([]float64{1})
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("Single element slice should have returned an error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMidhinge(t *testing.T) {
|
func TestMidhinge(t *testing.T) {
|
||||||
@@ -84,11 +67,6 @@ func TestMidhinge(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Empty slice should have returned an error")
|
t.Errorf("Empty slice should have returned an error")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stats.Midhinge([]float64{1})
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("Single element slice should have returned an error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrimean(t *testing.T) {
|
func TestTrimean(t *testing.T) {
|
||||||
@@ -103,9 +81,4 @@ func TestTrimean(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Empty slice should have returned an error")
|
t.Errorf("Empty slice should have returned an error")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stats.Trimean([]float64{1})
|
|
||||||
if err == nil {
|
|
||||||
t.Errorf("Single element slice should have returned an error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user