public UnfixedAnyInteger Convert(UnfixedDecInteger dec, NumberBases numType) { string output = FromDecIntConversionPos(dec.StoredNumber, (int)numType); UnfixedAnyInteger any = new UnfixedAnyInteger(numType, output); return any; }
public void Initialization_TEST() { UnfixedDecInteger dec = new UnfixedDecInteger(""); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec = new UnfixedDecInteger(0); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec = new UnfixedDecInteger(5); Assert.AreEqual("5", dec.StoredInput); Assert.AreEqual(5, dec.StoredNumber); dec = new UnfixedDecInteger("A"); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec = new UnfixedDecInteger("Abc"); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec = new UnfixedDecInteger("255"); Assert.AreEqual("255", dec.StoredInput); Assert.AreEqual(255, dec.StoredNumber); dec = new UnfixedDecInteger(255); Assert.AreEqual("255", dec.StoredInput); Assert.AreEqual(255, dec.StoredNumber); dec = new UnfixedDecInteger("-2"); Assert.AreEqual("2", dec.StoredInput); Assert.AreEqual(2, dec.StoredNumber); }
public UnfixedDecInteger Convert(UnfixedPowOfTwoInteger input) { int numberBase = (int)input.GetNumberBase(); uint result = SetUpConvert(input, numberBase); UnfixedDecInteger output = new UnfixedDecInteger(result); return output; }
public UnfixedDecInteger Convert(UnfixedBinInteger input) { uint result = SetUpConvert(input, (int)NumberBases.BASE_TWO); UnfixedDecInteger output = new UnfixedDecInteger(result); return output; }
public void DeleteChar_TEST() { UnfixedDecInteger dec = new UnfixedDecInteger(""); dec.DeleteCharFromBack(); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec.StoredInput = "5"; dec.DeleteCharFromBack(); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec.StoredNumber = 256; dec.DeleteCharFromBack(); Assert.AreEqual("25", dec.StoredInput); Assert.AreEqual(25, dec.StoredNumber); }
public void ClearInput_TEST() { UnfixedDecInteger dec = new UnfixedDecInteger(""); dec.ClearInput(); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec.StoredInput = "5"; dec.ClearInput(); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec.StoredNumber = 256; dec.ClearInput(); Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); }
public void ConvertDecToBin() { UnfixedDecInteger dec = new UnfixedDecInteger(0); ConverterToAny converter = new ConverterToAny(); UnfixedAnyInteger any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("0", any.StoredInput); dec.StoredNumber = 1; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("1", any.StoredInput); dec.StoredNumber = 2; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("10", any.StoredInput); dec.StoredNumber = 3; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("11", any.StoredInput); dec.StoredNumber = 4; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("100", any.StoredInput); dec.StoredNumber = 8; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("1000", any.StoredInput); dec.StoredNumber = 15; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("1111", any.StoredInput); dec.StoredNumber = 16; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("10000", any.StoredInput); dec.StoredNumber = 32; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("100000", any.StoredInput); dec.StoredNumber = 41; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("101001", any.StoredInput); dec.StoredNumber = 170; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("10101010", any.StoredInput); dec.StoredNumber = 255; any = converter.Convert(dec, NumberBases.BASE_TWO); Assert.AreEqual("11111111", any.StoredInput); }
public void AddChar_TEST() { UnfixedDecInteger dec = new UnfixedDecInteger(""); dec.AddChar('2'); Assert.AreEqual("2", dec.StoredInput); Assert.AreEqual(2, dec.StoredNumber); dec.AddChar('5'); Assert.AreEqual("25", dec.StoredInput); Assert.AreEqual(25, dec.StoredNumber); dec.DeleteCharFromBack(); dec.AddChar('5'); Assert.AreEqual("25", dec.StoredInput); Assert.AreEqual(25, dec.StoredNumber); dec.StoredInput = "12"; dec.AddChar('8'); Assert.AreEqual("128", dec.StoredInput); Assert.AreEqual(128, dec.StoredNumber); dec.StoredNumber = 6; dec.AddChar('8'); Assert.AreEqual("68", dec.StoredInput); Assert.AreEqual(68, dec.StoredNumber); }
public static Tuple<uint, bool> VerifyInput(string input, UnfixedDecInteger dec) { return VerifyInput(input, dec.StoredNumber, dec.StoredInput == null); }
public void SetStoredInput_TEST() { UnfixedDecInteger dec = new UnfixedDecInteger(""); dec.StoredInput = "5"; Assert.AreEqual("5", dec.StoredInput); Assert.AreEqual(5, dec.StoredNumber); dec.StoredNumber = 0; Assert.AreEqual("0", dec.StoredInput); Assert.AreEqual(0, dec.StoredNumber); dec.StoredInput = "256"; Assert.AreEqual("256", dec.StoredInput); Assert.AreEqual(256, dec.StoredNumber); dec.StoredInput = "AAA"; Assert.AreEqual("256", dec.StoredInput); Assert.AreEqual(256, dec.StoredNumber); dec.StoredInput = "-2"; Assert.AreEqual("2", dec.StoredInput); Assert.AreEqual(2, dec.StoredNumber); }
//TO DO: Add back once PowOfTwoInteger is adjusted //public BinInt Convert(PowOfTwoInteger input) //{ // int bitNumber = input.allowedNumberOfBits; // NumberBases baseChoice = input.GetNumberBase(); // string storedInput = input.storedInput; // string result = FromPowerOfTwoIntPos(storedInput, baseChoice); // BinInteger output = new BinInteger(bitNumber, result); // return output; //} public UnfixedBinInteger Convert(UnfixedDecInteger input) { return UDecToUBin(input); }
private UnfixedBinInteger UDecToUBin(UnfixedDecInteger udec) { ConverterToAny converterAny = new ConverterToAny(); UnfixedAnyInteger any = converterAny.Convert(udec, NumberBases.BASE_TWO); UnfixedBinInteger ubin = new UnfixedBinInteger(any.StoredInput); return ubin; }
public void ConvertFromUnfixedBin() { uDec = converter.Convert(uBin); Assert.AreEqual("0", uDec.StoredInput); uBin.StoredInput = "1"; uDec = converter.Convert(uBin); Assert.AreEqual("1", uDec.StoredInput); uBin.StoredInput = "10"; uDec = converter.Convert(uBin); Assert.AreEqual("2", uDec.StoredInput); uBin.StoredInput = "11"; uDec = converter.Convert(uBin); Assert.AreEqual("3", uDec.StoredInput); uBin.StoredInput = "100"; uDec = converter.Convert(uBin); Assert.AreEqual("4", uDec.StoredInput); uBin.StoredInput = "1000"; uDec = converter.Convert(uBin); Assert.AreEqual("8", uDec.StoredInput); uBin.StoredInput = "10000"; uDec = converter.Convert(uBin); Assert.AreEqual("16", uDec.StoredInput); uBin.StoredInput = "11111"; uDec = converter.Convert(uBin); Assert.AreEqual("31", uDec.StoredInput); uBin.StoredInput = "100000"; uDec = converter.Convert(uBin); Assert.AreEqual("32", uDec.StoredInput); uBin.StoredInput = "10101010"; uDec = converter.Convert(uBin); Assert.AreEqual("170", uDec.StoredInput); uBin.StoredInput = "101001"; uDec = converter.Convert(uBin); Assert.AreEqual("41", uDec.StoredInput); uBin.StoredInput = "11111111"; uDec = converter.Convert(uBin); Assert.AreEqual("255", uDec.StoredInput); uBin.StoredInput = "100000000"; uDec = converter.Convert(uBin); Assert.AreEqual("256", uDec.StoredInput); uBin.StoredInput = "1000000000"; uDec = converter.Convert(uBin); Assert.AreEqual("512", uDec.StoredInput); }
public void ConvertFromUnfixedOct() { uDec = converter.Convert(oct); Assert.AreEqual("0", uDec.StoredInput); oct.StoredInput = "1"; uDec = converter.Convert(oct); Assert.AreEqual("1", uDec.StoredInput); oct.StoredInput = "5"; uDec = converter.Convert(oct); Assert.AreEqual("5", uDec.StoredInput); oct.StoredInput = "10"; uDec = converter.Convert(oct); Assert.AreEqual("8", uDec.StoredInput); oct.StoredInput = "377"; uDec = converter.Convert(oct); Assert.AreEqual("255", uDec.StoredInput); }
public void ConvertFromUnfixedHex() { uDec = converter.Convert(hex); Assert.AreEqual("0", uDec.StoredInput); hex.StoredInput = "1"; uDec = converter.Convert(hex); Assert.AreEqual("1", uDec.StoredInput); hex.StoredInput = "2"; uDec = converter.Convert(hex); Assert.AreEqual("2", uDec.StoredInput); hex.StoredInput = "5"; uDec = converter.Convert(hex); Assert.AreEqual("5", uDec.StoredInput); hex.StoredInput = "A"; uDec = converter.Convert(hex); Assert.AreEqual("10", uDec.StoredInput); hex.StoredInput = "B"; uDec = converter.Convert(hex); Assert.AreEqual("11", uDec.StoredInput); hex.StoredInput = "c"; uDec = converter.Convert(hex); Assert.AreEqual("12", uDec.StoredInput); hex.StoredInput = "d"; uDec = converter.Convert(hex); Assert.AreEqual("13", uDec.StoredInput); hex.StoredInput = "E"; uDec = converter.Convert(hex); Assert.AreEqual("14", uDec.StoredInput); hex.StoredInput = "f"; uDec = converter.Convert(hex); Assert.AreEqual("15", uDec.StoredInput); hex.StoredInput = "10"; uDec = converter.Convert(hex); Assert.AreEqual("16", uDec.StoredInput); hex.StoredInput = "ff"; uDec = converter.Convert(hex); Assert.AreEqual("255", uDec.StoredInput); }