Example #1
0
        public void ConvertFrom_WithInvalidCharacters(string value, NumberSystem numberSystem)
        {
            // arrange

            // act - assert
            Assert.ThrowsAny <Exception>(() => NumberConversionStrategy.ConvertFrom(value, numberSystem));
        }
    public static Number Convert(string inputValue, NumberSystem inputNumberSystem, NumberSystem outputNumberSystem)
    {
        var decimalValue = ConvertNumberToDecimal(inputValue, inputNumberSystem);
        var result       = ConvertDecimalToNumberSystem(decimalValue, outputNumberSystem);

        return(result);
    }
Example #3
0
    // Start is called before the first frame update
    protected override void Start()
    {
        base.Start();

        theNS        = FindObjectOfType <NumberSystem>();
        theSR.sprite = sprites[0];
    }
    private static Number ConvertDecimalToCollapsibleNumberSystem(int decimalValue, NumberSystem outputNumberSystem)
    {
        var radix          = outputNumberSystem.Radix;
        int number         = decimalValue;
        int divisionResult = 0;
        int moduloResult   = 0;
        var result         = new List <int>();

        do
        {
            divisionResult = number / radix;
            moduloResult   = number % radix;
            result.Add(moduloResult);
            number = divisionResult;
        }while (divisionResult >= outputNumberSystem.Radix);
        if (divisionResult > 0)
        {
            result.Add(divisionResult);
        }

        var symbolList = result.Select((value, index) => outputNumberSystem.NumberAlphabet.ToSymbol(value)).ToList();

        symbolList.Reverse();
        var resultString = symbolList.Aggregate(string.Empty, (s, c) => s += c);

        return(new Number(outputNumberSystem, resultString));
    }
