// ================================================================================================ // // IgnoreCaseSetのテストクラスソース。 // // // Copyright (C) 2012 Honeplus. All rights reserved. // // Honeplus // ================================================================================================ namespace Honememo.Models { using System; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; /// /// のテストクラスです。 /// [TestClass] public class IgnoreCaseSetTest { #region コンストラクタテストケース /// /// コンストラクタテストケース(引数なし)。 /// [TestMethod] public void TestConstructor() { IgnoreCaseSet set = new IgnoreCaseSet(); Assert.AreEqual(0, set.Set.Count); } /// /// コンストラクタテストケース(引数Set)。 /// [TestMethod] public void TestConstructorSet() { ISet inner = new HashSet(); inner.Add("TestValue"); IgnoreCaseSet set = new IgnoreCaseSet(inner); Assert.AreEqual(inner, set.Set); Assert.IsTrue(set.Contains("TESTValue")); } /// /// コンストラクタテストケース(引数Enumerable)。 /// [TestMethod] public void TestConstructorEnumerable() { IList other = new List(); other.Add("TestValue"); IgnoreCaseSet set = new IgnoreCaseSet(other); Assert.IsTrue(set.Contains("TESTValue")); } /// /// コンストラクタテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestConstructorSetNull() { new IgnoreCaseSet(null); } #endregion #region 独自実装公開プロパティテストケース /// /// Setプロパティテストケース(正常系)。 /// [TestMethod] public void TestSet() { IgnoreCaseSet set = new IgnoreCaseSet(); ISet inner = new HashSet(); inner.Add("TestValue"); set.Set = inner; Assert.AreSame(inner, set.Set); Assert.IsTrue(set.Contains("TESTvalue")); } /// /// Setプロパティテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestSetNull() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Set = null; } #endregion #region ラップするインスタンスを参照するプロパティテストケース /// /// Countプロパティテストケース。 /// [TestMethod] public void TestCount() { // ラップするISetと同じ値であること ISet inner = new HashSet(); inner.Add("TestValue"); IgnoreCaseSet set = new IgnoreCaseSet(inner); Assert.AreEqual(inner.Count, set.Count); } /// /// IsReadOnlyプロパティテストケース。 /// [TestMethod] public void TestIsReadOnly() { // ラップするISetと同じ値であること ISet inner = new HashSet(); inner.Add("TestValue"); IgnoreCaseSet set = new IgnoreCaseSet(inner); Assert.AreEqual(inner.IsReadOnly, set.IsReadOnly); } #endregion #region 独自実装メソッドテストケース /// /// Addメソッドテストケース(正常系)。 /// [TestMethod] public void TestAdd() { IgnoreCaseSet set = new IgnoreCaseSet(); Assert.AreEqual(0, set.Count); set.Add("TestValue"); Assert.AreEqual(1, set.Count); Assert.IsTrue(set.Contains("TESTvalue")); Assert.IsTrue(set.Set.Contains("TestValue")); Assert.IsFalse(set.Set.Contains("TESTvalue")); set.Add("tESTvALUE2"); Assert.AreEqual(2, set.Count); Assert.IsTrue(set.Contains("TESTvalue2")); Assert.IsTrue(set.Set.Contains("tESTvALUE2")); } /// /// Addメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestAddNull() { new IgnoreCaseSet().Add(null); } /// /// Containsメソッドテストケース(正常系)。 /// [TestMethod] public void TestContains() { IgnoreCaseSet set = new IgnoreCaseSet(); Assert.IsFalse(set.Contains("TestValue")); set.Add("TestValue"); Assert.IsTrue(set.Contains("TestValue")); Assert.IsTrue(set.Contains("tESTvALue")); Assert.IsFalse(set.Contains("TestValue2")); } /// /// Containsメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestContainsNull() { new IgnoreCaseSet().Contains(null); } /// /// Clearメソッドテストケース。 /// [TestMethod] public void TestClear() { // 全データが削除されること、またラップしているオブジェクトは維持されること ISet inner = new HashSet(); IgnoreCaseSet set = new IgnoreCaseSet(inner); set.Add("TestValue"); set.Add("tESTVAlue2"); Assert.AreEqual(2, set.Count); Assert.AreSame(inner, set.Set); set.Clear(); Assert.AreEqual(0, set.Count); Assert.AreSame(inner, set.Set); } /// /// CopyToメソッドテストケース(正常系)。 /// [TestMethod] public void TestCopyTo() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); string[] array = new string[5]; set.CopyTo(array, 3); Assert.IsNull(array[0]); Assert.IsNull(array[1]); Assert.IsNull(array[2]); Assert.AreEqual("TestValue", array[3]); Assert.AreEqual("tESTvAlue2", array[4]); } /// /// CopyToメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestCopyToNull() { new IgnoreCaseSet().CopyTo(null, 0); } /// /// CopyToメソッドテストケース(インデックスがマイナス値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException))] public void TestCopyToOutOfRange() { new IgnoreCaseSet().CopyTo(new string[5], -1); } /// /// CopyToメソッドテストケース(領域不足)。 /// [TestMethod] [ExpectedException(typeof(ArgumentException))] public void TestCopyToOverflow() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.CopyTo(new string[5], 4); } /// /// ExceptWithメソッドテストケース(正常系)。 /// [TestMethod] public void TestExceptWith() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); set.ExceptWith(new string[] { "TestValue", "testvalUE2", "TestValue4" }); Assert.AreEqual(1, set.Count); Assert.IsTrue(set.Set.Contains("testvalue3")); } /// /// ExceptWithメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestExceptWithNull() { new IgnoreCaseSet().ExceptWith(null); } /// /// IntersectWithメソッドテストケース(正常系)。 /// [TestMethod] public void TestIntersectWith() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); set.IntersectWith(new string[] { "TestValue", "testvalUE2", "TestValue4" }); Assert.AreEqual(2, set.Count); Assert.IsTrue(set.Set.Contains("TestValue")); Assert.IsTrue(set.Set.Contains("tESTvAlue2")); } /// /// IntersectWithメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestIntersectWithNull() { new IgnoreCaseSet().IntersectWith(null); } /// /// IsProperSubsetOfメソッドテストケース(正常系)。 /// [TestMethod] public void TestIsProperSubsetOf() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); Assert.IsFalse(set.IsProperSubsetOf(new string[0])); Assert.IsFalse(set.IsProperSubsetOf(new string[] { "TestValue", "testvalUE2" })); Assert.IsFalse(set.IsProperSubsetOf(new string[] { "TestValue", "testvalUE2", "TestValue4" })); Assert.IsFalse(set.IsProperSubsetOf(new string[] { "TestValue", "testvalUE2", "TestValue3" })); Assert.IsTrue(set.IsProperSubsetOf(new string[] { "TestValue", "testvalUE2", "TestValue3", "TestValue4" })); Assert.IsFalse(set.IsProperSubsetOf(new string[] { "TestValue4" })); } /// /// IsProperSubsetOfメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestIsProperSubsetOfNull() { new IgnoreCaseSet().IsProperSubsetOf(null); } /// /// IsProperSupersetOfメソッドテストケース(正常系)。 /// [TestMethod] public void TestIsProperSupersetOf() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); Assert.IsTrue(set.IsProperSupersetOf(new string[0])); Assert.IsTrue(set.IsProperSupersetOf(new string[] { "TestValue", "testvalUE2" })); Assert.IsFalse(set.IsProperSupersetOf(new string[] { "TestValue", "testvalUE2", "TestValue4" })); Assert.IsFalse(set.IsProperSupersetOf(new string[] { "TestValue", "testvalUE2", "TestValue3" })); Assert.IsFalse(set.IsProperSupersetOf(new string[] { "TestValue", "testvalUE2", "TestValue3", "TestValue4" })); Assert.IsFalse(set.IsProperSupersetOf(new string[] { "TestValue4" })); } /// /// IsProperSupersetOfメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestIsProperSupersetOfNull() { new IgnoreCaseSet().IsProperSupersetOf(null); } /// /// IsSubsetOfメソッドテストケース(正常系)。 /// [TestMethod] public void TestIsSubsetOf() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); Assert.IsFalse(set.IsSubsetOf(new string[0])); Assert.IsFalse(set.IsSubsetOf(new string[] { "TestValue", "testvalUE2" })); Assert.IsFalse(set.IsSubsetOf(new string[] { "TestValue", "testvalUE2", "TestValue4" })); Assert.IsTrue(set.IsSubsetOf(new string[] { "TestValue", "testvalUE2", "TestValue3" })); Assert.IsTrue(set.IsSubsetOf(new string[] { "TestValue", "testvalUE2", "TestValue3", "TestValue4" })); Assert.IsFalse(set.IsSubsetOf(new string[] { "TestValue4" })); } /// /// IsSubsetOfメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestIsSubsetOfNull() { new IgnoreCaseSet().IsSubsetOf(null); } /// /// IsSupersetOfメソッドテストケース(正常系)。 /// [TestMethod] public void TestIsSupersetOf() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); Assert.IsTrue(set.IsSupersetOf(new string[0])); Assert.IsTrue(set.IsSupersetOf(new string[] { "TestValue", "testvalUE2" })); Assert.IsFalse(set.IsSupersetOf(new string[] { "TestValue", "testvalUE2", "TestValue4" })); Assert.IsTrue(set.IsSupersetOf(new string[] { "TestValue", "testvalUE2", "TestValue3" })); Assert.IsFalse(set.IsSupersetOf(new string[] { "TestValue", "testvalUE2", "TestValue3", "TestValue4" })); Assert.IsFalse(set.IsSupersetOf(new string[] { "TestValue4" })); } /// /// IsSupersetOfメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestIsSupersetOfNull() { new IgnoreCaseSet().IsSupersetOf(null); } /// /// Overlapsメソッドテストケース(正常系)。 /// [TestMethod] public void TestOverlaps() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); Assert.IsFalse(set.Overlaps(new string[0])); Assert.IsTrue(set.Overlaps(new string[] { "TestValue", "testvalUE2" })); Assert.IsTrue(set.Overlaps(new string[] { "TestValue", "testvalUE2", "TestValue4" })); Assert.IsTrue(set.Overlaps(new string[] { "TestValue", "testvalUE2", "TestValue3" })); Assert.IsTrue(set.Overlaps(new string[] { "TestValue", "testvalUE2", "TestValue3", "TestValue4" })); Assert.IsFalse(set.Overlaps(new string[] { "TestValue4" })); } /// /// Overlapsメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestOverlapsNull() { new IgnoreCaseSet().Overlaps(null); } /// /// Removeメソッドテストケース(正常系)。 /// [TestMethod] public void TestRemove() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlUe2"); Assert.AreEqual(2, set.Count); Assert.IsTrue(set.Contains("TestValue")); Assert.IsTrue(set.Contains("tESTvAlUe2")); Assert.IsTrue(set.Remove("tEstValue")); Assert.AreEqual(1, set.Count); Assert.IsFalse(set.Contains("TestValue")); Assert.IsTrue(set.Contains("tESTvAlUe2")); Assert.IsFalse(set.Remove("tESTvAlUe3")); Assert.AreEqual(1, set.Count); Assert.IsTrue(set.Contains("tESTvAlUe2")); Assert.IsTrue(set.Remove("tESTvAlUe2")); Assert.AreEqual(0, set.Count); Assert.IsFalse(set.Contains("tESTvAlUe2")); } /// /// Removeメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestRemoveNull() { new IgnoreCaseSet().Remove(null); } /// /// SetEqualsメソッドテストケース(正常系)。 /// [TestMethod] public void TestSetEquals() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); Assert.IsFalse(set.SetEquals(new string[0])); Assert.IsFalse(set.SetEquals(new string[] { "TestValue", "testvalUE2" })); Assert.IsFalse(set.SetEquals(new string[] { "TestValue", "testvalUE2", "TestValue4" })); Assert.IsTrue(set.SetEquals(new string[] { "TestValue", "testvalUE2", "TestValue3" })); Assert.IsFalse(set.SetEquals(new string[] { "TestValue", "testvalUE2", "TestValue3", "TestValue4" })); Assert.IsFalse(set.SetEquals(new string[] { "TestValue4" })); } /// /// SetEqualsメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestSetEqualsNull() { new IgnoreCaseSet().SetEquals(null); } /// /// SymmetricExceptWithメソッドテストケース(正常系)。 /// [TestMethod] public void TestSymmetricExceptWith() { IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); set.SymmetricExceptWith(new string[] { "TestValue", "testvalUE2", "TestValue4" }); Assert.AreEqual(2, set.Count); Assert.IsTrue(set.Set.Contains("testvalue3")); Assert.IsTrue(set.Set.Contains("TestValue4")); } /// /// SymmetricExceptWithメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestSymmetricExceptWithNull() { new IgnoreCaseSet().SymmetricExceptWith(null); } /// /// UnionWithメソッドテストケース(正常系)。 /// [TestMethod] public void TestUnionWith() { // 両方の値が格納される、重複するものは後の値で上書き IgnoreCaseSet set = new IgnoreCaseSet(); set.Add("TestValue"); set.Add("tESTvAlue2"); set.Add("testvalue3"); set.UnionWith(new string[] { "TestValue", "testvalUE2", "TestValue4" }); Assert.AreEqual(4, set.Count); Assert.IsTrue(set.Set.Contains("TestValue")); Assert.IsTrue(set.Set.Contains("testvalUE2")); Assert.IsTrue(set.Set.Contains("testvalue3")); Assert.IsTrue(set.Set.Contains("TestValue4")); } /// /// UnionWithメソッドテストケース(null値)。 /// [TestMethod] [ExpectedException(typeof(ArgumentNullException))] public void TestUnionWithNull() { new IgnoreCaseSet().UnionWith(null); } #endregion #region ラップするインスタンスを参照するメソッドテストケース /// /// GetEnumeratorメソッドテストケース。 /// [TestMethod] public void TestGetEnumerator() { // ラップするISetと同じ値であること ISet inner = new HashSet(); inner.Add("TestValue"); IgnoreCaseSet set = new IgnoreCaseSet(inner); Assert.AreEqual(inner.GetEnumerator(), set.GetEnumerator()); } #endregion } }