Commit 8037445d authored by An Ionescu's avatar An Ionescu

Numerous changes to NestedIDictionaryBase: Adding new tests, Adding...

Numerous changes to NestedIDictionaryBase: Adding new tests, Adding constructor delegates to the constructor to allow flexible creation of needed collections, Moving constructor parameters into a data class. Changing MultiMap test classes to accomodate the recent modifications.
parent c8fff6ab
......@@ -2,6 +2,11 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using NestedIDictionaryArgs = Anvoker.Collections.Maps.Tests
.NestedIDictionaryBase<int, decimal,
Anvoker.Collections.Maps.MultiMap<int, decimal>,
System.Collections.Generic.ICollection<decimal>>
.Args;
namespace Anvoker.Collections.Maps.Tests.MultiMap
{
......@@ -10,25 +15,47 @@ namespace Anvoker.Collections.Maps.Tests.MultiMap
/// </summary>
internal static class FixtureSource_IntDecimal
{
private static readonly int[] intKeys = new int[]
private static readonly int[] keys = new int[]
{
25, 37, 99, 20, -5
};
private static readonly int[] intKeysExcluded = new int[]
private static readonly int[] keysToAdd = new int[]
{
900, 901, 525
};
private static readonly int[] keysExcluded = new int[]
{
24, 2, -8
};
private static readonly decimal[][] decimalValues = new decimal[][]
private static readonly decimal[][] values = new decimal[][]
{
new decimal[] { 0.1m },
new decimal[] { 5.25m, 0.0m },
new decimal[] { 5.25m, 0.0m, 2.0m, 5.0m },
new decimal[] { 1.75m },
new decimal[] { },
new decimal[] { 3.75m },
};
private static readonly decimal[][] valuesToAdd = new decimal[][]
{
new decimal[] { 99.1m },
new decimal[] { },
new decimal[] { 5.25m, 0.0m, 25.0m },
};
private static readonly decimal[][] valuesExcluded = new decimal[][]
{
new decimal[] { 5.25m, 0.0m },
new decimal[] { },
new decimal[] { 5.25m, 0.0m, 25.0m },
};
private static readonly Func<IEnumerable<decimal>, ICollection<decimal>>
valueCollectionCtor = (x) => new HashSet<decimal>(x);
/// <summary>
/// Provides the arguments for a test fixture that is decorated with
/// <see cref="TestCaseSourceAttribute"/> and has a constructor with
......@@ -37,28 +64,38 @@ namespace Anvoker.Collections.Maps.Tests.MultiMap
/// <returns>An array of objects where each object is a collection
/// that contains all of the necessary parameters to run a constructor
/// of matching type.</returns>
public static object[] FixtureArgs() => new object[]
public static object[] GetNestedIDictionaryArgs() => new object[]
{
ConstructIntDecimalCase()
};
private static object[] ConstructIntDecimalCase()
{
var multiMap = new MultiMap<int, decimal>()
#pragma warning disable IDE0039 // Use local function
Func<MultiMap<int, decimal>> multiMapCtor = ()
=> new MultiMap<int, decimal>()
{
{ intKeys[0], decimalValues[0] },
{ intKeys[1], decimalValues[1] },
{ intKeys[2], decimalValues[2] },
{ intKeys[3], decimalValues[3] },
{ intKeys[4], decimalValues[4] }
{ keys[0], values[0] },
{ keys[1], values[1] },
{ keys[2], values[2] },
{ keys[3], values[3] },
{ keys[4], values[4] }
};
#pragma warning restore IDE0039 // Use local function
return new object[]
{
multiMap,
intKeys,
(ICollection<decimal>[])decimalValues,
intKeysExcluded
new NestedIDictionaryArgs(
multiMapCtor,
valueCollectionCtor,
keys,
values,
keysExcluded,
valuesExcluded,
keysToAdd,
valuesToAdd,
null,
null)
};
}
}
......
......@@ -14,34 +14,20 @@ namespace Anvoker.Collections.Maps.Tests.MultiMap.IDictionary
/// <see cref="MultiMap{TKey, TVal}"/>.</typeparam>
/// <typeparam name="TVal">Type of the values in the
/// <see cref="MultiMap{TKey, TVal}"/>.</typeparam>
[TestFixture]
public class NestedIDictionary<TKey, TVal>
: NestedIDictionaryBase<TKey, TVal, MultiMap<TKey, TVal>,
ICollection<TVal>>
{
/// <summary>
/// Initializes a new instance of the
/// <see cref="NestedIDictionary{TKey, TVal}"/> class with and the
/// specified keys and values.
/// <see cref="NestedIDictionary{TKey, TVal}"/>
/// class with <see cref="MultiMap{TKey, TVal}"/> as the collection
/// being tested.
/// </summary>
/// <param name="multiMap">An instance of
/// <see cref="MultiMap{TKey, TVal}"/> already initialized with the
/// specified keys and values.</param>
/// <param name="initialKeys">An enumeration of keys also found in the
/// specified <paramref name="multiMap"/>.
/// <para>Used to verify tests.</para></param>
/// <param name="initialValueCollections">An enumeration of collections
/// of values also found in <paramref name="multiMap"/>.
/// <para>Used to verify tests.</para></param>
/// <param name="excludedKeys">An enumeration of value of the same type
/// as the keys in <paramref name="multiMap"/>, none of which are
/// contained in <paramref name="multiMap"/>.
/// <para>Used to test for false positives.</para></param>
public NestedIDictionary(
MultiMap<TKey, TVal> multiMap,
TKey[] initialKeys,
ICollection<TVal>[] initialValueCollections,
TKey[] excludedKeys)
: base(multiMap, initialKeys, initialValueCollections, excludedKeys)
/// <param name="args">A data class containing all of the necessary
/// arguments for initializing the tests.</param>
public NestedIDictionary(Args args) : base(args)
{
}
}
......
......@@ -2,7 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Api;
namespace Anvoker.Collections.Maps.Tests.MultiMap.IDictionary
{
......@@ -14,34 +13,25 @@ namespace Anvoker.Collections.Maps.Tests.MultiMap.IDictionary
/// </summary>
[TestFixture, TestFixtureSource(
typeof(FixtureSource_IntDecimal),
nameof(FixtureSource_IntDecimal.FixtureArgs))]
nameof(FixtureSource_IntDecimal.GetNestedIDictionaryArgs))]
public class IntDecimal : NestedIDictionary<int, decimal>
{
/// <summary>
/// Initializes a new instance of the
/// <see cref="IntDecimal"/> class with and the
/// specified keys and values of <see cref="int"/> and
/// <see cref="decimal"/> type respectively.
/// <see cref="IntDecimal"/>
/// class with that leverages
/// <see cref="NestedIDictionaryBase{TKey, TVal, TIDict, TValCol}"/>
/// with <see cref="MultiMap{TKey, TVal}"/> as the collection
/// being tested and <see cref="int"/> and <see cref="decimal"/> as
/// the key and value types respectively.
/// </summary>
/// <param name="multiMap">An instance of
/// <see cref="MultiMap{TKey, TVal}"/> already initialized with the
/// specified keys and values.</param>
/// <param name="initialKeys">An enumeration of keys also found in the
/// specified <paramref name="multiMap"/>.
/// <para>Used to verify tests.</para></param>
/// <param name="initialValueCollections">An enumeration of collections
/// of values also found in <paramref name="multiMap"/>.
/// <para>Used to verify tests.</para></param>
/// <param name="excludedKeys">An enumeration of value of the same type
/// as the keys in <paramref name="multiMap"/>, none of which are
/// contained in <paramref name="multiMap"/>.
/// <para>Used to test for false positives.</para></param>
public IntDecimal(
MultiMap<int, decimal> multiMap,
int[] initialKeys,
ICollection<decimal>[] initialValueCollections,
int[] excludedKeys)
: base(multiMap, initialKeys, initialValueCollections, excludedKeys)
/// <remark>This exists just for readability purposes. It offers an
/// intermediary and more specific variant of
/// <see cref="NestedIDictionaryBase{TKey, TVal, TIDict, TValCol}"/>
/// </remark>
/// <param name="args">A data class containing all of the necessary
/// arguments for initializing the tests.</param>
public IntDecimal(Args args) : base(args)
{
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment