view Collections/CollectionsTest.cs @ 39:8b7aa46c4513

Re #48: Collection equality * Add initial tests for list equality
author IBBoard <dev@ibboard.co.uk>
date Tue, 26 Apr 2011 14:15:31 +0000
parents
children 8e8d0dc4ba20
line wrap: on
line source

//  This file (CollectionsTest.cs) is a part of the IBBoard.Tests project and is copyright 2011 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;
using System.Collections.Generic;
using NUnit.Framework.SyntaxHelpers;

namespace IBBoard.Collections
{
	[TestFixture()]
	public class CollectionsTest
	{
		[Test]
		public void TestSelfEquality()
		{
			IList<int> list1 = new List<int>();
			Assert.That(Collections.AreEqual(list1, list1), Is.True);
		}

		[Test()]
		public void TestEmptyListEquality()
		{
			IList<int> list1 = new List<int>();
			IList<int> list2 = new List<int>();
			Assert.That(Collections.AreEqual(list1, list2), Is.True);
			Assert.That(Collections.AreEqual(list2, list1), Is.True);
		}

		[Test()]
		public void TestEmptyAndNonEmptyListForInequality()
		{
			IList<int> list1 = new List<int>();
			IList<int> list2 = new List<int>();
			list1.Add(1);
			Assert.That(Collections.AreEqual(list1, list2), Is.False);
			Assert.That(Collections.AreEqual(list2, list1), Is.False);
		}

		[Test]
		public void TestDifferentNonEmptyListsForInequality()
		{
			IList<int> list1 = new List<int>();
			list1.Add(1);
			IList<int> list2 = new List<int>();
			list2.Add(2);
			Assert.That(Collections.AreEqual(list1, list2), Is.False);
			Assert.That(Collections.AreEqual(list2, list1), Is.False);
		}

		[Test]
		public void TestMatchingNonEmptyListsForEquality()
		{
			IList<int> list1 = new List<int>();
			list1.Add(1);
			IList<int> list2 = new List<int>();
			list2.Add(1);
			Assert.That(Collections.AreEqual(list1, list2), Is.True);
			Assert.That(Collections.AreEqual(list2, list1), Is.True);
		}

		[Test]
		public void TestDifferentOrderedListsForInequality()
		{
			IList<int> list1 = new List<int>();
			list1.Add(1);
			list1.Add(2);
			list1.Add(3);
			IList<int> list2 = new List<int>();
			list2.Add(3);
			list2.Add(2);
			list2.Add(1);
			Assert.That(Collections.AreEqual(list1, list2), Is.False);
			Assert.That(Collections.AreEqual(list2, list1), Is.False);
		}
	}
}