public void BasicComparisonTests() { Rational r1 = new Rational(-3, 6); Rational r2 = new Rational(2, 4); Rational r3 = new Rational(1, 2); Assert.IsTrue(r1.CompareTo(r2) < 0); Assert.IsTrue(r2.CompareTo(r1) > 0); Assert.IsTrue(r2.CompareTo(r3) == 0); }
public void TestConstructor() { Note n = new Note(0, 0, new Rational(1, 4)); Rational r = n.GetDuration(); Assert.IsTrue(r.CompareTo(new Rational(1, 4)) == 0); }
public bool AddNote(Note note) { Rational currentLength = Length(); Rational newLength = currentLength.Add(note.GetDuration()); if (newLength.CompareTo(duration) > 0) { return(false); } else { voice.Add(note); return(true); } }
public static void Main() { ShowParse("-12/30"); ShowParse("123"); ShowParse("1.125"); Rational f = new Rational(6, -10); Console.WriteLine("6/(-10) simplifies to {0}", f); Console.WriteLine("reciprocal of {0} is {1}", f, f.Reciprocal()); Console.WriteLine("{0} negated is {1}", f, f.Negate()); Rational h = new Rational(1, 2); Console.WriteLine("{0} + {1} is {2}", f, h, f.Add(h)); Console.WriteLine("{0} - {1} is {2}", f, h, f.Subtract(h)); Console.WriteLine("{0} * {1} is {2}", f, h, f.Multiply(h)); Console.WriteLine("({0}) / ({1}) is {2}", f, h, f.Divide(h)); Console.WriteLine("{0} > {1} ? {2}", h, f, (h.CompareTo(f) > 0)); Console.WriteLine("{0} as a double is {1}", f, f.ToDouble()); Console.WriteLine("{0} as a decimal is {1}", h, h.ToDecimal()); }