diff ArraysTests.cs @ 29:9bdfaf717b58

Re #2: Refactor API * Test subtracting more * Test differencing, IndexOf and Contains * Add equality checker tests * Make use of new IBBoard NUnit helpers
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Aug 2010 16:03:03 +0000
parents 16c28954b559
children 8c1e331b47d5
line wrap: on
line diff
--- a/ArraysTests.cs	Sat Aug 21 10:07:09 2010 +0000
+++ b/ArraysTests.cs	Sat Aug 21 16:03:03 2010 +0000
@@ -1,9 +1,10 @@
 //  This file (ArraysTests.cs) is a part of the IBBoard.Tests project and is copyright 2010 IBBoard
 // 
-//  // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
 using System;
 using NUnit.Framework;
 using NUnit.Framework.SyntaxHelpers;
+using IBBoard.NUnit;
 namespace IBBoard
 {
 	[TestFixture()]
@@ -13,18 +14,26 @@
 		private static readonly string STRING_TWO = "two";
 		private static readonly string STRING_THREE = "three";
 		private static readonly string STRING_FOUR = "four";
+		private static readonly string[] EMPTY_ARRAY = new string[0];
 		private static readonly string[] THREE_ITEM_ARRAY = new string[] {
 			STRING_ONE,
 			STRING_TWO,
 			STRING_THREE
 		};
 		private static readonly string[] ONE_ITEM_ARRAY = new string[] { STRING_FOUR };
+		private static readonly string[] OTHER_ONE_ITEM_ARRAY = new string[] { STRING_TWO };
+		private static readonly string[] ANOTHER_ONE_ITEM_ARRAY = new string[] { STRING_THREE };
+		private static readonly string[] TWO_ITEM_ARRAY = new string[] { STRING_ONE, STRING_THREE };
+		private static readonly string[] OTHER_TWO_ITEM_ARRAY = new string[] { STRING_ONE, STRING_TWO };
 		
 		[Test()]
 		public void TestSubtractWithNoOverlapLeavesSameArray()
 		{
 			Assert.That(Arrays.Subtract(THREE_ITEM_ARRAY, ONE_ITEM_ARRAY), Is.EqualTo(THREE_ITEM_ARRAY));
 			Assert.That(Arrays.Subtract(ONE_ITEM_ARRAY, THREE_ITEM_ARRAY), Is.EqualTo(ONE_ITEM_ARRAY));
+			Assert.That(Arrays.Subtract(EMPTY_ARRAY, THREE_ITEM_ARRAY), Is.EqualTo(EMPTY_ARRAY));
+			Assert.That(Arrays.Subtract(ONE_ITEM_ARRAY, EMPTY_ARRAY), Is.EqualTo(ONE_ITEM_ARRAY));
+			
 		}
 		
 		[Test()]
@@ -32,6 +41,56 @@
 		{
 			Assert.That(Arrays.Subtract(THREE_ITEM_ARRAY, THREE_ITEM_ARRAY), Has.Length(0));
 			Assert.That(Arrays.Subtract(ONE_ITEM_ARRAY, ONE_ITEM_ARRAY), Has.Length(0));
+			Assert.That(Arrays.Subtract(EMPTY_ARRAY, EMPTY_ARRAY), Has.Length(0));
+		}
+		
+		[Test()]
+		public void TestSubtractWithEmptyArraysDoesNotError()
+		{
+			Assert.That(Arrays.Subtract(EMPTY_ARRAY, ONE_ITEM_ARRAY), Has.Length(0));
+			Assert.That(Arrays.Subtract(ONE_ITEM_ARRAY, EMPTY_ARRAY), Is.EqualTo(ONE_ITEM_ARRAY));
+		}
+
+		[Test()]
+		public void TestSubtractWithPartialOverlapLeavesPartialArray()
+		{
+			Assert.That(Arrays.Subtract(THREE_ITEM_ARRAY, OTHER_ONE_ITEM_ARRAY), Is.EqualTo(TWO_ITEM_ARRAY));
+			Assert.That(Arrays.Subtract(THREE_ITEM_ARRAY, ANOTHER_ONE_ITEM_ARRAY), Is.EqualTo(OTHER_TWO_ITEM_ARRAY));
+		}
+		
+		[Test()]
+		public void TestDifferenceWithNoOverlapReturnsAllEntities()
+		{
+			Assert.That(Arrays.Difference(ONE_ITEM_ARRAY, OTHER_ONE_ITEM_ARRAY), Does.ArrayContain(STRING_FOUR, STRING_TWO));
+			Assert.That(Arrays.Difference(ONE_ITEM_ARRAY, TWO_ITEM_ARRAY), Does.ArrayContain(STRING_ONE, STRING_THREE, STRING_FOUR));
+			Assert.That(Arrays.Difference(TWO_ITEM_ARRAY, ONE_ITEM_ARRAY), Does.ArrayContain(STRING_ONE, STRING_THREE, STRING_FOUR));
+			Assert.That(Arrays.Difference(EMPTY_ARRAY, ONE_ITEM_ARRAY), Does.ArrayContain(STRING_FOUR));
+			Assert.That(Arrays.Difference(TWO_ITEM_ARRAY, EMPTY_ARRAY), Does.ArrayContain(STRING_ONE, STRING_THREE));
+		}
+
+		[Test()]
+		public void TestDifferenceWithFullOverlapReturnsNoEntities()
+		{
+			Assert.That(Arrays.Difference(THREE_ITEM_ARRAY, THREE_ITEM_ARRAY), Is.Empty);
+			Assert.That(Arrays.Difference(ONE_ITEM_ARRAY, ONE_ITEM_ARRAY), Is.Empty);
+		}
+		
+		[Test()]
+		public void TestIndexOf()
+		{
+			Assert.That(Arrays.IndexOf(THREE_ITEM_ARRAY, STRING_ONE), Is.EqualTo(0));
+			Assert.That(Arrays.IndexOf(THREE_ITEM_ARRAY, STRING_TWO), Is.EqualTo(1));
+			Assert.That(Arrays.IndexOf(THREE_ITEM_ARRAY, STRING_FOUR), Is.EqualTo(-1));
+			Assert.That(Arrays.IndexOf(EMPTY_ARRAY, STRING_FOUR), Is.EqualTo(-1));
+		}
+
+		[Test()]
+		public void TestContains()
+		{
+			Assert.That(Arrays.Contains(THREE_ITEM_ARRAY, STRING_ONE), Is.True);
+			Assert.That(Arrays.Contains(THREE_ITEM_ARRAY, STRING_TWO), Is.True);
+			Assert.That(Arrays.Contains(THREE_ITEM_ARRAY, STRING_FOUR), Is.False);
+			Assert.That(Arrays.Contains(EMPTY_ARRAY, STRING_FOUR), Is.False);
 		}
 	}
 }