public void HashCodeInvariantCultureCaseInsensitive() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: true); // Act var objectHashCode = comparer.GetHashCode((object)'h'); var objectHashCode2 = comparer.GetHashCode((object)'h'); var objectHashCode3 = comparer.GetHashCode((object)'H'); var charHashCode = comparer.GetHashCode('h'); var charHashCode2 = comparer.GetHashCode('h'); var charHashCode3 = comparer.GetHashCode('H'); // Assert comparer.Should().NotBeNull(); objectHashCode.Should().Be(objectHashCode2); objectHashCode.Should().Be(objectHashCode3); charHashCode.Should().Be(charHashCode2); charHashCode.Should().Be(charHashCode3); objectHashCode.Should().Be(charHashCode); objectHashCode2.Should().Be(charHashCode2); objectHashCode3.Should().Be(charHashCode3); objectHashCode.Should().Be(charHashCode2); objectHashCode.Should().Be(charHashCode3); objectHashCode3.Should().Be(charHashCode); }
public void ExpectedCompare(CharacterComparer comparer) { // Arrange // se parameter // Act var bothObjectNullCompare = comparer.Compare((object)null, (object)null); var objectCompare = comparer.Compare((object)'h', (object)'h'); var charCompare = comparer.Compare('h', 'h'); const char instance = 'h'; var objectReferenceCompare = comparer.Compare((object)instance, (object)instance); var leftObjectNullCompare = comparer.Compare(null, (object)'h'); var leftCharNullCompare = comparer.Compare(null, 'h'); var rightObjectNullCompare = comparer.Compare((object)'h', null); var rightCharNullCompare = comparer.Compare('h', null); var lowerCompare = comparer.Compare('a', 'h'); var higherCompoare = comparer.Compare('h', 'a'); // Assert objectCompare.Should().Be(0); charCompare.Should().Be(0); bothObjectNullCompare.Should().Be(0); objectReferenceCompare.Should().Be(0); leftObjectNullCompare.Should().Be(-1); leftCharNullCompare.Should().Be(-1); rightObjectNullCompare.Should().Be(1); rightCharNullCompare.Should().Be(1); lowerCompare.Should().BeInRange(int.MinValue, -1); higherCompoare.Should().BeInRange(1, int.MaxValue); }
public void InvalidCreationArguments() { // Arrange // Act Action nullCreationArgumentAct = () => CharacterComparer.Create(null, ignoreCase: true); // Assert nullCreationArgumentAct.Should().ThrowExactly <ArgumentNullException>(); }
public void InvalidHasCodeArguments() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: true); // Act Action nullHashCodeAct = () => comparer.GetHashCode(null); Action nullHashCodeAct2 = () => comparer.GetHashCode((object)null); // Assert nullHashCodeAct.Should().ThrowExactly <ArgumentNullException>(); nullHashCodeAct2.Should().ThrowExactly <ArgumentNullException>(); }
public void ComparerObjectHashCodeComparison() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: true); var obj = new object(); // Act var objectHashCode = obj.GetHashCode(); var comparerHashCode = comparer.GetHashCode(obj); // Assert comparer.Should().NotBeNull(); objectHashCode.Should().Be(comparerHashCode); }
public void EqualityInvariantCultureCaseSensitive() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: false); // Act var objectEquality = comparer.Equals((object)'H', (object)'H'); var charEquality = comparer.Equals('H', 'H'); var objectInequality = comparer.Equals((object)'h', (object)'H'); var charInequality = comparer.Equals('h', 'H'); // Assert comparer.Should().NotBeNull(); objectEquality.Should().BeTrue(); charEquality.Should().BeTrue(); objectInequality.Should().BeFalse(); charInequality.Should().BeFalse(); }
public void ComparerNonCharEqualityComparison() { // Arrange var comparer = CharacterComparer.Create(CultureInfo.InvariantCulture, ignoreCase: true); // Act var fromNumberCompare = 42.CompareTo(84); var comparerNumberCompare = comparer.Compare(42, 84); Action mixedCompareAct = () => comparer.Compare(42, 'A'); Action mixedCompareAct2 = () => comparer.Compare('A', 42); Action objectCompareAct = () => comparer.Compare(new object(), 42); var nullCompare = comparer.Compare('A', null); // Assert comparer.Should().NotBeNull(); fromNumberCompare.Should().Be(comparerNumberCompare); mixedCompareAct.Should().ThrowExactly <ArgumentException>(); mixedCompareAct2.Should().ThrowExactly <ArgumentException>(); objectCompareAct.Should().ThrowExactly <ArgumentException>(); nullCompare.Should().Be(1); }