public void Test_Constructor() { SignedRational rational = new SignedRational(7, -55); Assert.AreEqual(7, rational.Numerator); Assert.AreEqual(-55, rational.Denominator); rational = new SignedRational(-755, 100); Assert.AreEqual(-151, rational.Numerator); Assert.AreEqual(20, rational.Denominator); rational = new SignedRational(-755, -100, false); Assert.AreEqual(-755, rational.Numerator); Assert.AreEqual(-100, rational.Denominator); rational = new SignedRational(-151, -20); Assert.AreEqual(-151, rational.Numerator); Assert.AreEqual(-20, rational.Denominator); rational = new SignedRational(-7.55); Assert.AreEqual(-151, rational.Numerator); Assert.AreEqual(20, rational.Denominator); rational = new SignedRational(7); Assert.AreEqual(7, rational.Numerator); Assert.AreEqual(1, rational.Denominator); }
public void Test_ToDouble() { SignedRational rational = new SignedRational(0, 0); Assert.AreEqual(double.NaN, rational.ToDouble()); rational = new SignedRational(2, 0); Assert.AreEqual(double.PositiveInfinity, rational.ToDouble()); rational = new SignedRational(-2, 0); Assert.AreEqual(double.NegativeInfinity, rational.ToDouble()); }
public void ShouldReturnTheCorrectValue() { var rational = new SignedRational(0, 1); Assert.Equal("0", rational.ToString()); rational = new SignedRational(-2, 1); Assert.Equal("-2", rational.ToString()); rational = new SignedRational(-1, 2); Assert.Equal("-1/2", rational.ToString()); }
public void ExifSignedRationalTests(ExifTag tag) { var expected = new SignedRational(21, 42); ExifValue value = ExifValues.Create(tag); Assert.False(value.TrySetValue(expected.ToString())); Assert.True(value.TrySetValue(expected)); var typed = (ExifSignedRational)value; Assert.Equal(expected, typed.Value); }
public void Test_ToDouble() { SignedRational rational = new SignedRational(0, 0); Assert.AreEqual(double.NaN, rational.ToDouble()); rational = new SignedRational(2, 0); Assert.AreEqual(double.PositiveInfinity, rational.ToDouble()); rational = new SignedRational(-2, 0); Assert.AreEqual(double.NegativeInfinity, rational.ToDouble()); }
public void AreEqual() { SignedRational r1 = new SignedRational(3, 2); SignedRational r2 = new SignedRational(3, 2); Assert.Equal(r1, r2); Assert.True(r1 == r2); SignedRational r3 = new SignedRational(7.55); SignedRational r4 = new SignedRational(755, 100); SignedRational r5 = new SignedRational(151, 20); Assert.Equal(r3, r4); Assert.Equal(r4, r5); }
private bool TrySetSignedArray(SignedRational[] signed) { if (Array.FindIndex(signed, x => x.Numerator < 0 || x.Denominator < 0) > -1) { return(false); } var unsigned = new Rational[signed.Length]; for (int i = 0; i < signed.Length; i++) { SignedRational s = signed[i]; unsigned[i] = new Rational((uint)s.Numerator, (uint)s.Denominator); } this.Value = unsigned; return(true); }
public void Test_IEquatable() { SignedRational first = new SignedRational(3, 2); Assert.IsFalse(first.Equals(null)); Assert.IsTrue(first.Equals(first)); Assert.IsTrue(first.Equals((object)first)); SignedRational second = new SignedRational(3, 2); Assert.IsTrue(first == second); Assert.IsTrue(first.Equals(second)); Assert.IsTrue(first.Equals((object)second)); second = new SignedRational(2, 3); Assert.IsTrue(first != second); Assert.IsFalse(first.Equals(second)); }
public void Test_IEquatable() { SignedRational first = new SignedRational(3, 2); Assert.IsFalse(first.Equals(null)); Assert.IsTrue(first.Equals(first)); Assert.IsTrue(first.Equals((object)first)); SignedRational second = new SignedRational(3, 2); Assert.IsTrue(first == second); Assert.IsTrue(first.Equals(second)); Assert.IsTrue(first.Equals((object)second)); second = new SignedRational(2, 3); Assert.IsTrue(first != second); Assert.IsFalse(first.Equals(second)); }
public void ToStringRepresention() { SignedRational rational = new SignedRational(0, 0); Assert.Equal("[ Indeterminate ]", rational.ToString()); rational = new SignedRational(double.PositiveInfinity); Assert.Equal("[ PositiveInfinity ]", rational.ToString()); rational = new SignedRational(double.NegativeInfinity); Assert.Equal("[ NegativeInfinity ]", rational.ToString()); rational = new SignedRational(0, 1); Assert.Equal("0", rational.ToString()); rational = new SignedRational(2, 1); Assert.Equal("2", rational.ToString()); rational = new SignedRational(1, 2); Assert.Equal("1/2", rational.ToString()); }
public void Test_ToString() { SignedRational rational = new SignedRational(0, 0); Assert.AreEqual("Indeterminate", rational.ToString()); rational = new SignedRational(double.PositiveInfinity); Assert.AreEqual("PositiveInfinity", rational.ToString()); rational = new SignedRational(double.NegativeInfinity); Assert.AreEqual("NegativeInfinity", rational.ToString()); rational = new SignedRational(0, 1); Assert.AreEqual("0", rational.ToString()); rational = new SignedRational(2, 1); Assert.AreEqual("2", rational.ToString()); rational = new SignedRational(1, 2); Assert.AreEqual("1/2", rational.ToString()); }
public void ToString_ReturnsReadableString(int numerator, int denominator, string str) { var rational = new SignedRational(numerator, denominator); Assert.Equal(str, rational.ToString()); }
public void ShouldReturnNegativeInfinityWhenDenominatorIsZeroAndValueIsNegative() { var rational = new SignedRational(-2, 0); Assert.Equal(double.NegativeInfinity, rational.ToDouble()); }
public void ShouldReturnPositiveInfinityWhenDenominatorIsZero() { var rational = new SignedRational(2, 0); Assert.Equal(double.PositiveInfinity, rational.ToDouble()); }
public void ShouldReturnNanWhenNumeratorIsZero() { var rational = new SignedRational(0, 0); Assert.Equal(double.NaN, rational.ToDouble()); }
public void ShouldReturnNegativeInfinityWhenValueIsNegativeInfinity() { var rational = new SignedRational(double.NegativeInfinity); Assert.Equal("NegativeInfinity", rational.ToString()); }
private static int WriteSignedRational(SignedRational value, byte[] destination, int offset) { Write(BitConverter.GetBytes(value.Numerator), destination, offset); Write(BitConverter.GetBytes(value.Denominator), destination, offset + 4); return offset + 8; }
public void ShouldReturnTrueWhenObjectIsTheSame() { var density = new SignedRational(-3, 2); Assert.True(density.Equals((object)density)); }
public void ShouldReturnTrueWhenInstanceIsTheSame() { var density = new SignedRational(-3, 2); Assert.True(density.Equals(density)); }
public void ShouldReturnFalseWhenInstanceIsNull() { var density = new SignedRational(-3, 2); Assert.False(density.Equals(null)); }
public void Test_ToString() { SignedRational rational = new SignedRational(0, 0); Assert.AreEqual("Indeterminate", rational.ToString()); rational = new SignedRational(double.PositiveInfinity); Assert.AreEqual("PositiveInfinity", rational.ToString()); rational = new SignedRational(double.NegativeInfinity); Assert.AreEqual("NegativeInfinity", rational.ToString()); rational = new SignedRational(0, 1); Assert.AreEqual("0", rational.ToString()); rational = new SignedRational(2, 1); Assert.AreEqual("2", rational.ToString()); rational = new SignedRational(1, 2); Assert.AreEqual("1/2", rational.ToString()); }
public void ShouldReturnPositiveInfinityWhenValueIsNan() { var rational = new SignedRational(double.NaN); Assert.Equal("Indeterminate", rational.ToString()); }
public void Test_Fraction() { SignedRational first = new SignedRational(1.0 / 1600); SignedRational second = new SignedRational(1.0 / 1600, true); Assert.IsFalse(first.Equals(second)); }
private static void TestValue(ExifValue value, SignedRational expected) { Assert.NotNull(value); Assert.Equal(expected, value.Value); }
public void ShouldReturnPositiveInfinityWhenValueIsPositiveInfinity() { var rational = new SignedRational(double.PositiveInfinity); Assert.AreEqual("PositiveInfinity", rational.ToString()); }