mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 00:38:47 +00:00
Move IEnumerable.Product tests to Linq namespace (#7)
This commit is contained in:
parent
d5a74c12a8
commit
6a1f64f042
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow((byte)0, (byte)1)]
|
||||
[DataRow((byte)2, (byte)3, (byte)4)]
|
||||
[DataRow((byte)1, (byte)2, (byte)3, (byte)4, (byte)5, (byte)6, (byte)7, (byte)8, (byte)9, (byte)10)] // 10!
|
||||
public void ProductByte_Fixed(params byte[] source)
|
||||
{
|
||||
byte expected = 1;
|
||||
foreach (byte item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
byte actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow((byte)0, (byte)1)]
|
||||
[DataRow((byte)2, (byte)3, (byte)4)]
|
||||
[DataRow((byte)1, (byte)2, (byte)3, (byte)4, (byte)5, (byte)6, (byte)7, (byte)8, (byte)9, (byte)10)] // 10!
|
||||
public void ProductByte_Transformed_Fixed(params byte[] source)
|
||||
{
|
||||
byte expected = 1;
|
||||
foreach (byte item in source)
|
||||
{
|
||||
expected *= (byte)(item * 2);
|
||||
}
|
||||
|
||||
byte actual = source.Product(n => (byte)(n * 2));
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductByte_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new byte[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (byte)random.Next(1, 100);
|
||||
}
|
||||
|
||||
byte expected = 1;
|
||||
foreach (byte item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
byte actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductByte_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new byte[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (byte)random.Next(1, 100);
|
||||
}
|
||||
|
||||
byte expected = 1;
|
||||
foreach (byte item in source)
|
||||
{
|
||||
expected *= (byte)(item * 2);
|
||||
}
|
||||
|
||||
byte actual = source.Product(n => (byte)(n * 2));
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
// the Fixed methods in these tests can't use DataRow attribute because the use of a decimal literal compiles to an
|
||||
// instantiation of the decimal struct, which is not a compile-time constant expression.
|
||||
// thanks. I fucking hate it.
|
||||
|
||||
[TestMethod]
|
||||
public void ProductDecimal_Fixed()
|
||||
{
|
||||
{
|
||||
var source = new[] {0m, 1m};
|
||||
var expected = 1m;
|
||||
foreach (decimal item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
decimal actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
{
|
||||
|
||||
var source = new[] {2m, 3m, 4m};
|
||||
var expected = 1m;
|
||||
foreach (decimal item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
decimal actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
{
|
||||
|
||||
var source = new[] {1m, 2m, 3m, 4m, 5m, 6m, 7m, 8m, 9m, 10m};
|
||||
var expected = 1m;
|
||||
foreach (decimal item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
decimal actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductDecimal_Transformed_Fixed()
|
||||
{
|
||||
{
|
||||
var source = new[] {0m, 1m};
|
||||
var expected = 1m;
|
||||
foreach (decimal item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
decimal actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
{
|
||||
var source = new[] {2m, 3m, 4m};
|
||||
var expected = 1m;
|
||||
foreach (decimal item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
decimal actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
{
|
||||
var source = new[] {1m, 2m, 3m, 4m, 5m, 6m, 7m, 8m, 9m, 10m};
|
||||
var expected = 1m;
|
||||
foreach (decimal item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
decimal actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductDecimal_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new decimal[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (decimal)random.NextDouble();
|
||||
}
|
||||
|
||||
var expected = 1m;
|
||||
foreach (decimal item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
decimal actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductDecimal_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new decimal[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (decimal)random.NextDouble();
|
||||
}
|
||||
|
||||
var expected = 1m;
|
||||
foreach (decimal item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
decimal actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(0.0, 1.0)]
|
||||
[DataRow(2.0, 3.0, 4.0)]
|
||||
[DataRow(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)] // 10!
|
||||
public void ProductDouble_Fixed(params double[] source)
|
||||
{
|
||||
var expected = 1.0;
|
||||
foreach (double item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
double actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0.0, 1.0)]
|
||||
[DataRow(2.0, 3.0, 4.0)]
|
||||
[DataRow(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)] // 10!
|
||||
public void ProductDouble_Transformed_Fixed(params double[] source)
|
||||
{
|
||||
var expected = 1.0;
|
||||
foreach (double item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
double actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductDouble_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new double[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = random.NextDouble();
|
||||
}
|
||||
|
||||
var expected = 1.0;
|
||||
foreach (double item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
double actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductDouble_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new double[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = random.NextDouble();
|
||||
}
|
||||
|
||||
var expected = 1.0;
|
||||
foreach (double item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
double actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow((short)0, (short)1)]
|
||||
[DataRow((short)2, (short)3, (short)4)]
|
||||
[DataRow((short)1, (short)2, (short)3, (short)4, (short)5, (short)6, (short)7, (short)8, (short)9, (short)10)] // 10!
|
||||
public void ProductInt16_Fixed(params short[] source)
|
||||
{
|
||||
short expected = 1;
|
||||
foreach (short item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
short actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow((short)0, (short)1)]
|
||||
[DataRow((short)2, (short)3, (short)4)]
|
||||
[DataRow((short)1, (short)2, (short)3, (short)4, (short)5, (short)6, (short)7, (short)8, (short)9, (short)10)] // 10!
|
||||
public void ProductInt16_Transformed_Fixed(params short[] source)
|
||||
{
|
||||
short expected = 1;
|
||||
foreach (short item in source)
|
||||
{
|
||||
expected *= (short)(item * 2);
|
||||
}
|
||||
|
||||
short actual = source.Product(n => (short)(n * 2));
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductInt16_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new short[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (short)random.Next(1, 100);
|
||||
}
|
||||
|
||||
short expected = 1;
|
||||
foreach (short item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
short actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductInt16_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new short[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (short)random.Next(1, 100);
|
||||
}
|
||||
|
||||
short expected = 1;
|
||||
foreach (short item in source)
|
||||
{
|
||||
expected *= (short)(item * 2);
|
||||
}
|
||||
|
||||
short actual = source.Product(n => (short)(n * 2));
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(0, 1)]
|
||||
[DataRow(2, 3, 4)]
|
||||
[DataRow(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)] // 10!
|
||||
public void ProductInt32_Fixed(params int[] source)
|
||||
{
|
||||
var expected = 1;
|
||||
foreach (int item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
int actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0, 1)]
|
||||
[DataRow(2, 3, 4)]
|
||||
[DataRow(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)] // 10!
|
||||
public void ProductInt32_Transformed_Fixed(params int[] source)
|
||||
{
|
||||
var expected = 1;
|
||||
foreach (int item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
int actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductInt32_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new int[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = random.Next(1, 100);
|
||||
}
|
||||
|
||||
var expected = 1;
|
||||
foreach (int item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
int actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductInt32_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new int[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = random.Next(1, 100);
|
||||
}
|
||||
|
||||
var expected = 1;
|
||||
foreach (int item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
int actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(0L, 1L)]
|
||||
[DataRow(2L, 3L, 4L)]
|
||||
[DataRow(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)] // 10!
|
||||
public void ProductInt64_Fixed(params long[] source)
|
||||
{
|
||||
var expected = 1L;
|
||||
foreach (long item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
long actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0L, 1L)]
|
||||
[DataRow(2L, 3L, 4L)]
|
||||
[DataRow(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)] // 10!
|
||||
public void ProductInt64_Transformed_Fixed(params long[] source)
|
||||
{
|
||||
var expected = 1L;
|
||||
foreach (long item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
long actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductInt64_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new long[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = random.NextInt64(1, 100);
|
||||
}
|
||||
|
||||
var expected = 1L;
|
||||
foreach (long item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
long actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductInt64_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new long[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = random.NextInt64(1, 100);
|
||||
}
|
||||
|
||||
var expected = 1L;
|
||||
foreach (long item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
long actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow((sbyte)0, (sbyte)1)]
|
||||
[DataRow((sbyte)2, (sbyte)3, (sbyte)4)]
|
||||
[DataRow((sbyte)1, (sbyte)2, (sbyte)3, (sbyte)4, (sbyte)5, (sbyte)6, (sbyte)7, (sbyte)8, (sbyte)9, (sbyte)10)] // 10!
|
||||
public void ProductSByte_Fixed(params sbyte[] source)
|
||||
{
|
||||
sbyte expected = 1;
|
||||
foreach (sbyte item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
sbyte actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow((sbyte)0, (sbyte)1)]
|
||||
[DataRow((sbyte)2, (sbyte)3, (sbyte)4)]
|
||||
[DataRow((sbyte)1, (sbyte)2, (sbyte)3, (sbyte)4, (sbyte)5, (sbyte)6, (sbyte)7, (sbyte)8, (sbyte)9, (sbyte)10)] // 10!
|
||||
public void ProductSByte_Transformed_Fixed(params sbyte[] source)
|
||||
{
|
||||
sbyte expected = 1;
|
||||
foreach (sbyte item in source)
|
||||
{
|
||||
expected *= (sbyte)(item * 2);
|
||||
}
|
||||
|
||||
sbyte actual = source.Product(n => (sbyte)(n * 2));
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductSByte_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new sbyte[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (sbyte)random.Next(1, 100);
|
||||
}
|
||||
|
||||
sbyte expected = 1;
|
||||
foreach (sbyte item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
sbyte actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductSByte_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new sbyte[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (sbyte)random.Next(1, 100);
|
||||
}
|
||||
|
||||
sbyte expected = 1;
|
||||
foreach (sbyte item in source)
|
||||
{
|
||||
expected *= (sbyte)(item * 2);
|
||||
}
|
||||
|
||||
sbyte actual = source.Product(n => (sbyte)(n * 2));
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(0f, 1f)]
|
||||
[DataRow(2f, 3f, 4f)]
|
||||
[DataRow(1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f)] // 10!
|
||||
public void ProductSingle_Fixed(params float[] source)
|
||||
{
|
||||
var expected = 1f;
|
||||
foreach (float item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
float actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0f, 1f)]
|
||||
[DataRow(2f, 3f, 4f)]
|
||||
[DataRow(1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f)] // 10!
|
||||
public void ProductSingle_Transformed_Fixed(params float[] source)
|
||||
{
|
||||
var expected = 1f;
|
||||
foreach (float item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
float actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductSingle_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new float[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (float)random.NextDouble();
|
||||
}
|
||||
|
||||
var expected = 1f;
|
||||
foreach (float item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
float actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductSingle_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new float[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (float)random.NextDouble();
|
||||
}
|
||||
|
||||
var expected = 1f;
|
||||
foreach (float item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
float actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow((ushort)0, (ushort)1)]
|
||||
[DataRow((ushort)2, (ushort)3, (ushort)4)]
|
||||
[DataRow((ushort)1, (ushort)2, (ushort)3, (ushort)4, (ushort)5, (ushort)6, (ushort)7, (ushort)8, (ushort)9, (ushort)10)] // 10!
|
||||
public void ProductUInt16_Fixed(params ushort[] source)
|
||||
{
|
||||
ushort expected = 1;
|
||||
foreach (ushort item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
ushort actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow((ushort)0, (ushort)1)]
|
||||
[DataRow((ushort)2, (ushort)3, (ushort)4)]
|
||||
[DataRow((ushort)1, (ushort)2, (ushort)3, (ushort)4, (ushort)5, (ushort)6, (ushort)7, (ushort)8, (ushort)9, (ushort)10)] // 10!
|
||||
public void ProductUInt16_Transformed_Fixed(params ushort[] source)
|
||||
{
|
||||
ushort expected = 1;
|
||||
foreach (ushort item in source)
|
||||
{
|
||||
expected *= (ushort)(item * 2);
|
||||
}
|
||||
|
||||
ushort actual = source.Product(n => (ushort)(n * 2));
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductUInt16_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new ushort[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (ushort)random.Next(1, 100);
|
||||
}
|
||||
|
||||
ushort expected = 1;
|
||||
foreach (ushort item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
ushort actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductUInt16_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new ushort[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (ushort)random.Next(1, 100);
|
||||
}
|
||||
|
||||
ushort expected = 1;
|
||||
foreach (ushort item in source)
|
||||
{
|
||||
expected *= (ushort)(item * 2);
|
||||
}
|
||||
|
||||
ushort actual = source.Product(n => (ushort)(n * 2));
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(0u, 1u)]
|
||||
[DataRow(2u, 3u, 4u)]
|
||||
[DataRow(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u)] // 10!
|
||||
public void ProductUInt32_Fixed(params uint[] source)
|
||||
{
|
||||
var expected = 1u;
|
||||
foreach (uint item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
uint actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0u, 1u)]
|
||||
[DataRow(2u, 3u, 4u)]
|
||||
[DataRow(1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u)] // 10!
|
||||
public void ProductUInt32_Transformed_Fixed(params uint[] source)
|
||||
{
|
||||
var expected = 1u;
|
||||
foreach (uint item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
uint actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductUInt32_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new uint[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (uint) random.Next(1, 100);
|
||||
}
|
||||
|
||||
var expected = 1u;
|
||||
foreach (uint item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
uint actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductUInt32_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new uint[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (uint) random.Next(1, 100);
|
||||
}
|
||||
|
||||
var expected = 1u;
|
||||
foreach (uint item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
uint actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
public partial class EnumerableTests
|
||||
{
|
||||
[TestMethod]
|
||||
[DataRow(0UL, 1UL)]
|
||||
[DataRow(2UL, 3UL, 4UL)]
|
||||
[DataRow(1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL, 8UL, 9UL, 10UL)] // 10!
|
||||
public void ProductUInt64_Fixed(params ulong[] source)
|
||||
{
|
||||
var expected = 1UL;
|
||||
foreach (ulong item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
ulong actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0UL, 1UL)]
|
||||
[DataRow(2UL, 3UL, 4UL)]
|
||||
[DataRow(1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL, 8UL, 9UL, 10UL)] // 10!
|
||||
public void ProductUInt64_Transformed_Fixed(params ulong[] source)
|
||||
{
|
||||
var expected = 1UL;
|
||||
foreach (ulong item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
ulong actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductUInt64_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new ulong[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (ulong) random.NextInt64(1, 100);
|
||||
}
|
||||
|
||||
var expected = 1UL;
|
||||
foreach (ulong item in source)
|
||||
{
|
||||
expected *= item;
|
||||
}
|
||||
|
||||
ulong actual = source.Product();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductUInt64_Transformed_Random1000()
|
||||
{
|
||||
var random = new Random();
|
||||
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var source = new ulong[10];
|
||||
for (var j = 0; j < source.Length; j++)
|
||||
{
|
||||
source[j] = (ulong) random.NextInt64(1, 100);
|
||||
}
|
||||
|
||||
var expected = 1UL;
|
||||
foreach (ulong item in source)
|
||||
{
|
||||
expected *= item * 2;
|
||||
}
|
||||
|
||||
ulong actual = source.Product(n => n * 2);
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
36
X10D.Tests/src/Linq/ByteTests.cs
Normal file
36
X10D.Tests/src/Linq/ByteTests.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
public class ByteTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
byte Cast(int i) => (byte)i;
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
|
||||
// 6! will overflow for byte
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
byte Double(int i) => (byte)(i * 2);
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double));
|
||||
|
||||
// Π_(i=1)^(n(i*2)) will overflow at i=4 for byte
|
||||
}
|
||||
}
|
44
X10D.Tests/src/Linq/DecimalTests.cs
Normal file
44
X10D.Tests/src/Linq/DecimalTests.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
public class DecimalTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
decimal Cast(int i) => i;
|
||||
|
||||
Assert.AreEqual(0m, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1m, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2m, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6m, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24m, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120m, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
Assert.AreEqual(720m, Enumerable.Range(1, 6).Select(Cast).Product());
|
||||
Assert.AreEqual(5040m, Enumerable.Range(1, 7).Select(Cast).Product());
|
||||
Assert.AreEqual(40320m, Enumerable.Range(1, 8).Select(Cast).Product());
|
||||
Assert.AreEqual(362880m, Enumerable.Range(1, 9).Select(Cast).Product());
|
||||
Assert.AreEqual(3628800m, Enumerable.Range(1, 10).Select(Cast).Product());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
decimal Double(int i) => i * 2m;
|
||||
|
||||
Assert.AreEqual(0m, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2m, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8m, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48m, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384m, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840m, Enumerable.Range(1, 5).Product(Double));
|
||||
Assert.AreEqual(46080m, Enumerable.Range(1, 6).Product(Double));
|
||||
Assert.AreEqual(645120m, Enumerable.Range(1, 7).Product(Double));
|
||||
Assert.AreEqual(10321920m, Enumerable.Range(1, 8).Product(Double));
|
||||
Assert.AreEqual(185794560m, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200m, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
}
|
44
X10D.Tests/src/Linq/DoubleTests.cs
Normal file
44
X10D.Tests/src/Linq/DoubleTests.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
public class DoubleTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
double Cast(int i) => i;
|
||||
|
||||
Assert.AreEqual(0.0, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1.0, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2.0, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6.0, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24.0, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120.0, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
Assert.AreEqual(720.0, Enumerable.Range(1, 6).Select(Cast).Product());
|
||||
Assert.AreEqual(5040.0, Enumerable.Range(1, 7).Select(Cast).Product());
|
||||
Assert.AreEqual(40320.0, Enumerable.Range(1, 8).Select(Cast).Product());
|
||||
Assert.AreEqual(362880.0, Enumerable.Range(1, 9).Select(Cast).Product());
|
||||
Assert.AreEqual(3628800.0, Enumerable.Range(1, 10).Select(Cast).Product());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
double Double(int i) => i * 2.0;
|
||||
|
||||
Assert.AreEqual(0.0, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2.0, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8.0, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48.0, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384.0, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840.0, Enumerable.Range(1, 5).Product(Double));
|
||||
Assert.AreEqual(46080.0, Enumerable.Range(1, 6).Product(Double));
|
||||
Assert.AreEqual(645120.0, Enumerable.Range(1, 7).Product(Double));
|
||||
Assert.AreEqual(10321920.0, Enumerable.Range(1, 8).Product(Double));
|
||||
Assert.AreEqual(185794560.0, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200.0, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
}
|
40
X10D.Tests/src/Linq/Int16Tests.cs
Normal file
40
X10D.Tests/src/Linq/Int16Tests.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
public class Int16Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
short Cast(int i) => (short)i;
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
Assert.AreEqual(720, Enumerable.Range(1, 6).Select(Cast).Product());
|
||||
Assert.AreEqual(5040, Enumerable.Range(1, 7).Select(Cast).Product());
|
||||
|
||||
// 8! will overflow for short
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
short Double(int i) => (short)(i * 2);
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840, Enumerable.Range(1, 5).Product(Double));
|
||||
|
||||
// Π_(i=1)^(n(i*2)) will overflow at i=6 for short
|
||||
}
|
||||
}
|
43
X10D.Tests/src/Linq/Int32Tests.cs
Normal file
43
X10D.Tests/src/Linq/Int32Tests.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
public class Int32Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Product());
|
||||
Assert.AreEqual(1, Enumerable.Range(1, 1).Product());
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 2).Product());
|
||||
Assert.AreEqual(6, Enumerable.Range(1, 3).Product());
|
||||
Assert.AreEqual(24, Enumerable.Range(1, 4).Product());
|
||||
Assert.AreEqual(120, Enumerable.Range(1, 5).Product());
|
||||
Assert.AreEqual(720, Enumerable.Range(1, 6).Product());
|
||||
Assert.AreEqual(5040, Enumerable.Range(1, 7).Product());
|
||||
Assert.AreEqual(40320, Enumerable.Range(1, 8).Product());
|
||||
Assert.AreEqual(362880, Enumerable.Range(1, 9).Product());
|
||||
Assert.AreEqual(3628800, Enumerable.Range(1, 10).Product());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
int Double(int i) => i * 2;
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840, Enumerable.Range(1, 5).Product(Double));
|
||||
Assert.AreEqual(46080, Enumerable.Range(1, 6).Product(Double));
|
||||
Assert.AreEqual(645120, Enumerable.Range(1, 7).Product(Double));
|
||||
Assert.AreEqual(10321920, Enumerable.Range(1, 8).Product(Double));
|
||||
Assert.AreEqual(185794560, Enumerable.Range(1, 9).Product(Double));
|
||||
|
||||
// Π_(i=1)^(n(i*2)) will overflow at i=10 for int
|
||||
}
|
||||
}
|
44
X10D.Tests/src/Linq/Int64Tests.cs
Normal file
44
X10D.Tests/src/Linq/Int64Tests.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
public class Int64Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
long Cast(int i) => i;
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
Assert.AreEqual(720, Enumerable.Range(1, 6).Select(Cast).Product());
|
||||
Assert.AreEqual(5040, Enumerable.Range(1, 7).Select(Cast).Product());
|
||||
Assert.AreEqual(40320, Enumerable.Range(1, 8).Select(Cast).Product());
|
||||
Assert.AreEqual(362880, Enumerable.Range(1, 9).Select(Cast).Product());
|
||||
Assert.AreEqual(3628800, Enumerable.Range(1, 10).Select(Cast).Product());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
long Double(int i) => i * 2;
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840, Enumerable.Range(1, 5).Product(Double));
|
||||
Assert.AreEqual(46080, Enumerable.Range(1, 6).Product(Double));
|
||||
Assert.AreEqual(645120, Enumerable.Range(1, 7).Product(Double));
|
||||
Assert.AreEqual(10321920, Enumerable.Range(1, 8).Product(Double));
|
||||
Assert.AreEqual(185794560, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
}
|
37
X10D.Tests/src/Linq/SByteExtensions.cs
Normal file
37
X10D.Tests/src/Linq/SByteExtensions.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
[CLSCompliant(false)]
|
||||
public class SByteTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
sbyte Cast(int i) => (sbyte)i;
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Product());
|
||||
Assert.AreEqual(1, Enumerable.Range(1, 1).Product());
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 2).Product());
|
||||
Assert.AreEqual(6, Enumerable.Range(1, 3).Product());
|
||||
Assert.AreEqual(24, Enumerable.Range(1, 4).Product());
|
||||
Assert.AreEqual(120, Enumerable.Range(1, 5).Product());
|
||||
|
||||
// 6! will overflow for sbyte
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
sbyte Double(int i) => (sbyte)(i * 2);
|
||||
|
||||
Assert.AreEqual(0, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48, Enumerable.Range(1, 3).Product(Double));
|
||||
|
||||
// Π_(i=1)^(n(i*2)) will overflow at i=4 for sbyte
|
||||
}
|
||||
}
|
44
X10D.Tests/src/Linq/SingleTests.cs
Normal file
44
X10D.Tests/src/Linq/SingleTests.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
public class SingleTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
float Cast(int i) => i;
|
||||
|
||||
Assert.AreEqual(0f, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1f, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2f, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6f, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24f, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120f, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
Assert.AreEqual(720f, Enumerable.Range(1, 6).Select(Cast).Product());
|
||||
Assert.AreEqual(5040f, Enumerable.Range(1, 7).Select(Cast).Product());
|
||||
Assert.AreEqual(40320f, Enumerable.Range(1, 8).Select(Cast).Product());
|
||||
Assert.AreEqual(362880f, Enumerable.Range(1, 9).Select(Cast).Product());
|
||||
Assert.AreEqual(3628800f, Enumerable.Range(1, 10).Select(Cast).Product());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
float Double(int i) => i * 2f;
|
||||
|
||||
Assert.AreEqual(0f, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2f, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8f, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48f, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384f, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840f, Enumerable.Range(1, 5).Product(Double));
|
||||
Assert.AreEqual(46080f, Enumerable.Range(1, 6).Product(Double));
|
||||
Assert.AreEqual(645120f, Enumerable.Range(1, 7).Product(Double));
|
||||
Assert.AreEqual(10321920f, Enumerable.Range(1, 8).Product(Double));
|
||||
Assert.AreEqual(185794560f, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200f, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
}
|
43
X10D.Tests/src/Linq/UInt16Tests.cs
Normal file
43
X10D.Tests/src/Linq/UInt16Tests.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
[CLSCompliant(false)]
|
||||
public class UInt16Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
ushort Cast(int i) => (ushort)i;
|
||||
|
||||
Assert.AreEqual(0U, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1U, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2U, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6U, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24U, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120U, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
Assert.AreEqual(720U, Enumerable.Range(1, 6).Select(Cast).Product());
|
||||
Assert.AreEqual(5040U, Enumerable.Range(1, 7).Select(Cast).Product());
|
||||
Assert.AreEqual(40320U, Enumerable.Range(1, 8).Select(Cast).Product());
|
||||
|
||||
// 9! will overflow for ushort
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
ushort Double(int i) => (ushort)(i * 2);
|
||||
|
||||
Assert.AreEqual(0U, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2U, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8U, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48U, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384U, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840U, Enumerable.Range(1, 5).Product(Double));
|
||||
Assert.AreEqual(46080U, Enumerable.Range(1, 6).Product(Double));
|
||||
|
||||
// Π_(i=1)^(n(i*2)) will overflow at i=7 for ushort
|
||||
}
|
||||
}
|
45
X10D.Tests/src/Linq/UInt32Tests.cs
Normal file
45
X10D.Tests/src/Linq/UInt32Tests.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
[CLSCompliant(false)]
|
||||
public class UInt32Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
ulong Cast(int i) => (ulong)i;
|
||||
|
||||
Assert.AreEqual(0U, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1U, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2U, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6U, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24U, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120U, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
Assert.AreEqual(720U, Enumerable.Range(1, 6).Select(Cast).Product());
|
||||
Assert.AreEqual(5040U, Enumerable.Range(1, 7).Select(Cast).Product());
|
||||
Assert.AreEqual(40320U, Enumerable.Range(1, 8).Select(Cast).Product());
|
||||
Assert.AreEqual(362880U, Enumerable.Range(1, 9).Select(Cast).Product());
|
||||
Assert.AreEqual(3628800U, Enumerable.Range(1, 10).Select(Cast).Product());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
uint Double(int i) => (uint)i * 2;
|
||||
|
||||
Assert.AreEqual(0U, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2U, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8U, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48U, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384U, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840U, Enumerable.Range(1, 5).Product(Double));
|
||||
Assert.AreEqual(46080U, Enumerable.Range(1, 6).Product(Double));
|
||||
Assert.AreEqual(645120U, Enumerable.Range(1, 7).Product(Double));
|
||||
Assert.AreEqual(10321920U, Enumerable.Range(1, 8).Product(Double));
|
||||
Assert.AreEqual(185794560U, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200U, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
}
|
45
X10D.Tests/src/Linq/UInt64Tests.cs
Normal file
45
X10D.Tests/src/Linq/UInt64Tests.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
|
||||
[TestClass]
|
||||
[CLSCompliant(false)]
|
||||
public class UInt64Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void ProductShouldBeCorrect()
|
||||
{
|
||||
ulong Cast(int i) => (ulong)i;
|
||||
|
||||
Assert.AreEqual(0UL, Enumerable.Range(0, 10).Select(Cast).Product());
|
||||
Assert.AreEqual(1UL, Enumerable.Range(1, 1).Select(Cast).Product());
|
||||
Assert.AreEqual(2UL, Enumerable.Range(1, 2).Select(Cast).Product());
|
||||
Assert.AreEqual(6UL, Enumerable.Range(1, 3).Select(Cast).Product());
|
||||
Assert.AreEqual(24UL, Enumerable.Range(1, 4).Select(Cast).Product());
|
||||
Assert.AreEqual(120UL, Enumerable.Range(1, 5).Select(Cast).Product());
|
||||
Assert.AreEqual(720UL, Enumerable.Range(1, 6).Select(Cast).Product());
|
||||
Assert.AreEqual(5040UL, Enumerable.Range(1, 7).Select(Cast).Product());
|
||||
Assert.AreEqual(40320UL, Enumerable.Range(1, 8).Select(Cast).Product());
|
||||
Assert.AreEqual(362880UL, Enumerable.Range(1, 9).Select(Cast).Product());
|
||||
Assert.AreEqual(3628800UL, Enumerable.Range(1, 10).Select(Cast).Product());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductOfDoublesShouldBeCorrect()
|
||||
{
|
||||
ulong Double(int i) => (ulong)i * 2;
|
||||
|
||||
Assert.AreEqual(0UL, Enumerable.Range(0, 10).Product(Double));
|
||||
Assert.AreEqual(2UL, Enumerable.Range(1, 1).Product(Double));
|
||||
Assert.AreEqual(8UL, Enumerable.Range(1, 2).Product(Double));
|
||||
Assert.AreEqual(48UL, Enumerable.Range(1, 3).Product(Double));
|
||||
Assert.AreEqual(384UL, Enumerable.Range(1, 4).Product(Double));
|
||||
Assert.AreEqual(3840UL, Enumerable.Range(1, 5).Product(Double));
|
||||
Assert.AreEqual(46080UL, Enumerable.Range(1, 6).Product(Double));
|
||||
Assert.AreEqual(645120UL, Enumerable.Range(1, 7).Product(Double));
|
||||
Assert.AreEqual(10321920UL, Enumerable.Range(1, 8).Product(Double));
|
||||
Assert.AreEqual(185794560UL, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200UL, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user