Example #5
0
 public static int ConvertFrom(string value, NumberSystem system)
 {
     return(system switch
     {
         NumberSystem.Roman => new RomanNumeral(value).ToInt(),
         _ => Convert.ToInt32(value, _numberSytemBaseMapping[system]),
     });
            public static string IntToString(int num, NumberSystem numberSystem, int minimumLength = 1)
            {
                var numberTable = GetNumberTable(numberSystem);

                var len = numberTable.Length;
                var n   = num;
                var sb  = new StringBuilder();

                while (true)
                {
                    // 取低位
                    var i = n % len;
                    _ = sb.Insert(0, numberTable[i]);
                    if (n < len)
                    {
                        break;
                    }

                    n /= len;
                }

                while (sb.Length < minimumLength)
                {
                    _ = sb.Insert(0, numberTable[0]);
                }

                return(sb.ToString());
            }
            public static int StringToInt(string numStr, NumberSystem numberSystem)
            {
                var numberTable = GetNumberTable(numberSystem);

                if (numberTable == null)
                {
                    throw new NotSupportedException($"找不到{numberSystem.ToString()}的算法");
                }

                var len = numberTable.Length;
                var num = 0;

                foreach (var n in numStr)
                {
                    if (num == 0)
                    {
                        num = numberTable.IndexOf(n);
                    }
                    else
                    {
                        num = (num * len) + numberTable.IndexOf(n);
                    }
                }

                return(num);
            }
    private static void Main()
    {
        NumberSystem demo = new NumberSystem();

        demo.TakeInput();
        demo.GenerateBinary();
    }
Example #9
0
    private void SetupOfflineEarnings()
    {
        CalculateTimeSpawn();

        if (timeDifference.TotalSeconds < 30)
        {
            return;                                   // so that after RewardVideo we do not open this panel
        }
        if (GameManager.In.OfflineEarningsOneSecond == 0)
        {
            return;
        }

        float limitTotalSeconds = (float)timeDifference.TotalSeconds;

        double freeOfflineEarnings = (GameManager.In.OfflineEarningsOneSecond * limitTotalSeconds) / 10f;

        string textFreeOfflineEarnings = NumberSystem.Output(freeOfflineEarnings);
        double adsOfflineEarnings      = freeOfflineEarnings * 5f;
        string textadsOfflineEarnings  = NumberSystem.Output(adsOfflineEarnings);

        textadsOfflineEarnings += "(Ads)";

        UIGetBonusCoins uiOfflineEarnings = GameManager.In.PanelOfflineEarnings.GetComponent <UIGetBonusCoins>();

        uiOfflineEarnings.FreeCoins       = freeOfflineEarnings;
        uiOfflineEarnings.AdsCoins        = adsOfflineEarnings;
        uiOfflineEarnings.FreeButton.text = "+" + textFreeOfflineEarnings;
        uiOfflineEarnings.AdsButton.text  = "+" + textadsOfflineEarnings;

        GameManager.In.PanelOfflineEarnings.SetActive(true);
    }
Example #10
0
    public void OutputProcessing() // -> SaveManager - LoadSave()
    {
        double coins = GameManager.In.Coins;

        TextCoins.text = NumberSystem.OutputTwoNumbers(coins);
        UpdateData.In.CheckAvailableUpdate();
    }
 public static Number ConvertFromDecimal(int inputValue, NumberSystem outputNumberSystem)
 {
     if (outputNumberSystem.FirstSymbolType == FirstSymbolType.One)
     {
         CheckNotZero(inputValue);
     }
     return(ConvertDecimalToNumberSystem(inputValue, outputNumberSystem));
 }
    private static int GetDecimalValueOfCharacter(NumberSystem inputNumberSystem, int index, char ch)
    {
        var radix       = inputNumberSystem.Radix;
        var coefficient = inputNumberSystem.NumberAlphabet.ToOrdinal(ch);
        var value       = coefficient * (int)Math.Pow(radix, index);

        return(value);
    }
 private void Print(NumberSystem numberSystem, int start, int end)
 {
     for (int i = start; i < end; i++)
     {
         var number = NumberConverter.ConvertFromDecimal(i, numberSystem);
         Console.WriteLine("{0,6} {1,6}  - [{2}]", i, number.Value, number.NumberSystem);
     }
 }
Example #14
0
 public Form1()
 {
     InitializeComponent();
     swapDirection  = "right";
     numSys         = new NumberSystem();
     comboBox1.Text = "Decimal";
     comboBox2.Text = "Binary";
 }
Example #15
0
 // Start is called before the first frame update
 void Start()
 {
     theDM     = FindObjectOfType <DialogueManager>();
     theOrder  = FindObjectOfType <OrderManager>();
     thePlayer = FindObjectOfType <PlayerManager>();
     theNumber = FindObjectOfType <NumberSystem>();
     event2    = FindObjectOfType <Event2Manager>();
 }
Example #16
0
 private void Print(NumberSystem numberSystem, int start, int end)
 {
     for (int i = start; i < end; i++)
     {
         var number = NumberConverter.ConvertFromDecimal(i, numberSystem);
         Console.WriteLine("{0,6} {1,6}  - [{2}]", i, number.Value, number.NumberSystem);
     }
 }
        void SegregateIntoUnitsForInteger()
        {
            if (string.IsNullOrEmpty(IntegerPartofInputNumber) == true)
            {
                IntegerPartofInputNumberText = "Zero";
            }

            string IntegerPartofInputNumberTmp = IntegerPartofInputNumber;
            int    nTotalLength       = IntegerPartofInputNumberTmp.Length;
            int    nCurrentUnitLength = nTotalLength;


            string TempNumberStr = IntegerPartofInputNumber;

            int UnitID = NumberSystem.GetUnitIDByDigitsLength(nTotalLength);

            int startIndex = 0, EndIndex = 0, ActualUnitLength = 0, ActualFullLength;

            ActualFullLength = nTotalLength;
            for (; UnitID > 0; UnitID--)
            {
                UnitMetaInfo CurrUnitMetaInfo = null;

                if (NumberSystem.GetUnitMetaInfo(UnitID, out CurrUnitMetaInfo) == false)
                {
                    throw new InvalidProgramException("");
                }

                if (startIndex == 0)
                {
                    ActualUnitLength = IntegerPartofInputNumberTmp.Length - CurrUnitMetaInfo.GetDigitsMaxLength() + CurrUnitMetaInfo.GetUnitMaxLength();
                }
                else
                {
                    ActualUnitLength = CurrUnitMetaInfo.GetUnitMaxLength();
                }

                EndIndex      = startIndex + ActualUnitLength;
                TempNumberStr = IntegerPartofInputNumberTmp.Substring(startIndex, ActualUnitLength);

                // Convert string to Integer datatype
                int TempNumber = 0;
                if (Int32.TryParse(TempNumberStr, out TempNumber) == false)
                {
                    continue;
                }

                // Check not exceed 999
                if (TempNumber != 0)
                {
                    bool IsConjuctionRequired = UnitID == 1 ? true : false;
                    IntegerPartofInputNumberText = IntegerPartofInputNumberText + NumberSystem.ToText(TempNumber, CurrUnitMetaInfo.GetUnitName(), IsConjuctionRequired);
                }
                startIndex = EndIndex;
            }
        }
Example #18
0
        public void ConvertTo_WithValidValues(int value, NumberSystem numberSystem, string expectedResult)
        {
            // arrange

            // act
            var result = NumberConversionStrategy.ConvertTo(value, numberSystem);

            // assert
            Assert.Equal(expectedResult, result);
        }
        void SegregateIntoUnitsForDecimal()
        {
            string UnitName = NumberSystem.GetCoinName();

            if (DecimalNumber > 1)
            {
                UnitName = UnitName + "S";
            }
            DecimalPartofInputNumberText = NumberSystem.ToText(DecimalNumber, UnitName, false);
        }
        public void TestCrore()
        {
            INumberToWord system       = new IndianNumberSystem();
            NumberSystem  numberSystem = new NumberSystem(system);
            string        expected     = "Fifty Two Crore Thirty Four Lakh Fifty Six Thousand Seven Hundred Eighty Nine";

            string actual = numberSystem.Convert(523456789);

            Assert.AreEqual(expected, actual, false);
        }
        public void TestZero()
        {
            INumberToWord system       = new IndianNumberSystem();
            NumberSystem  numberSystem = new NumberSystem(system);
            string        expected     = "Zero";

            string actual = numberSystem.Convert(0);

            Assert.AreEqual(expected, actual, false);
        }
        public void TestThousand1()
        {
            INumberToWord system       = new IndianNumberSystem();
            NumberSystem  numberSystem = new NumberSystem(system);
            string        expected     = "One Thousand";

            string actual = numberSystem.Convert(1000);

            Assert.AreEqual(expected, actual, false);
        }
        public void TestLakh()
        {
            INumberToWord system       = new IndianNumberSystem();
            NumberSystem  numberSystem = new NumberSystem(system);
            string        expected     = "Fifty Five Lakh Fifty Five Thousand Five Hundred Fifty Five";

            string actual = numberSystem.Convert(5555555);

            Assert.AreEqual(expected, actual, false);
        }
        public void TestNegative()
        {
            INumberToWord system       = new IndianNumberSystem();
            NumberSystem  numberSystem = new NumberSystem(system);
            string        expected     = "Negative Ninety Nine";

            string actual = numberSystem.Convert(-99);

            Assert.AreEqual(expected, actual, false);
        }
        public void TestThousand()
        {
            INumberToWord system       = new IndianNumberSystem();
            NumberSystem  numberSystem = new NumberSystem(system);
            string        expected     = "Seven Thousand One";

            string actual = numberSystem.Convert(7001);

            Assert.AreEqual(expected, actual, false);
        }
        public void TestBillion()
        {
            INumberToWord system       = new InternationalNumberSystem();
            NumberSystem  numberSystem = new NumberSystem(system);
            string        expected     = "One Hundred Two Billion Five Hundred Twenty Three Million Four Hundred Fifty Six Thousand Seven Hundred Eighty Nine";

            string actual = numberSystem.Convert(102523456789);

            Assert.AreEqual(expected, actual, false);
        }
Example #27
0
        public void GetNumberSystemErrorMessage(NumberSystem numberSystem)
        {
            // arrange

            // act
            var result = NumberConversionStrategy.GetNumberSystemErrorMessage(numberSystem);

            // assert
            Assert.Contains(numberSystem.ToString(), result);
        }
Example #28
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        theNum   = FindObjectOfType <NumberSystem>();
        theAudio = FindObjectOfType <AudioManager>();//추가

        if (theNum.GetResult())
        {
            go.SetActive(true);
            theAudio.Play(endingSong);//추가
        }
    }
    private static Number PadWithFirstSymbol(Number number, int requiredLength, NumberSystem numberSystem)
    {
        var currentValue            = number.Value;
        var currentLength           = currentValue.Length;
        var additionalCharsRequired = requiredLength - currentLength;
        var paddingSymbol           = numberSystem.NumberAlphabet.Alphabet[0];
        var padding  = new string(paddingSymbol, additionalCharsRequired);
        var newValue = padding + currentValue;

        return(new Number(numberSystem, newValue));
    }
