public void TestAdd() { Random r = new Random(); int num1 = r.Next(-100, 100); int num2 = r.Next(-100, 100); Number n1 = new DecimalNumber(num1.ToString()); Number n2 = new DecimalNumber(num2.ToString()); Number sum = n1.AddToCurrent(n2); Assert.AreEqual((num1 + num2).ToString(), con.Add(n1, n2)); Assert.AreEqual((num1 + num2).ToString(), sum.ToString()); Number n3 = n1.ToAnotherSystem(Bases.Binary); Number n4 = n2.ToAnotherSystem(Bases.Binary); string s = sum.ToAnotherSystem(Bases.Binary).ToString(); Assert.AreEqual(n3.AddToCurrent(n4).ToAnotherSystem(Bases.Binary).ToString(), s); }
public void TestRevers() { Random r = new Random(); long num1 = r.Next(1, 1000); long num2 = r.Next(1, 1000); Number n1 = new DecimalNumber(num1.ToString()); Number n2 = new DecimalNumber(num2.ToString()); Assert.AreEqual(n1.ReturnRevers().ToString(), (-1 * num1).ToString()); Assert.AreEqual(n2.ReturnRevers().ToString(), (-1 * num2).ToString()); n1 = n1.ToAnotherSystem(Bases.Hex); n2 = n2.ToAnotherSystem(Bases.Hex); Assert.AreEqual(n1.ReturnRevers().ToString(), '-' + Convert.ToString(long.Parse(num1.ToString()), 16).ToUpper()); Assert.AreEqual(n2.ReturnRevers().ToString(), '-' + Convert.ToString(long.Parse(num2.ToString()), 16).ToUpper()); n1 = n1.ToAnotherSystem(Bases.Binary); n2 = n2.ToAnotherSystem(Bases.Binary); Assert.AreEqual(n1.ReturnRevers().ToString(), '-' + Convert.ToString(long.Parse(num1.ToString()), 2)); Assert.AreEqual(n2.ReturnRevers().ToString(), '-' + Convert.ToString(long.Parse(num2.ToString()), 2)); }
public void TestSub() { Random r = new Random(); int num1 = r.Next(-100, 100); int num2 = r.Next(-100, 100); Number n1 = new DecimalNumber(num1.ToString()); Number n2 = new DecimalNumber(num2.ToString()); Number sub = n1.SubFromCurrent(n2); Number sub2 = n2.SubFromCurrent(n1); Assert.AreEqual((num1 - num2).ToString(), con.Sub(n1, n2)); Assert.AreEqual((num2 - num1).ToString(), con.Sub(n2, n1)); Number n3 = n1.ToAnotherSystem(Bases.Binary); Number n4 = n2.ToAnotherSystem(Bases.Binary); string s = sub.ToAnotherSystem(Bases.Binary).ToString(); Assert.AreEqual(n3.SubFromCurrent(n4).ToAnotherSystem(Bases.Binary).ToString(), s); s = sub2.ToAnotherSystem(Bases.Binary).ToString(); Assert.AreEqual(n4.SubFromCurrent(n3).ToAnotherSystem(Bases.Binary).ToString(), s); }
public void TestTranslation9() { string expected = "10000000000"; DecimalNumber DN1 = new DecimalNumber("1024"); string correct = DN1.ToAnotherSystem(Bases.Binary).ToString(); Assert.AreEqual(expected.ToString(), correct, "Перевод из 10-ой в 2-ую корректен"); }
public void TestTranslation8() { string expected = "200"; DecimalNumber DN1 = new DecimalNumber("512"); string correct = DN1.ToAnotherSystem(Bases.Hex).ToString(); Assert.AreEqual(expected.ToString(), correct, "Перевод из 10-ой в 16-ую корректен"); }
public void TestTranslation() { Random r = new Random(); long num1 = r.Next(-1000, 1000); string n2; if (num1.ToString().Contains("-")) n2 = '-' + new DecimalNumber(num1.ToString().Remove(0,1)).ToAnotherSystem(Bases.Hex).ToString(); else n2 = new DecimalNumber(num1.ToString()).ToAnotherSystem(Bases.Hex).ToString(); Assert.AreEqual(con.ToAnotherSystem(num1.ToString(), Bases._Decimal, Bases.Hex), n2.ToString()); if (num1.ToString().Contains("-")) n2 = '-' + new DecimalNumber(num1.ToString().Remove(0, 1)).ToAnotherSystem(Bases.Binary).ToString(); else n2 = new DecimalNumber(num1.ToString()).ToAnotherSystem(Bases.Binary).ToString(); Assert.AreEqual(con.ToAnotherSystem(num1.ToString(), Bases._Decimal, Bases.Binary), n2.ToString()); string n3; if (!num1.ToString().Contains("-")) n3 = Convert.ToString(long.Parse(num1.ToString()), 16).ToUpper(); else n3 = '-'+ Convert.ToString(long.Parse(num1.ToString().Remove(0, 1)), 16).ToUpper(); if (n3.Contains("-")) n2 = '-' + new HexNumber(n3.Remove(0, 1)).ToAnotherSystem(Bases.Binary).ToString(); else n2 = new HexNumber(n3).ToAnotherSystem(Bases.Binary).ToString(); Assert.AreEqual(con.ToAnotherSystem(n3, Bases.Hex, Bases.Binary), n2); }
public void TestSumDec() { int expected = 9; DecimalNumber DN1 = new DecimalNumber("5"); DecimalNumber DN2 = new DecimalNumber("4"); string correct = DN1.AddToCurrent(DN2).ToString(); Assert.AreEqual(expected.ToString(), correct, "Sum 2 decimal are correctly"); }
public void TestSubDec() { int expected = 1; DecimalNumber DN1 = new DecimalNumber("5"); DecimalNumber DN2 = new DecimalNumber("4"); string correct = DN1.SubFromCurrent(DN2).ToString(); Assert.AreEqual(expected.ToString(), correct, "Minus 2 decimal are correctly"); }