public void ToStringDoesSomethingReasonable() { BigInteger n1 = BigInteger.Create(30); BigInteger d1 = BigInteger.Create(60); Ratio r1 = new Ratio(n1, d1); Expect(r1.ToString(), EqualTo("30/60")); }
public void GetsThePiecesFromTheConstructedThing() { BigInteger n = BigInteger.Create(30); BigInteger d = BigInteger.Create(60); Ratio r = new Ratio(n, d); Expect(r.numerator, SameAs(n)); Expect(r.denominator, SameAs(d)); }
public void RaionalizeWorksOnDoubles() { object r = Numbers.rationalize(0.0625); Expect(r, InstanceOf(typeof(Ratio))); Ratio rr = (Ratio)r; Ratio ratio = new Ratio(BigInteger.Create(1), BigInteger.Create(16)); Expect(rr, EqualTo(ratio)); }
public void ToBigDecimalWithNoContextAndNoRoundingRequiredWorks() { BigInteger n1 = BigInteger.Create(1); BigInteger d1 = BigInteger.Create(4); Ratio r1 = new Ratio(n1, d1); BigDecimal bd = r1.ToBigDecimal(); Expect(bd, EqualTo(BigDecimal.Parse("0.25"))); }
public void ToBigDecimalWithContextWorks() { BigInteger n1 = BigInteger.Create(1); BigInteger d1 = BigInteger.Create(3); Ratio r1 = new Ratio(n1, d1); BigDecimal.Context c = new BigDecimal.Context(6, BigDecimal.RoundingMode.HalfUp); BigDecimal bd = r1.ToBigDecimal(c); Expect(bd, EqualTo(BigDecimal.Parse("0.333333"))); }
public void RationalizeTakesFractionToBigInteger() { BigDecimal bd = BigDecimal.Parse("123.45"); object r = Numbers.rationalize(bd); Expect(r, InstanceOf(typeof(Ratio))); Ratio rr = (Ratio)r; Ratio ratio = new Ratio(BigInteger.Create(12345/5), BigInteger.Create(100/5)); Expect(rr, EqualTo(ratio)); }
public void EqualsReturnsTrueOnEquals() { BigInteger n1 = BigInteger.Create(30); BigInteger d1 = BigInteger.Create(60); Ratio r1 = new Ratio(n1, d1); BigInteger n2 = BigInteger.Create(30); BigInteger d2 = BigInteger.Create(60); Ratio r2 = new Ratio(n2, d2); Expect(r1.Equals(r2)); }
public void ToBigDecimalWithNoContextThrowsIfRoundingIsRequired() { BigInteger n1 = BigInteger.Create(1); BigInteger d1 = BigInteger.Create(3); Ratio r1 = new Ratio(n1, d1); BigDecimal bd = r1.ToBigDecimal(); }
public void ToDoubleWorks() { BigInteger n1 = BigInteger.Create(1); BigInteger d1 = BigInteger.Create(3); Ratio r1 = new Ratio(n1, d1); BigDecimal.Context c = new BigDecimal.Context(6, BigDecimal.RoundingMode.HalfUp); double d = r1.ToDouble(null); Expect(d, EqualTo(0.3333333333333333)); // precision = 16 }
public void ToDoubleWorks() { BigInteger n1 = BigInteger.Create(1); BigInteger d1 = BigInteger.Create(3); Ratio r1 = new Ratio(n1, d1); double d = r1.ToDouble(null); Expect(d, EqualTo(0.3333333333333333)); // precision = 16 }
/// <summary> /// Determines of an object is equal to this object. /// </summary> /// <param name="obj">The object to compare to.</param> /// <returns><value>true</value> if the object is equal to this object; <value>false</value> otherwise.</returns> public override bool Equals(object obj) { Ratio r = obj as Ratio; return(r != null && r._numerator.Equals(_numerator) && r._denominator.Equals(_denominator)); }