Example #30
0
        /// <summary>
        /// Creates simulations for all parameter and temperature sweeps.
        /// </summary>
        /// <param name="statement">Statement.</param>
        /// <param name="context">Context.</param>
        /// <param name="createSimulation">Create simulation factory.</param>
        /// <returns></returns>
        public List <BaseSimulation> CreateSimulations(Control statement, ICircuitContext context, Func <string, Control, ICircuitContext, BaseSimulation> createSimulation)
        {
            var result = new List <BaseSimulation>();

            ProcessTempParameterSweep(context);

            if (context.Result.SimulationConfiguration.ParameterSweeps.Count == 0)
            {
                result.AddRange(AllTemperaturesFactory.CreateSimulations(
                                    statement,
                                    context,
                                    createSimulation));

                return(result);
            }

            List <List <double> > sweeps = new List <List <double> >();
            int productCount             = 1;

            for (var i = 0; i < context.Result.SimulationConfiguration.ParameterSweeps.Count; i++)
            {
                var sweepValues = context.Result.SimulationConfiguration.ParameterSweeps[i].Sweep.Points.ToList();
                sweeps.Add(sweepValues);
                productCount *= sweepValues.Count;
            }

            int[] system = sweeps.Select(s => s.Count()).ToArray();

            for (var i = 0; i < productCount; i++)
            {
                int[] indexes = NumberSystem.GetValueInSystem(i, system);

                Func <string, Control, ICircuitContext, BaseSimulation> createSimulationWithSweepParametersFactory =
                    (name, control, modifiedContext) =>
                {
                    List <KeyValuePair <Parameter, double> > parameterValues =
                        GetSweepParameterValues(context, sweeps, system, indexes);
                    string suffix = GetSimulationNameSuffix(parameterValues);

                    var simulation = createSimulation($"{name} ({suffix})", control, modifiedContext);
                    SetSweepSimulation(context, parameterValues, simulation);

                    return(simulation);
                };

                result.AddRange(AllTemperaturesFactory.CreateSimulations(
                                    statement,
                                    context,
                                    createSimulationWithSweepParametersFactory));
            }

            return(result);
        }
            private static string GetNumberTable(NumberSystem numberSystem)
            {
                string numberTable = null;

                switch (numberSystem)
                {
                case NumberSystem.N8:
                    numberTable = NumberTable_8;
                    break;

                case NumberSystem.N10:
                    numberTable = NumberTable_10;
                    break;

                case NumberSystem.N16:
                    numberTable = NumberTable_16;
                    break;

                case NumberSystem.N26:
                    numberTable = NumberTable_26;
                    break;

                case NumberSystem.N36:
                    numberTable = NumberTable_36;
                    break;

                case NumberSystem.N42:
                    numberTable = NumberTable_42;
                    break;

                case NumberSystem.N62:
                    numberTable = NumberTable_62;
                    break;

                case NumberSystem.Base64:
                    numberTable = NumberTable_64;
                    break;

                case NumberSystem.SafeBase64:
                    numberTable = NumberTableSafe_64;
                    break;

                case NumberSystem.N68:
                    numberTable = NumberTable_68;
                    break;

                default:
                    break;
                }

                return(numberTable);
            }
Example #32
0
 public Number(NumberSystem numberSystem, string value)
 {
     NumberSystem = numberSystem;
     Value = value;
 }
Example #33
0
 public static Number ToNumber(this Number number, NumberSystem numberSystem) => NumberConverter.Convert(number, numberSystem);