Skip to content

Commit 32371ba

Browse files
authored
Increase stat code cov (#306)
* Increase stat code cov * Rebase, other changes, hopefully fix circleCI
1 parent 1497ca3 commit 32371ba

File tree

1 file changed

+92
-8
lines changed

1 file changed

+92
-8
lines changed

source/mir/math/stat.d

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ unittest
544544
}
545545

546546
version(mir_test)
547-
@safe pure @nogc nothrow
547+
@safe pure nothrow @nogc
548548
unittest
549549
{
550550
import mir.ndslice.slice: sliced;
@@ -816,7 +816,7 @@ unittest
816816

817817
/// Arbitrary harmonic mean
818818
version(mir_test)
819-
@safe pure @nogc nothrow
819+
@safe pure nothrow @nogc
820820
unittest
821821
{
822822
import mir.math.common: approxEqual;
@@ -830,7 +830,7 @@ unittest
830830
}
831831

832832
version(mir_test)
833-
@safe pure @nogc nothrow
833+
@safe pure nothrow @nogc
834834
unittest
835835
{
836836
import mir.math.common: approxEqual;
@@ -860,7 +860,7 @@ F nthroot(F)(in F x, in size_t n)
860860
}
861861

862862
version(mir_test)
863-
@safe @nogc pure nothrow
863+
@safe pure nothrow @nogc
864864
unittest
865865
{
866866
import mir.math.common: approxEqual;
@@ -1221,7 +1221,7 @@ unittest
12211221
}
12221222

12231223
version(mir_test)
1224-
@safe pure @nogc nothrow
1224+
@safe pure nothrow @nogc
12251225
unittest
12261226
{
12271227
import mir.ndslice.slice: sliced;
@@ -1259,7 +1259,8 @@ template median(F, bool allowModify = false)
12591259
Params:
12601260
slice = slice
12611261
+/
1262-
meanType!F median(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind) slice) @nogc
1262+
@nogc
1263+
meanType!F median(Iterator, size_t N, SliceKind kind)(Slice!(Iterator, N, kind) slice)
12631264
{
12641265
static assert (!allowModify ||
12651266
isMutable!(slice.DeepElement),
@@ -1436,6 +1437,23 @@ unittest
14361437
assert(x.sliced.median == 2);
14371438
}
14381439

1440+
// withAsSlice test
1441+
version(mir_test)
1442+
@safe pure nothrow @nogc
1443+
unittest
1444+
{
1445+
import mir.math.common: approxEqual;
1446+
import mir.rc.array: RCArray;
1447+
1448+
static immutable a = [9.0, 1, 0, 2, 3, 4, 6, 8, 7, 10, 5];
1449+
1450+
auto x = RCArray!double(11);
1451+
foreach(i, ref e; x)
1452+
e = a[i];
1453+
1454+
assert(x.median.approxEqual(5));
1455+
}
1456+
14391457
/++
14401458
For integral slices, can pass output type as template parameter to ensure output
14411459
type is correct
@@ -1775,6 +1793,38 @@ unittest
17751793
assert(x.center.standardDeviation!"assumeZeroMean".approxEqual(x.standardDeviation));
17761794
}
17771795

1796+
// dynamic array test
1797+
version(mir_test)
1798+
@safe pure nothrow
1799+
unittest
1800+
{
1801+
import mir.algorithm.iteration: all;
1802+
import mir.math.common: approxEqual;
1803+
1804+
double[] x = [1.0, 2, 3, 4, 5, 6];
1805+
1806+
assert(x.center.all!approxEqual([-2.5, -1.5, -0.5, 0.5, 1.5, 2.5]));
1807+
}
1808+
1809+
// withAsSlice test
1810+
version(mir_test)
1811+
@safe pure nothrow @nogc
1812+
unittest
1813+
{
1814+
import mir.algorithm.iteration: all;
1815+
import mir.math.common: approxEqual;
1816+
import mir.rc.array: RCArray;
1817+
1818+
static immutable a = [1.0, 2, 3, 4, 5, 6];
1819+
static immutable result = [-2.5, -1.5, -0.5, 0.5, 1.5, 2.5];
1820+
1821+
auto x = RCArray!double(6);
1822+
foreach(i, ref e; x)
1823+
e = a[i];
1824+
1825+
assert(x.center.all!approxEqual(result));
1826+
}
1827+
17781828
/++
17791829
Output range that applies function `fun` to each input before summing
17801830
+/
@@ -1836,7 +1886,7 @@ unittest
18361886
}
18371887

18381888
version(mir_test)
1839-
@safe pure @nogc nothrow
1889+
@safe pure nothrow @nogc
18401890
unittest
18411891
{
18421892
import mir.ndslice.slice: sliced;
@@ -2317,6 +2367,40 @@ unittest
23172367
assert(v.variance(PopulationFalseCT).approxEqual(54.76562 / 11));
23182368
}
23192369

2370+
// dynamic array test
2371+
version(mir_test)
2372+
@safe pure nothrow
2373+
unittest
2374+
{
2375+
import mir.math.common: approxEqual;
2376+
import mir.rc.array: RCArray;
2377+
2378+
double[] x = [0.0, 1.0, 1.5, 2.0, 3.5, 4.25,
2379+
2.0, 7.5, 5.0, 1.0, 1.5, 0.0];
2380+
2381+
auto v = VarianceAccumulator!(double, VarianceAlgo.twoPass, Summation.naive)(x);
2382+
assert(v.centeredSumOfSquares.sum.approxEqual(54.76562));
2383+
}
2384+
2385+
// withAsSlice test
2386+
version(mir_test)
2387+
@safe pure nothrow @nogc
2388+
unittest
2389+
{
2390+
import mir.math.common: approxEqual;
2391+
import mir.rc.array: RCArray;
2392+
2393+
static immutable a = [0.0, 1.0, 1.5, 2.0, 3.5, 4.25,
2394+
2.0, 7.5, 5.0, 1.0, 1.5, 0.0];
2395+
2396+
auto x = RCArray!double(12);
2397+
foreach(i, ref e; x)
2398+
e = a[i];
2399+
2400+
auto v = VarianceAccumulator!(double, VarianceAlgo.twoPass, Summation.naive)(x);
2401+
assert(v.centeredSumOfSquares.sum.approxEqual(54.76562));
2402+
}
2403+
23202404
///
23212405
struct VarianceAccumulator(T, VarianceAlgo varianceAlgo, Summation summation)
23222406
if (isMutable!T && varianceAlgo == VarianceAlgo.assumeZeroMean)
@@ -2872,7 +2956,7 @@ unittest
28722956
}
28732957

28742958
version(mir_test)
2875-
@safe pure @nogc nothrow
2959+
@safe pure nothrow @nogc
28762960
unittest
28772961
{
28782962
import mir.ndslice.slice: sliced;

0 commit comments

Comments
 (0)