public void ArbitraryNumber_HasIntegerAndFractionalParts() { var an = new ArbitraryNumber(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 4); Assert.That(an.IntegerPart, Is.EquivalentTo(new[] { 1, 2, 3, 4, 5 })); Assert.That(an.FractionalPart, Is.EquivalentTo(new[] { 6, 7, 8, 9 })); }
public void ArbitraryNumber_ExplicitCast_ToInt_ReturnsRightArbitraryNumber(int[] digits, int decimalCount, bool isNegative, int expectedOutput) { var an = new ArbitraryNumber(digits, decimalCount, isNegative); int i = (int)an; Assert.That(i, Is.EqualTo(expectedOutput)); }
public void ArbitraryNumber_ImplicitCast_FromInt_ReturnsRightArbitraryNumber(int origin, int[] digits, int decimalCount, bool isNegative) { ArbitraryNumber an = origin; Assert.That(an.Digits, Is.EquivalentTo(digits)); Assert.That(an.DecimalsCount, Is.EqualTo(decimalCount)); Assert.That(an.IsNegative, Is.EqualTo(isNegative)); }
public void ArbitraryNumber_NewInstance_WithNullArbitraryNumber_IsZero() { var an = new ArbitraryNumber(null); Assert.That(an.Digits, Is.EquivalentTo(new int[0])); Assert.That(an.DecimalsCount, Is.Zero); Assert.That(an.IsNegative, Is.False); }
public void Operations_Pow_WithPositiveIntegerExponent_ReturnsNewCorrectArbitraryNumber(int[] digits, int decimalCount, bool isNegative, int power, int[] expectedDigits, int expectedDecimalCount, bool expectedIsNegative) { var an = new ArbitraryNumber(digits, decimalCount, isNegative); ArbitraryNumber result = an.Pow(power); Assert.That(result.Digits, Is.EquivalentTo(expectedDigits)); Assert.That(result.DecimalsCount, Is.EqualTo(expectedDecimalCount)); Assert.That(result.IsNegative, Is.EqualTo(expectedIsNegative)); }
public void Operations_Mult_WithInteger_ReturnsNewCorrectArbitraryNumber(int factor, int[] digits, int decimalCount, bool isNegative) { var an = new ArbitraryNumber(new[] { 1, 5, 7, 4, 1, 2, 3, 6, 5 }, 4); ArbitraryNumber result = an * factor; Assert.That(result.Digits, Is.EquivalentTo(digits)); Assert.That(result.DecimalsCount, Is.EqualTo(decimalCount)); Assert.That(result.IsNegative, Is.EqualTo(isNegative)); }
public void Operations_Mult_WithArbitraryNumbers_ReturnsNewCorrectArbitraryNumber(int[] digits1, int decimalCount1, bool isNegative1, int[] digits2, int decimalCount2, bool isNegative2, int[] expectedDigits, int excpectedDecimalCount, bool expectedIsNegative) { var an1 = new ArbitraryNumber(digits1, decimalCount1); var an2 = new ArbitraryNumber(digits2, decimalCount2); ArbitraryNumber result = an1 * an2; Assert.That(result.Digits, Is.EquivalentTo(expectedDigits)); Assert.That(result.DecimalsCount, Is.EqualTo(excpectedDecimalCount)); Assert.That(result.IsNegative, Is.EqualTo(expectedIsNegative)); }
public void Operations_Add_WithPositiveArbitraryNumbers_ReturnsNewCorrectArbitraryNumber() { var an1 = new ArbitraryNumber(new[] { 1, 5, 7, 4, 1, 2, 3, 6, 5 }, 4); var an2 = new ArbitraryNumber(new[] { 9, 5, 6, 3, 1, 2 }, 2); ArbitraryNumber result = an1 + an2; Assert.That(result.Digits, Is.EquivalentTo(new[] { 2, 5, 3, 0, 4, 3, 5, 6, 5 })); Assert.That(result.IntegerPart, Is.EquivalentTo(new[] { 2, 5, 3, 0, 4 })); Assert.That(result.FractionalPart, Is.EquivalentTo(new[] { 3, 5, 6, 5 })); }
public void Operations_Sub_WithPositiveArbitraryNumbers_ReturnsNewCorrectArbitraryNumber() { var an1 = new ArbitraryNumber(new[] { 1, 5, 7, 4, 1, 2, 3, 6, 5 }, 4); var an2 = new ArbitraryNumber(new[] { 9, 5, 6, 3, 1, 2 }, 2); ArbitraryNumber result = an1 - an2; Assert.That(result.IsNegative, Is.False); Assert.That(result.Digits, Is.EquivalentTo(new[] { 6, 1, 7, 8, 1, 1, 6, 5 })); Assert.That(result.IntegerPart, Is.EquivalentTo(new[] { 6, 1, 7, 8 })); Assert.That(result.FractionalPart, Is.EquivalentTo(new[] { 1, 1, 6, 5 })); }