Skip to content

Commit 6698c01

Browse files
committed
relax check that enforced that inpur sequences were not empty
1 parent bdb225d commit 6698c01

6 files changed

Lines changed: 14 additions & 54 deletions

File tree

LinqStatistics/EnumerableStatsBinCount.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public static int BinCountSturges<T>(this IEnumerable<T> source)
1717
if (source == null)
1818
throw new ArgumentNullException("source");
1919

20-
if (!source.Any())
21-
throw new InvalidOperationException("source sequence contains no elements");
22-
2320
return (int)Math.Round(Math.Log(source.Count(), 2) + 1, 0);
2421
}
2522

@@ -34,9 +31,6 @@ public static int BinCountSquareRoot<T>(this IEnumerable<T> source)
3431
if (source == null)
3532
throw new ArgumentNullException("source");
3633

37-
if (!source.Any())
38-
throw new InvalidOperationException("source sequence contains no elements");
39-
4034
return (int)Math.Round(Math.Sqrt(source.Count()), 0);
4135
}
4236

@@ -50,9 +44,6 @@ public static int BinCountRice<T>(this IEnumerable<T> source)
5044
{
5145
if (source == null)
5246
throw new ArgumentNullException("source");
53-
54-
if (!source.Any())
55-
throw new InvalidOperationException("source sequence contains no elements");
5647

5748
return (int)Math.Round(2.0 * Math.Pow(source.Count(), 1.0 / 3.0), 0);
5849
}

LinqStatistics/EnumerableStatsCountEach.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ public static IEnumerable<ItemCount<T>> CountEach<T>(this IEnumerable<T> source,
2121
if (comparer == null)
2222
throw new ArgumentNullException("comparer");
2323

24-
if (!source.Any())
25-
throw new InvalidOperationException("source sequence contains no elements");
26-
2724
return source.GroupBy(t => t, comparer).OrderBy(g => g.Key).Select(g => new ItemCount<T>(g.Key, g.Count()));
2825
}
2926

LinqStatistics/EnumerableStatsKurtosis.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -467,23 +467,4 @@ public static double Kurtosis<TSource>(this IEnumerable<TSource> source, Func<TS
467467
return source.Select(selector).Kurtosis();
468468
}
469469
}
470-
}
471-
// a single pass implementation
472-
//double M1 = 0, M2 = 0, M3 = 0, M4 = 0;
473-
474-
//int n = 0;
475-
//foreach (var x in source)
476-
//{
477-
// int n1 = n;
478-
// n++;
479-
// double delta = x - M1;
480-
// double delta_n = delta / n;
481-
// double delta_n2 = delta_n * delta_n;
482-
// double term1 = delta * delta_n * n1;
483-
// M1 += delta_n;
484-
// M4 += term1 * delta_n2 * (n * n - 3 * n + 3) + 6 * delta_n2 * M2 - 4 * delta_n * M3;
485-
// M3 += term1 * delta_n * (n - 2) - 3 * delta_n * M2;
486-
// M2 += term1;
487-
//}
488-
489-
//return n * M4 / (M2 * M2) - 3.0;
470+
}

LinqStatistics/EnumerableStatsKurtosis.tt

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,4 @@ namespace LinqStatistics
120120
}
121121
<# } #>
122122
}
123-
}
124-
// a single pass implementation
125-
//double M1 = 0, M2 = 0, M3 = 0, M4 = 0;
126-
127-
//int n = 0;
128-
//foreach (var x in source)
129-
//{
130-
// int n1 = n;
131-
// n++;
132-
// double delta = x - M1;
133-
// double delta_n = delta / n;
134-
// double delta_n2 = delta_n * delta_n;
135-
// double term1 = delta * delta_n * n1;
136-
// M1 += delta_n;
137-
// M4 += term1 * delta_n2 * (n * n - 3 * n + 3) + 6 * delta_n2 * M2 - 4 * delta_n * M3;
138-
// M3 += term1 * delta_n * (n - 2) - 3 * delta_n * M2;
139-
// M2 += term1;
140-
//}
141-
142-
//return n * M4 / (M2 * M2) - 3.0;
123+
}

LinqStatistics/Range.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ public override int GetHashCode()
195195
}
196196

197197
/// <summary>
198-
/// Returns the fully qualified type name of this instance.
198+
/// Returns a string representation of the range
199199
/// </summary>
200200
/// <returns>
201-
/// A <see cref="T:System.String"/> containing a fully qualified type name.
201+
/// A <see cref="T:System.String"/> representation of the range
202202
/// </returns>
203203
public override string ToString()
204204
{

LinqStatisticsTests/HistogramTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ namespace LinqStatistics.UnitTests
1010
[TestClass]
1111
public class HistogramTests
1212
{
13+
[TestMethod]
14+
public void CounEachEmpty()
15+
{
16+
var list = new List<int>();
17+
18+
var counts = list.CountEach();
19+
20+
Assert.IsFalse(counts.Any());
21+
}
22+
1323
[TestMethod]
1424
public void CounEachIntegers()
1525
{

0 commit comments

Comments
 (0)