public void TestTranslation5() { string expected = "1010"; HexNumber HN1 = new HexNumber("A"); string correct = HN1.ToAnotherSystem(Bases.Binary).ToString(); Assert.AreEqual(expected, correct, "Перевод из 16-ой в 2-ую корректен"); }
public void TestTranslation4() { string expected = "171"; HexNumber HN1 = new HexNumber("AB"); string correct = HN1.ToAnotherSystem(Bases._Decimal).ToString(); Assert.AreEqual(expected, correct, "Перевод из 16-ой в 10-ую корректен"); }
public void TestSumHex() { int expected = 18; HexNumber HN1 = new HexNumber("9"); HexNumber HN2 = new HexNumber("9"); string correct = HN1.AddToCurrent(HN2).ToString(); Assert.AreEqual(expected.ToString(), correct, "Sum 2 hex are correctly"); }
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 TestSubHex() { int expected = 0; HexNumber HN1 = new HexNumber("9"); HexNumber HN2 = new HexNumber("9"); string correct = HN1.SubFromCurrent(HN2).ToString(); Assert.AreEqual(expected.ToString(), correct, "Minus 2 hex are correctly"); }