Commit a5fad1ad authored by An Ionescu's avatar An Ionescu

Adding MultiMap unit tests.

parent 56e12778
fileFormatVersion: 2
guid: ee2345ce74b53b94a9dc75c94e4da301
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
namespace Anvoker.Collections.Maps.Tests.MultiMap
{
/// <summary>
/// Unit tests for <see cref="MultiMap{TKey, TVal}"/>'s constructors.
/// </summary>
[TestFixture]
public class Constructors
{
/// <summary>
/// Checks that the parameterless constructor leaves the new MultiMap
/// in the expected state.
/// </summary>
[Test]
public void ParameterlessConstructor()
{
var multiMap = new MultiMap<string, int>();
Assert.AreEqual(0, multiMap.Count);
Assert.AreEqual(0, multiMap.Keys.Count);
Assert.AreEqual(0, multiMap.Values.Count);
Assert.AreEqual(
EqualityComparer<string>.Default, multiMap.ComparerKey);
Assert.AreEqual(
EqualityComparer<int>.Default, multiMap.ComparerValue);
}
/// <summary>
/// Checks that the constructor with the capacity parameter leaves
/// the new MultiMap in the expected state.
/// </summary>
[Test]
public void CapacityConstructor()
{
var multiMap = new MultiMap<string, int>(10);
Assert.AreEqual(0, multiMap.Count);
Assert.AreEqual(0, multiMap.Keys.Count);
Assert.AreEqual(0, multiMap.Values.Count);
Assert.AreEqual(
EqualityComparer<string>.Default, multiMap.ComparerKey);
Assert.AreEqual(
EqualityComparer<int>.Default, multiMap.ComparerValue);
}
/// <summary>
/// Checks that the constructor with the comparer parameters leaves
/// the new MultiMap in the expected state.
/// </summary>
[Test]
public void ComparerConstructor()
{
var comparerKey = StringComparer.OrdinalIgnoreCase;
var comparerValue = StringComparer.InvariantCulture;
var multiMap = new MultiMap<string, string>(
comparerKey, comparerValue);
Assert.AreEqual(0, multiMap.Count);
Assert.AreEqual(comparerKey, multiMap.ComparerKey);
Assert.AreEqual(comparerValue, multiMap.ComparerValue);
Assert.AreEqual(0, multiMap.Keys.Count);
Assert.AreEqual(0, multiMap.Values.Count);
}
}
}
fileFormatVersion: 2
guid: 20c0e5437dc90824bb08e7913fb78467
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
namespace Anvoker.Collections.Maps.Tests.MultiMap
{
/// <summary>
/// Provides test data for <see cref="NestedIDictionary_IntDecimal"/>.
/// </summary>
internal static class FixtureSource_IntDecimal
{
private static readonly int[] intKeys = new int[]
{
25, 37, 99, 20, -5
};
private static readonly int[] intKeysExcluded = new int[]
{
24, 2, -8
};
private static readonly decimal[][] decimalValues = 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[] { 3.75m },
};
/// <summary>
/// Provides the arguments for a test fixture that is decorated with
/// <see cref="TestCaseSourceAttribute"/> and has a constructor with
/// matching parameter types.
/// </summary>
/// <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[]
{
ConstructIntDecimalCase()
};
private static object[] ConstructIntDecimalCase()
{
var multiMap = new MultiMap<int, decimal>()
{
{ intKeys[0], decimalValues[0] },
{ intKeys[1], decimalValues[1] },
{ intKeys[2], decimalValues[2] },
{ intKeys[3], decimalValues[3] },
{ intKeys[4], decimalValues[4] }
};
return new object[]
{
multiMap,
intKeys,
(ICollection<decimal>[])decimalValues,
intKeysExcluded
};
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: b1ce25a70ec7d754dbf876e89bc0145b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
namespace Anvoker.Collections.Maps.Tests.MultiMap.IDictionary
{
/// <summary>
/// Does nothing but specify some of the types for
/// <see cref="NestedIDictionaryBase{TKey, TVal, TIDict, TValCol}"/>,
/// leaving only the key and value types as generic.
/// </summary>
/// <typeparam name="TKey">Type of the keys in the
/// <see cref="MultiMap{TKey, TVal}"/>.</typeparam>
/// <typeparam name="TVal">Type of the values in the
/// <see cref="MultiMap{TKey, TVal}"/>.</typeparam>
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.
/// </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)
{
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 4999d849d360bba4292e6aa94995556f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Api;
namespace Anvoker.Collections.Maps.Tests.MultiMap.IDictionary
{
/// <summary>
/// Runs tests from
/// <see cref="NestedIDictionaryBase{TKey, TVal, TIDict, TValCol}"/>
/// on <see cref="MultiMap{TKey, TVal}"/> using test data from
/// <see cref="FixtureSource_IntDecimal"/>.
/// </summary>
[TestFixture, TestFixtureSource(
typeof(FixtureSource_IntDecimal),
nameof(FixtureSource_IntDecimal.FixtureArgs))]
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.
/// </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)
{
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 688f05cfcf191d14088bf8e5465d3775
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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