| using System;
using NUnit.Framework;
[TestFixture]
public class SetTest{
Set<int> set1, set2, set3, set4;
[SetUp]
public void Init(){
set1 = new Set<int>();
set2 = new Set<int>(10);
set3 = new Set<int>(new int[]{1,2,3});
set4 = new Set<int>(set3);
}
[Test]
public void MemberTest(){
Assert.IsFalse(set1.Member(1), "Member test 1");
Assert.IsFalse(set2.Member(1), "Member test 2");
Assert.IsTrue(set3.Member(1), "Member test 3");
Assert.IsTrue(set4.Member(1), "Member test 4");
Assert.IsFalse(set3.Member(4), "Member test 5");
Assert.IsFalse(set4.Member(4), "Member test 6");
}
[Test]
public void InsertNonMember(){
set1.Insert(1);
Assert.AreEqual(set1.Count, 1, "Insert test 1");
Assert.IsTrue(set1.Member(1), "Insert test 2");
set3.Insert(4);
Assert.AreEqual(set3.Count, 4, "Insert test 3");
set4.Insert(4);
Assert.AreEqual(set4.Count, 4, "Insert test 4");
}
[Test]
public void InsertMember(){
set1.Insert(1); set1.Insert(1);
Assert.AreEqual(set1.Count, 1, "Insert test 1");
Assert.IsTrue(set1.Member(1), "Insert test 2");
set3.Insert(3);
Assert.AreEqual(set3.Count, 3, "Insert test 3");
set4.Insert(3);
Assert.AreEqual(set4.Count, 3, "Insert test 4");
}
[Test]
public void DeleteNonMember(){
set1.Delete(1);
Assert.AreEqual(set1.Count, 0, "Delete test 1");
set3.Delete(4);
Assert.AreEqual(set3.Count, 3, "Delete test 2");
}
[Test]
public void DeleteMember(){
set3.Delete(1);
Assert.AreEqual(set3.Count, 2, "Delete test 1");
Assert.IsFalse(set3.Member(1), "Delete test 2");
}
// Delete member twice
[Test]
public void DeleteMemberTwice(){
set3.Delete(1); set3.Delete(1);
Assert.AreEqual(set3.Count, 2, "Delete test 1");
Assert.IsFalse(set3.Member(1), "Delete test 2");
}
[Test]
public void MultipleDelete(){
set3.Delete(1); set3.Delete(2); set3.Delete(3);
Assert.AreEqual(set3.Count, 0, "Delete test 1");
Assert.IsFalse(set3.Member(1), "Delete test 2");
Assert.IsFalse(set3.Member(2), "Delete test 3");
Assert.IsFalse(set3.Member(3), "Delete test 4");
}
} |