Skip to content

Instantly share code, notes, and snippets.

@cz75hiro
Created August 29, 2010 11:01
Show Gist options
  • Save cz75hiro/556201 to your computer and use it in GitHub Desktop.
Save cz75hiro/556201 to your computer and use it in GitHub Desktop.
/// <summary>
///Within のテスト
///</summary>
public void WithinTest2Helper<T>(StructInterval<T> target, T obj, bool expected) where T : struct, IComparable<T> {
bool actual = target.Within(obj);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void WithinTest2() {
#region 文字列テスト
StructInterval<char> stringInterval;
//閉区間の境界テスト
stringInterval = new StructInterval<char>('か', 'く');
WithinTest2Helper<char>(stringInterval, 'お', false);
WithinTest2Helper<char>(stringInterval, 'か', true);
WithinTest2Helper<char>(stringInterval, 'く', true);
WithinTest2Helper<char>(stringInterval, 'こ', false);
//開区間の境界テスト
////Beginをnullに
stringInterval = new StructInterval<char>(null, 'e');
WithinTest2Helper<char>(stringInterval, 'e', true);
WithinTest2Helper<char>(stringInterval, 'f', false);
////Endをnullに
stringInterval = new StructInterval<char>('c', null);
WithinTest2Helper<char>(stringInterval, 'b', false);
WithinTest2Helper<char>(stringInterval, 'c', true);
#endregion
#region 数値テスト
StructInterval<int> intInterval;
//閉区間の境界テスト
intInterval = new StructInterval<int>(100, 200);
WithinTest2Helper<int>(intInterval, 99, false);
WithinTest2Helper<int>(intInterval, 100, true);
WithinTest2Helper<int>(intInterval, 200, true);
WithinTest2Helper<int>(intInterval, 201, false);
//開区間の境界テスト
////Beginをnullに
intInterval = new StructInterval<int>(null, 200);
WithinTest2Helper<int>(intInterval, 200, true);
WithinTest2Helper<int>(intInterval, 201, false);
////Endをnullに
intInterval = new StructInterval<int>(100, null);
WithinTest2Helper<int>(intInterval, 99, false);
WithinTest2Helper<int>(intInterval, 100, true);
#endregion
#region DateTimeテスト
StructInterval<DateTime> dateTimeInterval;
//閉区間の境界テスト
dateTimeInterval = new StructInterval<DateTime>(new DateTime(2010, 8, 1, 12, 30, 30, 500), new DateTime(2010, 8, 15, 12, 30, 30, 500));
WithinTest2Helper<DateTime>(dateTimeInterval, new DateTime(2010, 8, 1, 12, 30, 30, 499), false);
WithinTest2Helper<DateTime>(dateTimeInterval, new DateTime(2010, 8, 1, 12, 30, 30, 500), true);
WithinTest2Helper<DateTime>(dateTimeInterval, new DateTime(2010, 8, 15, 12, 30, 30, 500), true);
WithinTest2Helper<DateTime>(dateTimeInterval, new DateTime(2010, 8, 15, 12, 30, 30, 501), false);
////開区間の境界テスト
////Beginをnullに
dateTimeInterval = new StructInterval<DateTime>(null, new DateTime(2010, 8, 15, 12, 30, 30, 500));
WithinTest2Helper<DateTime>(dateTimeInterval, new DateTime(2010, 8, 15, 12, 30, 30, 500), true);
WithinTest2Helper<DateTime>(dateTimeInterval, new DateTime(2010, 8, 15, 12, 30, 30, 501), false);
////Endをnullに
dateTimeInterval = new StructInterval<DateTime>(new DateTime(2010, 8, 1, 12, 30, 30, 500), null);
WithinTest2Helper<DateTime>(dateTimeInterval, new DateTime(2010, 8, 1, 12, 30, 30, 499), false);
WithinTest2Helper<DateTime>(dateTimeInterval, new DateTime(2010, 8, 1, 12, 30, 30, 500), true);
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment