Skip to content

Commit

Permalink
unit-test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Aug 26, 2023
1 parent 6349ae2 commit 47308a2
Show file tree
Hide file tree
Showing 74 changed files with 1,225 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/pkg/bifs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ func BIF_mean(collection *mlrval.Mlrval) *mlrval.Mlrval {
return value_if_not
}
n := BIF_count(collection)
if n.AcquireIntValue() == 0 {
return mlrval.VOID
}
sum := BIF_sum(collection)
return BIF_divide(sum, n)
}
Expand Down Expand Up @@ -595,6 +598,8 @@ func bif_percentiles(
p, ok := ps[i].GetNumericToFloatValue()
if !ok {
outputs[i] = mlrval.ERROR.Copy()
} else if len(sorted_array) == 0{
outputs[i] = mlrval.VOID
} else {
if interpolate_linearly {
outputs[i] = GetPercentileLinearlyInterpolated(sorted_array, len(sorted_array), p)
Expand All @@ -619,5 +624,9 @@ func bif_percentiles(
// ================================================================
// TODO:
// * mode & antimode ... doing strings ... :|
// * mode ties are non-deterministic ... fix that ...
// * olh: min/max recurse but other stats funcs do not
// * behavior of moments w/ too-short data
// * percentile panics? any panics?

// * also: str contains ... but extend to arrays? or nah?
1 change: 1 addition & 0 deletions test/cases/dsl-stats/count/various/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr -n --ofmtf 6 --xtab put -f ${CASEDIR}/mlr
Empty file.
20 changes: 20 additions & 0 deletions test/cases/dsl-stats/count/various/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
count_0 (error)
count_0_type error
count_null (error)
count_null_type error
count_empty_array 0
count_empty_array_type int
count_array_1 1
count_array_1_type int
count_array_3 3
count_array_3_type int
count_array_nested 3
count_array_nested_type int
count_empty_map 0
count_empty_map_type int
count_map_1 1
count_map_1_type int
count_map_3 3
count_map_3_type int
count_map_nested 3
count_map_nested_type int
26 changes: 26 additions & 0 deletions test/cases/dsl-stats/count/various/mlr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
end {
outputs = {};

outputs["count_0"] = count(0);
outputs["count_null"] = count(null);
outputs["count_nonesuch"] = count(nonesuch);

outputs["count_empty_array"] = count([]);
outputs["count_array_1"] = count([7]);
outputs["count_array_3"] = count([7,8,9]);
outputs["count_array_nested"] = count([7,[80,90],9]);

outputs["count_empty_map"] = count({});
outputs["count_map_1"] = count({ "a" : 7} );
outputs["count_map_3"] = count({ "a" : 7, "b" : 8, "c" : 9 } );
outputs["count_map_nested"] = count({ "a" : 7, "b" : [80,90], "c" : 9 });

typed_outputs = {};

for (k, v in outputs) {
typed_outputs[k] = v;
typed_outputs[k."_type"] = typeof(v);
}

emit typed_outputs;
}
1 change: 1 addition & 0 deletions test/cases/dsl-stats/distinct_count/various/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr -n --ofmtf 6 --xtab put -f ${CASEDIR}/mlr
Empty file.
32 changes: 32 additions & 0 deletions test/cases/dsl-stats/distinct_count/various/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
distinct_count_0 (error)
distinct_count_0_type error
distinct_count_null (error)
distinct_count_null_type error
distinct_count_empty_array 0
distinct_count_empty_array_type int
distinct_count_array_1 1
distinct_count_array_1_type int
distinct_count_array_3a 3
distinct_count_array_3a_type int
distinct_count_array_3b 2
distinct_count_array_3b_type int
distinct_count_array_3c 1
distinct_count_array_3c_type int
distinct_count_array_3d 1
distinct_count_array_3d_type int
distinct_count_array_nested 2
distinct_count_array_nested_type int
distinct_count_empty_map 0
distinct_count_empty_map_type int
distinct_count_map_1 1
distinct_count_map_1_type int
distinct_count_map_3a 3
distinct_count_map_3a_type int
distinct_count_map_3b 2
distinct_count_map_3b_type int
distinct_count_map_3c 1
distinct_count_map_3c_type int
distinct_count_map_3d 1
distinct_count_map_3d_type int
distinct_count_map_nested 2
distinct_count_map_nested_type int
32 changes: 32 additions & 0 deletions test/cases/dsl-stats/distinct_count/various/mlr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
end {
outputs = {};

outputs["distinct_count_0"] = distinct_count(0);
outputs["distinct_count_null"] = distinct_count(null);
outputs["distinct_count_nonesuch"] = distinct_count(nonesuch);

outputs["distinct_count_empty_array"] = distinct_count([]);
outputs["distinct_count_array_1"] = distinct_count([7]);
outputs["distinct_count_array_3a"] = distinct_count([7,8,9]);
outputs["distinct_count_array_3b"] = distinct_count([7,7,9]);
outputs["distinct_count_array_3c"] = distinct_count([7,7,7]);
outputs["distinct_count_array_3d"] = distinct_count([null,null,null]);
outputs["distinct_count_array_nested"] = distinct_count([7,[7],7]);

outputs["distinct_count_empty_map"] = distinct_count({});
outputs["distinct_count_map_1"] = distinct_count({ "a" : 7} );
outputs["distinct_count_map_3a"] = distinct_count({ "a" : 7, "b" : 8, "c" : 9 } );
outputs["distinct_count_map_3b"] = distinct_count({ "a" : 7, "b" : 7, "c" : 9 } );
outputs["distinct_count_map_3c"] = distinct_count({ "a" : 7, "b" : 7, "c" : 7 } );
outputs["distinct_count_map_3d"] = distinct_count({ "a" : null, "b" : null, "c" : null } );
outputs["distinct_count_map_nested"] = distinct_count({ "a" : 7, "b" : [7], "c" : 7 });

typed_outputs = {};

for (k, v in outputs) {
typed_outputs[k] = v;
typed_outputs[k."_type"] = typeof(v);
}

emit typed_outputs;
}
1 change: 1 addition & 0 deletions test/cases/dsl-stats/mode/various/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr -n --ofmtf 6 --xtab put -f ${CASEDIR}/mlr
Empty file.
24 changes: 24 additions & 0 deletions test/cases/dsl-stats/mode/various/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
mode_0 (error)
mode_0_type error
mode_null (error)
mode_null_type error
mode_empty_array
mode_empty_array_type empty
mode_array_1 7
mode_array_1_type string
mode_array_3a 7
mode_array_3a_type string
mode_array_3b 7
mode_array_3b_type string
mode_array_nested 9
mode_array_nested_type string
mode_empty_map
mode_empty_map_type empty
mode_map_1 7
mode_map_1_type string
mode_map_3a 7
mode_map_3a_type string
mode_map_3b 7
mode_map_3b_type string
mode_map_nested 9
mode_map_nested_type string
28 changes: 28 additions & 0 deletions test/cases/dsl-stats/mode/various/mlr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
end {
outputs = {};

outputs["mode_0"] = mode(0);
outputs["mode_null"] = mode(null);
outputs["mode_nonesuch"] = mode(nonesuch);

outputs["mode_empty_array"] = mode([]);
outputs["mode_array_1"] = mode([7]);
outputs["mode_array_3a"] = mode([7,8,9]);
outputs["mode_array_3b"] = mode([7,8,7]);
outputs["mode_array_nested"] = mode([7,[8,8,8,8,8,8],9,9,9]);

outputs["mode_empty_map"] = mode({});
outputs["mode_map_1"] = mode({ "a" : 7} );
outputs["mode_map_3a"] = mode({ "a" : 7, "b" : 8, "c" : 9 } );
outputs["mode_map_3b"] = mode({ "a" : 7, "b" : 8, "c" : 7 } );
outputs["mode_map_nested"] = mode({ "a" : 7, "b" : [8,8,8,8,8,8], "c" : 9, "d": 9, "e": 9 });

typed_outputs = {};

for (k, v in outputs) {
typed_outputs[k] = v;
typed_outputs[k."_type"] = typeof(v);
}

emit typed_outputs;
}
1 change: 1 addition & 0 deletions test/cases/dsl-stats/moments/numeric-000/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmtf 6 --ojson --from test/input/abixy head -n 0 then put -q -f test/input/test-moments.mlr
Empty file.
26 changes: 26 additions & 0 deletions test/cases/dsl-stats/moments/numeric-000/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"a_count": 0,
"a_sum": 0,
"a_sum2": 0,
"a_sum3": 0,
"a_sum4": 0,
"a_mean": "",
"a_var": "",
"a_stddev": "",
"a_meaneb": "",
"a_skewness": "",
"a_kurtosis": "",
"m_count": 0,
"m_sum": 0,
"m_sum2": 0,
"m_sum3": 0,
"m_sum4": 0,
"m_mean": "",
"m_var": "",
"m_stddev": "",
"m_meaneb": "",
"m_skewness": "",
"m_kurtosis": ""
}
]
1 change: 1 addition & 0 deletions test/cases/dsl-stats/moments/numeric-001/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmtf 6 --ojson --from test/input/abixy head -n 1 then put -q -f test/input/test-moments.mlr
Empty file.
26 changes: 26 additions & 0 deletions test/cases/dsl-stats/moments/numeric-001/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"a_count": 1,
"a_sum": 1,
"a_sum2": 1,
"a_sum3": 1,
"a_sum4": 1,
"a_mean": 1,
"a_var": "",
"a_stddev": "",
"a_meaneb": "",
"a_skewness": "",
"a_kurtosis": "",
"m_count": 1,
"m_sum": 1,
"m_sum2": 1,
"m_sum3": 1,
"m_sum4": 1,
"m_mean": 1,
"m_var": "",
"m_stddev": "",
"m_meaneb": "",
"m_skewness": "",
"m_kurtosis": ""
}
]
1 change: 1 addition & 0 deletions test/cases/dsl-stats/moments/numeric-002/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmtf 6 --ojson --from test/input/abixy head -n 2 then put -q -f test/input/test-moments.mlr
Empty file.
26 changes: 26 additions & 0 deletions test/cases/dsl-stats/moments/numeric-002/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"a_count": 2,
"a_sum": 3,
"a_sum2": 5,
"a_sum3": 9,
"a_sum4": 17,
"a_mean": 1.500000,
"a_var": 0.500000,
"a_stddev": 0.707107,
"a_meaneb": 0.500000,
"a_skewness": 0.000000,
"a_kurtosis": -2.000000,
"m_count": 2,
"m_sum": 3,
"m_sum2": 5,
"m_sum3": 9,
"m_sum4": 17,
"m_mean": 1.500000,
"m_var": 0.500000,
"m_stddev": 0.707107,
"m_meaneb": 0.500000,
"m_skewness": 0.000000,
"m_kurtosis": -2.000000
}
]
1 change: 1 addition & 0 deletions test/cases/dsl-stats/moments/numeric-003/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmtf 6 --ojson --from test/input/abixy head -n 3 then put -q -f test/input/test-moments.mlr
Empty file.
26 changes: 26 additions & 0 deletions test/cases/dsl-stats/moments/numeric-003/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"a_count": 3,
"a_sum": 6,
"a_sum2": 14,
"a_sum3": 36,
"a_sum4": 98,
"a_mean": 2,
"a_var": 1.000000,
"a_stddev": 1.000000,
"a_meaneb": 0.577350,
"a_skewness": 0.000000,
"a_kurtosis": -1.500000,
"m_count": 3,
"m_sum": 6,
"m_sum2": 14,
"m_sum3": 36,
"m_sum4": 98,
"m_mean": 2,
"m_var": 1.000000,
"m_stddev": 1.000000,
"m_meaneb": 0.577350,
"m_skewness": 0.000000,
"m_kurtosis": -1.500000
}
]
1 change: 1 addition & 0 deletions test/cases/dsl-stats/moments/numeric-004/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmtf 6 --ojson --from test/input/abixy head -n 4 then put -q -f test/input/test-moments.mlr
Empty file.
26 changes: 26 additions & 0 deletions test/cases/dsl-stats/moments/numeric-004/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"a_count": 4,
"a_sum": 10,
"a_sum2": 30,
"a_sum3": 100,
"a_sum4": 354,
"a_mean": 2.500000,
"a_var": 1.666667,
"a_stddev": 1.290994,
"a_meaneb": 0.645497,
"a_skewness": 0.000000,
"a_kurtosis": -1.360000,
"m_count": 4,
"m_sum": 10,
"m_sum2": 30,
"m_sum3": 100,
"m_sum4": 354,
"m_mean": 2.500000,
"m_var": 1.666667,
"m_stddev": 1.290994,
"m_meaneb": 0.645497,
"m_skewness": 0.000000,
"m_kurtosis": -1.360000
}
]
1 change: 1 addition & 0 deletions test/cases/dsl-stats/moments/numeric-all/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --ofmtf 6 --ojson --from test/input/abixy put -q -f test/input/test-moments.mlr
Empty file.
26 changes: 26 additions & 0 deletions test/cases/dsl-stats/moments/numeric-all/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"a_count": 10,
"a_sum": 55,
"a_sum2": 385,
"a_sum3": 3025,
"a_sum4": 25333,
"a_mean": 5.500000,
"a_var": 9.166667,
"a_stddev": 3.027650,
"a_meaneb": 0.957427,
"a_skewness": 0.000000,
"a_kurtosis": -1.224242,
"m_count": 10,
"m_sum": 55,
"m_sum2": 385,
"m_sum3": 3025,
"m_sum4": 25333,
"m_mean": 5.500000,
"m_var": 9.166667,
"m_stddev": 3.027650,
"m_meaneb": 0.957427,
"m_skewness": 0.000000,
"m_kurtosis": -1.224242
}
]
1 change: 1 addition & 0 deletions test/cases/dsl-stats/null_count/various/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr -n --ofmtf 6 --xtab put -f ${CASEDIR}/mlr
Empty file.
20 changes: 20 additions & 0 deletions test/cases/dsl-stats/null_count/various/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
null_count_0 (error)
null_count_0_type error
null_count_null (error)
null_count_null_type error
null_count_empty_array 0
null_count_empty_array_type int
null_count_array_1 0
null_count_array_1_type int
null_count_array_2 0
null_count_array_2_type int
null_count_array_3 2
null_count_array_3_type int
null_count_empty_map 0
null_count_empty_map_type int
null_count_map_1 0
null_count_map_1_type int
null_count_map_2 0
null_count_map_2_type int
null_count_map_3 2
null_count_map_3_type int
Loading

0 comments on commit 47308a2

Please sign in to comment.