From 90477a818994fdcdceb79d0345204f314fe3bb52 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 28 Jul 2017 12:07:43 -0400 Subject: [PATCH] Initial commit of ListExtensionsTest --- .../Extensions/ListExtensionsTest.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 ICD.Common.Utils.Tests/Extensions/ListExtensionsTest.cs diff --git a/ICD.Common.Utils.Tests/Extensions/ListExtensionsTest.cs b/ICD.Common.Utils.Tests/Extensions/ListExtensionsTest.cs new file mode 100644 index 0000000..f05539c --- /dev/null +++ b/ICD.Common.Utils.Tests/Extensions/ListExtensionsTest.cs @@ -0,0 +1,54 @@ +using ICD.Common.Utils.Extensions; +using NUnit.Framework; +using System.Collections.Generic; +using System; + +namespace ICD.Common.Utils.Tests_NetStandard.Extensions +{ + [TestFixture] + public sealed class ListExtensionsTest + { + [Test] + public void AddSortedTest() + { + List testList = new List(); + + testList.AddSorted(2); + testList.AddSorted(3); + testList.AddSorted(1); + testList.AddSorted(2); + + Assert.AreEqual(4, testList.Count); + Assert.AreEqual(1, testList[0]); + Assert.AreEqual(2, testList[1]); + Assert.AreEqual(2, testList[2]); + Assert.AreEqual(3, testList[3]); + } + + [Test] + public void AddSortedComparerTest() + { + List testList = new List(); + IComparer comparer = new InverseComparer(); + + testList.AddSorted(2, comparer); + testList.AddSorted(3, comparer); + testList.AddSorted(1, comparer); + testList.AddSorted(2, comparer); + + Assert.AreEqual(4, testList.Count); + Assert.AreEqual(3, testList[0]); + Assert.AreEqual(2, testList[1]); + Assert.AreEqual(2, testList[2]); + Assert.AreEqual(1, testList[3]); + } + + internal class InverseComparer : IComparer + { + public int Compare(int x, int y) + { + return y.CompareTo(x); + } + } + } +}