public void Initialization_TEST()
 {
     UnfixedPowOfTwoInteger hex;
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN);
     Assert.AreEqual("0", hex.StoredInput);
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "000");
     Assert.AreEqual("000", hex.StoredInput);
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "ABC");
     Assert.AreEqual("ABC", hex.StoredInput);
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "abc");
     Assert.AreEqual("abc", hex.StoredInput);
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "-dec");
     Assert.AreEqual("0", hex.StoredInput);
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "123");
     Assert.AreEqual("123", hex.StoredInput);
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "a123");
     Assert.AreEqual("a123", hex.StoredInput);
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "00123");
     Assert.AreEqual("00123", hex.StoredInput);
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "abcg");
     Assert.AreEqual("0", hex.StoredInput);
     UnfixedPowOfTwoInteger oct;
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT);
     Assert.AreEqual("0", oct.StoredInput);
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT,"1");
     Assert.AreEqual("1", oct.StoredInput);
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT, "56");
     Assert.AreEqual("56", oct.StoredInput);
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT, "48");
     Assert.AreEqual("0", oct.StoredInput);
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT, "10");
     Assert.AreEqual("10", oct.StoredInput);
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT, "9");
     Assert.AreEqual("0", oct.StoredInput);
 }
 public void ConvertUnsignedHex()
 {
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN, "");
     hex.StoredInput = "4";
     ubin = converter.Convert(hex);
     Assert.AreEqual("100", ubin.StoredInput);
     hex.StoredInput = "8";
     ubin = converter.Convert(hex);
     Assert.AreEqual("1000", ubin.StoredInput);
     hex.StoredInput = "A";
     ubin = converter.Convert(hex);
     Assert.AreEqual("1010", ubin.StoredInput);
     hex.StoredInput = "b";
     ubin = converter.Convert(hex);
     Assert.AreEqual("1011", ubin.StoredInput);
     hex.StoredInput = "C";
     ubin = converter.Convert(hex);
     Assert.AreEqual("1100", ubin.StoredInput);
     hex.StoredInput = "d";
     ubin = converter.Convert(hex);
     Assert.AreEqual("1101", ubin.StoredInput);
     hex.StoredInput = "56";
     ubin = converter.Convert(hex);
     Assert.AreEqual("1010110", ubin.StoredInput);
     hex.StoredInput = "ef";
     ubin = converter.Convert(hex);
     Assert.AreEqual("11101111", ubin.StoredInput);
 }
 public void AddChar_TEST()
 {
     UnfixedPowOfTwoInteger hex;
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN);
     hex.AddChar('0');
     Assert.AreEqual("00", hex.StoredInput);
     hex.AddChar('A');
     Assert.AreEqual("00A", hex.StoredInput);
     hex.StoredInput = "5";
     hex.AddChar('6');
     Assert.AreEqual("56", hex.StoredInput);
     hex.AddChar('-');
     Assert.AreEqual("56", hex.StoredInput);
     hex.AddChar('g');
     Assert.AreEqual("56", hex.StoredInput);
     hex.AddChar('f');
     Assert.AreEqual("56f", hex.StoredInput);
     UnfixedPowOfTwoInteger oct;
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT);
     oct.AddChar('0');
     Assert.AreEqual("00", oct.StoredInput);
     oct.StoredInput = "56";
     oct.AddChar('8');
     Assert.AreEqual("56", oct.StoredInput);
     oct.AddChar('7');
     Assert.AreEqual("567", oct.StoredInput);
 }
Exemplo n.º 4
0
        public UnfixedDecInteger Convert(UnfixedPowOfTwoInteger input)
        {
            int numberBase = (int)input.GetNumberBase();
            uint result = SetUpConvert(input, numberBase);
            UnfixedDecInteger output = new UnfixedDecInteger(result);

            return output;
        }
 public void ClearInput_TEST()
 {
     UnfixedPowOfTwoInteger hex;
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN);
     hex.ClearInput();
     Assert.AreEqual("0", hex.StoredInput);
     hex.StoredInput = "123";
     hex.ClearInput();
     Assert.AreEqual("0", hex.StoredInput);
 }
 public void DeleteChar_TEST()
 {
     UnfixedPowOfTwoInteger hex;
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN);
     hex.DeleteCharFromBack();
     Assert.AreEqual("0", hex.StoredInput);
     hex.StoredInput = "123";
     hex.DeleteCharFromBack();
     Assert.AreEqual("12", hex.StoredInput);
     hex.DeleteCharFromBack();
     Assert.AreEqual("1", hex.StoredInput);
 }
Exemplo n.º 7
0
        public UnfixedBinInteger Convert(UnfixedPowOfTwoInteger input)
        {
            //string toBeConverted = input.StoredInput;
            //NumberBases numberBase = input.GetNumberBase();

            //string result = FromPowerOfTwoIntPos(toBeConverted, numberBase);

            //UnfixedBinInteger bin = new UnfixedBinInteger(result);
            //return bin;

            ConverterToDec converter = new ConverterToDec();
            UnfixedDecInteger udec = converter.Convert(input);
            UnfixedBinInteger ubin = UDecToUBin(udec);

            return ubin;
        }
 public void SetStoredInput_TEST()
 {
     UnfixedPowOfTwoInteger hex;
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN);
     hex.StoredInput = "5";
     Assert.AreEqual("5", hex.StoredInput);
     hex.StoredInput = "000";
     Assert.AreEqual("000", hex.StoredInput);
     hex.StoredInput = "-5";
     Assert.AreEqual("000", hex.StoredInput);
     hex.StoredInput = "abc";
     Assert.AreEqual("abc", hex.StoredInput);
     hex.StoredInput = "abcg";
     Assert.AreEqual("abc", hex.StoredInput);
     hex.StoredInput = "56";
     Assert.AreEqual("56", hex.StoredInput);
     hex.StoredInput = "00124";
     Assert.AreEqual("00124", hex.StoredInput);
     UnfixedPowOfTwoInteger oct;
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT);
     oct.StoredInput = "00124";
     Assert.AreEqual("00124", oct.StoredInput);
     oct.StoredInput = "72";
     Assert.AreEqual("72", oct.StoredInput);
     oct.StoredInput = "-5";
     Assert.AreEqual("72", oct.StoredInput);
     oct.StoredInput = "128";
     Assert.AreEqual("72", oct.StoredInput);
 }
 public void Setup()
 {
     converter = new ConverterToDec();
     bin = new BinInt();
     uBin = new UnfixedBinInteger();
     hex = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_SIXTEEN);
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT);
 }
 public void ConvertUnsignedOct()
 {
     oct = new UnfixedPowOfTwoInteger(PowOfTwoBases.BASE_EIGHT);
     oct.StoredInput = "4";
     ubin = converter.Convert(oct);
     Assert.AreEqual("100", ubin.StoredInput);
     oct.StoredInput = "10";
     ubin = converter.Convert(oct);
     Assert.AreEqual("1000", ubin.StoredInput);
     oct.StoredInput = "42";
     ubin = converter.Convert(oct);
     Assert.AreEqual("100010", ubin.StoredInput);
     oct.StoredInput = "377";
     ubin = converter.Convert(oct);
     Assert.AreEqual("11111111", ubin.StoredInput);
 }