public void TestReferenceEquals() { var z = new ComplexNumber(1, 2); // ReSharper disable EqualExpressionComparison (z == z).ShouldBeTrue(); // ReSharper restore EqualExpressionComparison }
public void TestEqualityNull() { var z = new ComplexNumber(1, 2); // ReSharper disable ConditionIsAlwaysTrueOrFalse (z == null).ShouldBeFalse(); // ReSharper restore ConditionIsAlwaysTrueOrFalse }
public void TestNotEquals() { var z = new ComplexNumber(1, 2); var w = new ComplexNumber(1, 2); var x = new ComplexNumber(3, 2); (z != x).ShouldBeTrue(); (z != w).ShouldBeFalse(); }
public void ComplexNumberHashcodeShouldBeAsExpected() { var z = new ComplexNumber(1, 2); z.GetHashCode().ShouldEqual(z.Re.GetHashCode() ^ z.Im.GetHashCode()); }
public ComplexNumber Product(ComplexNumber w) { return new ComplexNumber(X * w.X - Y * w.Y, X * w.Y + Y * w.X); }
protected bool Equals(ComplexNumber other) { // ReSharper disable CompareOfFloatsByEqualityOperator return Re == other.Re && Im == other.Im; // ReSharper restore CompareOfFloatsByEqualityOperator }