public void IsGreaterThan() { CompareAssert.IsGreaterThan(7, 4); CompareAssert.IsGreaterThan("a", "B", StringComparer.Ordinal, "\"a\" should be greater than \"B\" for case-sensitive ordinal comparison."); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsGreaterThan("a", "B", StringComparer.OrdinalIgnoreCase), "\"a\" should not be greater than \"B\" for case-insensitive ordinal comparison."); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsGreaterThan("b", "B", StringComparer.OrdinalIgnoreCase), "\"b\" should not be greater than \"B\" for case-insensitive ordinal comparison."); CompareAssert.IsGreaterThan("x", null); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsGreaterThan(null, "x"), "(null) should not be greater than \"x\"."); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsGreaterThan <string>(null, null), "(null) should not be greater than (null)."); }
public void IsEqualTo() { CompareAssert.IsEqualTo(4, 4); CompareAssert.IsEqualTo("B", "B"); CompareAssert.IsEqualTo("B", "b", StringComparer.OrdinalIgnoreCase, "\"B\" should be equal to \"b\" for case-insensitive ordinal comparison."); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsEqualTo("B", "A"), "\"B\" should not be equal to \"A\"."); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsEqualTo("B", "b", StringComparer.Ordinal), "\"B\" should not be equal to \"b\" for case-sensitive ordinal comparison."); CompareAssert.IsEqualTo <string>(null, null); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsEqualTo(null, "x"), "(null) should not be equal to \"x\"."); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsEqualTo("x", null), "\"x\" should not be equal to (null)."); }
public void Compare_Nulls() { var comparer = KeyComparer.Create((City city) => city.Name); CompareAssert.IsLessThan(null, athens, comparer); CompareAssert.IsEqualTo(null, null, comparer); CompareAssert.IsGreaterThan(athens, null, comparer); }
public void Compare_String() { var comparer = new OrdinalStringComparer(); CompareAssert.IsEqualTo(null, null, comparer); CompareAssert.IsLessThan(null, "abc", comparer); CompareAssert.IsGreaterThan("abc", null, comparer); CompareAssert.IsEqualTo("abc", "abc", comparer); CompareAssert.IsLessThan("abc", "xyz", comparer); CompareAssert.IsGreaterThan("abc", "a", comparer); }
public void Compare_NullableInt() { var comparer = new NullableIntComparer(); CompareAssert.IsEqualTo(null, null, comparer); CompareAssert.IsLessThan(null, 4, comparer); CompareAssert.IsGreaterThan(4, null, comparer); CompareAssert.IsEqualTo(4, 4, comparer); CompareAssert.IsLessThan(4, 7, comparer); CompareAssert.IsGreaterThan(4, 2, comparer); }
public void Compare_Nulls() { var x = new[] { "Madrid", "Añasco" }; foreach (var comparisonType in EnumUtility.GetValues <SequenceComparison>()) { var comparer = SequenceComparer.Create <string>(comparisonType); CompareAssert.IsLessThan(null, x, comparer); CompareAssert.IsEqualTo(null, null, comparer); CompareAssert.IsGreaterThan(x, null, comparer); } }
public void Compare() { using (new CultureSwapper(PredefinedCulture.EnglishUnitedStates)) { var message = "'ñ' should be less than 't' for default comparison (current culture, en-US)."; var comparer = KeyComparer.Create((City city) => city.Name); CompareAssert.IsLessThan(añasco, athens, comparer, message); CompareAssert.IsEqualTo(añasco, añasco, comparer); CompareAssert.IsGreaterThan(athens, añasco, comparer, message); message = "'ñ' should greater less than 't' for ordinal comparison."; comparer = KeyComparer.Create((City city) => city.Name, StringComparer.Ordinal); CompareAssert.IsGreaterThan(añasco, athens, comparer, message); CompareAssert.IsEqualTo(añasco, añasco, comparer); CompareAssert.IsLessThan(athens, añasco, comparer, message); } }
public void Compare_Shortlex_Enumerables() { var comparer = SequenceComparer <int> .Shortlex; CompareAssert.IsEqualTo(Enumerable.Empty <int>(), Enumerable.Empty <int>(), comparer); CompareAssert.IsLessThan(Enumerable.Empty <int>(), EnumerableUtility.Yield(42), comparer); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59), Enumerable.Empty <int>(), comparer); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59), EnumerableUtility.Yield(42), comparer); CompareAssert.IsLessThan(EnumerableUtility.Yield(59), EnumerableUtility.Yield(42, 98), comparer); CompareAssert.IsLessThan(EnumerableUtility.Yield(59), EnumerableUtility.Yield(42, 98, 11), comparer); CompareAssert.IsLessThan(EnumerableUtility.Yield(59, 23), EnumerableUtility.Yield(42, 98, 11), comparer); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59, 23, 34), EnumerableUtility.Yield(42, 98, 11), comparer); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(42, 98, 11), comparer); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 98, 11), comparer); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 23, 11), comparer); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 23, 34), comparer); CompareAssert.IsEqualTo(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 23, 34, 16), comparer); CompareAssert.IsLessThan(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 23, 34, 16, 65), comparer); }
public void Compare_Shortlex_Arrays() { var comparer = SequenceComparer <int> .Shortlex; CompareAssert.IsEqualTo(new int[] { }, new int[] { }, comparer); CompareAssert.IsLessThan(new int[] { }, new int[] { 42 }, comparer); CompareAssert.IsGreaterThan(new int[] { 59 }, new int[] { }, comparer); CompareAssert.IsGreaterThan(new int[] { 59 }, new int[] { 42 }, comparer); CompareAssert.IsLessThan(new int[] { 59 }, new int[] { 42, 98 }, comparer); CompareAssert.IsLessThan(new int[] { 59 }, new int[] { 42, 98, 11 }, comparer); CompareAssert.IsLessThan(new int[] { 59, 23 }, new int[] { 42, 98, 11 }, comparer); CompareAssert.IsGreaterThan(new int[] { 59, 23, 34 }, new int[] { 42, 98, 11 }, comparer); CompareAssert.IsGreaterThan(new int[] { 59, 23, 34, 16 }, new int[] { 42, 98, 11 }, comparer); CompareAssert.IsGreaterThan(new int[] { 59, 23, 34, 16 }, new int[] { 59, 98, 11 }, comparer); CompareAssert.IsGreaterThan(new int[] { 59, 23, 34, 16 }, new int[] { 59, 23, 11 }, comparer); CompareAssert.IsGreaterThan(new int[] { 59, 23, 34, 16 }, new int[] { 59, 23, 34 }, comparer); CompareAssert.IsEqualTo(new int[] { 59, 23, 34, 16 }, new int[] { 59, 23, 34, 16 }, comparer); CompareAssert.IsLessThan(new int[] { 59, 23, 34, 16 }, new int[] { 59, 23, 34, 16, 65 }, comparer); }
public void Serialize_BinaryFormatter() { var x = new[] { "abc", "def" }; var y = new[] { "abc", "DEF" }; var z = new[] { "xyz" }; var binaryFormatter = new BinaryFormatter(); using (var stream = new MemoryStream()) { var original = SequenceComparer.Create(SequenceComparison.Shortlex, StringComparer.OrdinalIgnoreCase); binaryFormatter.Serialize(stream, original); stream.Position = 0; var comparer = (SequenceComparer <string>)binaryFormatter.Deserialize(stream); CompareAssert.IsEqualTo(x, y, comparer); CompareAssert.IsGreaterThan(x, z, comparer); } }
public void Compare_SameLength_Enumerables() { var comparer = SequenceComparer <int> .SameLength; CompareAssert.IsEqualTo(Enumerable.Empty <int>(), Enumerable.Empty <int>(), comparer); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(Enumerable.Empty <int>(), EnumerableUtility.Yield(42))); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59), Enumerable.Empty <int>())); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59), EnumerableUtility.Yield(42), comparer); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59), EnumerableUtility.Yield(42, 98))); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59), EnumerableUtility.Yield(42, 98, 11))); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59, 23), EnumerableUtility.Yield(42, 98, 11))); CompareAssert.IsGreaterThan(EnumerableUtility.Yield(59, 23, 34), EnumerableUtility.Yield(42, 98, 11), comparer); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(42, 98, 11))); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 98, 11))); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 23, 11))); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 23, 34))); CompareAssert.IsEqualTo(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 23, 34, 16), comparer); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(EnumerableUtility.Yield(59, 23, 34, 16), EnumerableUtility.Yield(59, 23, 34, 16, 65))); }
public void Compare_SameLength_Arrays() { var comparer = SequenceComparer <int> .SameLength; CompareAssert.IsEqualTo(new int[] { }, new int[] { }, comparer); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { }, new int[] { 42 })); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59 }, new int[] { })); CompareAssert.IsGreaterThan(new int[] { 59 }, new int[] { 42 }, comparer); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59 }, new int[] { 42, 98 })); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59 }, new int[] { 42, 98, 11 })); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59, 23 }, new int[] { 42, 98, 11 })); CompareAssert.IsGreaterThan(new int[] { 59, 23, 34 }, new int[] { 42, 98, 11 }, comparer); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59, 23, 34, 16 }, new int[] { 42, 98, 11 })); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59, 23, 34, 16 }, new int[] { 59, 98, 11 })); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59, 23, 34, 16 }, new int[] { 59, 23, 11 })); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59, 23, 34, 16 }, new int[] { 59, 23, 34 })); CompareAssert.IsEqualTo(new int[] { 59, 23, 34, 16 }, new int[] { 59, 23, 34, 16 }, comparer); ExceptionAssert.Throws <ArgumentException>(() => comparer.Compare(new int[] { 59, 23, 34, 16 }, new int[] { 59, 23, 34, 16, 65 })); }
public void IsLessThanOrEqualTo() { CompareAssert.IsLessThanOrEqualTo(4, 7); CompareAssert.IsLessThanOrEqualTo(4, 4); CompareAssert.IsLessThanOrEqualTo("B", "a", StringComparer.Ordinal, "\"B\" should be less than or equal to \"a\" for case-sensitive ordinal comparison."); CompareAssert.IsLessThanOrEqualTo("B", "b", StringComparer.OrdinalIgnoreCase, "\"B\" should be less than or equal to \"b\" for case-insensitive ordinal comparison."); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsLessThanOrEqualTo("B", "a", StringComparer.OrdinalIgnoreCase), "\"B\" should not be less than or equal to \"a\" for case-insensitive ordinal comparison."); CompareAssert.IsLessThanOrEqualTo <string>(null, null); CompareAssert.IsLessThanOrEqualTo(null, "x"); ExceptionAssert.ThrowsAssertFailed( () => CompareAssert.IsLessThanOrEqualTo("x", null), "\"x\" should not be less than or equal to (null)."); }
public void Compare_Strings() { var x = new[] { "Madrid", "Añasco" }; var y = new[] { "Madrid", "Athens" }; using (new CultureSwapper(PredefinedCulture.EnglishUnitedStates)) { foreach (var comparisonType in EnumUtility.GetValues <SequenceComparison>()) { var message = "'ñ' should be less than 't' for default comparison (current culture, en-US)."; var comparer = SequenceComparer.Create <string>(comparisonType); CompareAssert.IsLessThan(x, y, comparer, message); CompareAssert.IsEqualTo(x, x, comparer); CompareAssert.IsGreaterThan(y, x, comparer, message); message = "'ñ' should be greater than 't' for ordinal comparison."; comparer = SequenceComparer.Create(comparisonType, StringComparer.Ordinal); CompareAssert.IsGreaterThan(x, y, comparer, message); CompareAssert.IsEqualTo(x, x, comparer); CompareAssert.IsLessThan(y, x, comparer, message); } } }