mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-18 14:15:12 +00:00
Tidying
This commit is contained in:
@@ -13,10 +13,10 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> dict = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 },
|
||||
{ 3, 30 },
|
||||
{ 4, 40 },
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30},
|
||||
{4, 40},
|
||||
};
|
||||
|
||||
Assert.IsTrue(dict.RemoveValue(10));
|
||||
@@ -31,10 +31,10 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> dict = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 10 },
|
||||
{ 3, 30 },
|
||||
{ 4, 40 },
|
||||
{1, 10},
|
||||
{2, 10},
|
||||
{3, 30},
|
||||
{4, 40},
|
||||
};
|
||||
|
||||
dict.RemoveAllValues(10);
|
||||
@@ -49,10 +49,10 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> dict = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 10 },
|
||||
{ 3, 30 },
|
||||
{ 4, 40 },
|
||||
{1, 10},
|
||||
{2, 10},
|
||||
{3, 30},
|
||||
{4, 40},
|
||||
};
|
||||
|
||||
Assert.AreEqual(10, dict.GetDefault(1));
|
||||
@@ -64,10 +64,10 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> dict = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 10 },
|
||||
{ 3, 30 },
|
||||
{ 4, 40 },
|
||||
{1, 10},
|
||||
{2, 10},
|
||||
{3, 30},
|
||||
{4, 40},
|
||||
};
|
||||
|
||||
Assert.AreEqual(10, dict.GetDefault(1, 1000));
|
||||
@@ -79,10 +79,10 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> dict = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 10 },
|
||||
{ 3, 30 },
|
||||
{ 4, 40 },
|
||||
{1, 10},
|
||||
{2, 10},
|
||||
{3, 30},
|
||||
{4, 40},
|
||||
};
|
||||
|
||||
Assert.AreEqual(10, dict.GetOrAddDefault(1, 1000));
|
||||
@@ -96,9 +96,9 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> dict = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 },
|
||||
{ 3, 30 }
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
Assert.AreEqual(1, dict.GetKey(10));
|
||||
@@ -112,9 +112,9 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> dict = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 },
|
||||
{ 3, 30 }
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
int key;
|
||||
@@ -134,9 +134,9 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> dict = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 10 },
|
||||
{ 3, 30 }
|
||||
{1, 10},
|
||||
{2, 10},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
int[] aKeys = dict.GetKeys(10).ToArray();
|
||||
@@ -158,14 +158,14 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> a = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 10 },
|
||||
{1, 10},
|
||||
{2, 10},
|
||||
};
|
||||
|
||||
Dictionary<int, int> b = new Dictionary<int, int>
|
||||
{
|
||||
{ 2, 20 },
|
||||
{ 3, 30 }
|
||||
{2, 20},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
a.Update(b);
|
||||
@@ -201,31 +201,25 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
|
||||
[Test]
|
||||
public void DictionaryEqualTest()
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DictionaryEqualComparerTest()
|
||||
{
|
||||
Dictionary<int, int> a = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 },
|
||||
{ 3, 30 },
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
Dictionary<int, int> b = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 },
|
||||
{ 3, 30 },
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
Dictionary<int, int> c = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 }
|
||||
{1, 10},
|
||||
{2, 20}
|
||||
};
|
||||
|
||||
Assert.IsTrue(a.DictionaryEqual(b));
|
||||
@@ -236,19 +230,49 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DictionaryEqualFuncComparerTest()
|
||||
public void DictionaryEqualComparerTest()
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DictionaryEqualFuncComparerTest()
|
||||
{
|
||||
Dictionary<int, int> a = new Dictionary<int, int>
|
||||
{
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
Dictionary<int, int> b = new Dictionary<int, int>
|
||||
{
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
Dictionary<int, int> c = new Dictionary<int, int>
|
||||
{
|
||||
{1, 10},
|
||||
{2, 20}
|
||||
};
|
||||
|
||||
Assert.IsTrue(a.DictionaryEqual(b, (left, right) => left / 10 == right / 10));
|
||||
Assert.IsTrue(b.DictionaryEqual(a, (left, right) => left / 10 == right / 10));
|
||||
|
||||
Assert.IsFalse(a.DictionaryEqual(c, (left, right) => left / 10 == right / 10));
|
||||
Assert.IsFalse(c.DictionaryEqual(a, (left, right) => left / 10 == right / 10));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OrderByKeyTest()
|
||||
{
|
||||
Dictionary<int, int> a = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 },
|
||||
{ 3, 30 },
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30}
|
||||
};
|
||||
|
||||
KeyValuePair<int, int>[] ordered = a.OrderByKey().ToArray();
|
||||
@@ -264,9 +288,9 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
Dictionary<int, int> a = new Dictionary<int, int>
|
||||
{
|
||||
{ 1, 10 },
|
||||
{ 2, 20 },
|
||||
{ 3, 30 },
|
||||
{1, 10},
|
||||
{2, 20},
|
||||
{3, 30},
|
||||
};
|
||||
|
||||
int[] ordered = a.OrderValuesByKey().ToArray();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ICD.Common.Properties;
|
||||
#if SIMPLSHARP
|
||||
using Crestron.SimplSharp.Reflection;
|
||||
#else
|
||||
@@ -12,16 +13,19 @@ namespace ICD.Common.Utils.Tests
|
||||
[TestFixture]
|
||||
public sealed class ReflectionUtilsTest
|
||||
{
|
||||
[UsedImplicitly]
|
||||
private string TestProperty { get; set; }
|
||||
|
||||
[UsedImplicitly]
|
||||
private void TestMethod(string param1, int param2)
|
||||
{
|
||||
}
|
||||
|
||||
private class TestClass
|
||||
[UsedImplicitly]
|
||||
private sealed class TestClass
|
||||
{
|
||||
public string Param1 { get; set; }
|
||||
public int Param2 { get; set; }
|
||||
public string Param1 { get; }
|
||||
public int Param2 { get; }
|
||||
|
||||
public TestClass(string param1, int param2)
|
||||
{
|
||||
@@ -46,31 +50,31 @@ namespace ICD.Common.Utils.Tests
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => ReflectionUtils.MatchesConstructorParameters(null, new object[] { "test", 10 }));
|
||||
|
||||
ConstructorInfo constructor = typeof(TestClass).GetConstructor(new Type[] { typeof(string), typeof(int) });
|
||||
ConstructorInfo constructor = typeof(TestClass).GetConstructor(new Type[] {typeof(string), typeof(int)});
|
||||
|
||||
Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { "test", 10 }));
|
||||
Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { null, 10 }));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { "test", "test" }));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { "test" }));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { "test", "test", "test" }));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] { 10, 10 }));
|
||||
Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test", 10}));
|
||||
Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {null, 10}));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test", "test"}));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test"}));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test", "test", "test"}));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {10, 10}));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MatchesMethodParametersTest()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => ReflectionUtils.MatchesMethodParameters(null, new object[] { "test", 10 }));
|
||||
Assert.Throws<ArgumentNullException>(() => ReflectionUtils.MatchesMethodParameters(null, new object[] {"test", 10}));
|
||||
|
||||
MethodInfo method = GetType().GetMethod("TestMethod",
|
||||
BindingFlags.NonPublic |
|
||||
BindingFlags.Instance);
|
||||
|
||||
Assert.IsTrue(ReflectionUtils.MatchesMethodParameters(method, new object[] { "test", 10 }));
|
||||
Assert.IsTrue(ReflectionUtils.MatchesMethodParameters(method, new object[] { null, 10 }));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] { "test", "test" }));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] { "test" }));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] { "test", "test", "test" }));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] { 10, 10 }));
|
||||
Assert.IsTrue(ReflectionUtils.MatchesMethodParameters(method, new object[] {"test", 10}));
|
||||
Assert.IsTrue(ReflectionUtils.MatchesMethodParameters(method, new object[] {null, 10}));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] {"test", "test"}));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] {"test"}));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] {"test", "test", "test"}));
|
||||
Assert.IsFalse(ReflectionUtils.MatchesMethodParameters(method, new object[] {10, 10}));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user