本文整理汇总了C#中Rational.ToSimpleString方法的典型用法代码示例。如果您正苦于以下问题:C# Rational.ToSimpleString方法的具体用法?C# Rational.ToSimpleString怎么用?C# Rational.ToSimpleString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rational
的用法示例。
在下文中一共展示了Rational.ToSimpleString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestToSimpleString
public void TestToSimpleString()
{
var third1 = new Rational(1, 3);
var third2 = new Rational(2, 6);
Assert.Equal("1/3", third1.ToSimpleString());
Assert.Equal("1/3", third2.ToSimpleString());
Assert.Equal(third1, third2);
var twoThirds = new Rational(10, 15);
Assert.Equal("2/3", twoThirds.ToSimpleString());
var two = new Rational(10, 5);
Assert.True(two.IsInteger);
Assert.Equal("2", two.ToSimpleString());
Assert.Equal("2", two.ToSimpleString(allowDecimal: false));
var twoFifths = new Rational(4, 10);
Assert.Equal("0.4", twoFifths.ToSimpleString());
Assert.Equal("2/5", twoFifths.ToSimpleString(allowDecimal: false));
var threeEighths = new Rational(3, 8);
Assert.Equal("3/8", threeEighths.ToSimpleString());
var zero = new Rational(0, 8);
Assert.True(zero.IsInteger);
Assert.Equal("0", zero.ToSimpleString());
Assert.Equal("0", zero.ToSimpleString(allowDecimal: false));
zero = new Rational(0, 0);
Assert.True(zero.IsInteger);
Assert.Equal("0", zero.ToSimpleString());
Assert.Equal("0", zero.ToSimpleString(allowDecimal: false));
}