Mercurial > repos > IBBoard.Tests
view ArraysTests.cs @ 49:99e4c1949c92 default tip
* Update to v2.6 of NUnit and new syntax/API changes
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 28 Apr 2013 19:32:14 +0100 |
parents | 8c1e331b47d5 |
children |
line wrap: on
line source
// 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 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; namespace IBBoard { [TestFixture()] public class ArraysTests { private static readonly string STRING_ONE = "one"; 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()] public void TestSubtractWithFullOverlapLeaveEmptyArray() { Assert.That(Arrays.Subtract(THREE_ITEM_ARRAY, THREE_ITEM_ARRAY), Has.Length.EqualTo(0)); Assert.That(Arrays.Subtract(ONE_ITEM_ARRAY, ONE_ITEM_ARRAY), Has.Length.EqualTo(0)); Assert.That(Arrays.Subtract(EMPTY_ARRAY, EMPTY_ARRAY), Has.Length.EqualTo(0)); } [Test()] public void TestSubtractWithEmptyArraysDoesNotError() { Assert.That(Arrays.Subtract(EMPTY_ARRAY, ONE_ITEM_ARRAY), Has.Length.EqualTo(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.AreEqual(Arrays.Difference(ONE_ITEM_ARRAY, OTHER_ONE_ITEM_ARRAY), new String[]{STRING_FOUR, STRING_TWO}); Assert.AreEqual(Arrays.Difference(ONE_ITEM_ARRAY, TWO_ITEM_ARRAY), new String[]{STRING_ONE, STRING_THREE, STRING_FOUR}); Assert.AreEqual(Arrays.Difference(TWO_ITEM_ARRAY, ONE_ITEM_ARRAY), new String[]{STRING_ONE, STRING_THREE, STRING_FOUR}); Assert.AreEqual(Arrays.Difference(EMPTY_ARRAY, ONE_ITEM_ARRAY), new String[]{STRING_FOUR}); Assert.AreEqual(Arrays.Difference(TWO_ITEM_ARRAY, EMPTY_ARRAY), new String[]{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); } } }