Example #1
0
        public void Test_Parse(string valueString)
        {
            var bigNUmber       = StringNumber.Parse(valueString);
            var bigNumberString = bigNUmber.ToString();

            Assert.AreEqual(valueString, bigNumberString);
        }
Example #2
0
        protected override void Execute(CodeActivityContext context)
        {
            string numberString = string.Empty;

            if (IntNumber.Expression != null)
            {
                numberString = IntNumber.Get(context).ToString();
            }
            else if (LongNumber.Expression != null)
            {
                numberString = LongNumber.Get(context).ToString();
            }
            else if (StringNumber.Expression != null)
            {
                numberString = StringNumber.Get(context).ToString();
            }
            else
            {
                throw new ArgumentException("No input argument was filled.");
            }

            string converted = NumberConversor.Convert(numberString);

            SpelledInNumber.Set(context, converted);
        }
        public void UppercaseFirstTest_hello_Hello()
        {
            String str            = "hello";
            String expectedResult = "Hello";
            String actualResult   = StringNumber.UppercaseFirst(str);

            StringAssert.Equals(expectedResult, actualResult);
        }
        public void CreateStringTest()
        {
            long   num            = Convert.ToInt64(TestContext.DataRow["Number"]);
            String expectedResult = TestContext.DataRow["String"].ToString();
            String actualResult   = StringNumber.CreateString(num);

            StringAssert.Equals(expectedResult, actualResult);
        }
Example #5
0
        /// <summary>
        /// Execute arithmetic operation with operands op1 and op2
        /// </summary>
        /// <param name="op1">first operand</param>
        /// <param name="op2">second operand</param>
        /// <param name="operator">arithmetic operation</param>
        /// <returns>A result of arithmetic operation with bigNumbers op1 and op2.</returns>
        private string ApplyOperation(string op1, string op2, string @operator)
        {
            op1 = StringNumber.RemoveSpaces(op1);
            op2 = StringNumber.RemoveSpaces(op2);
            op1 = StringNumber.RemoveUnnecessaryZeros(op1);
            op2 = StringNumber.RemoveUnnecessaryZeros(op2);

            string norm_result = null;

            if ((norm_result = ProcessNeutralOperands(op1, op2, @operator)) != null)
            {
                return(norm_result);
            }

            int        p1     = StringNumber.GetPrecisionNumber(op1);
            int        p2     = StringNumber.GetPrecisionNumber(op2);
            int        prec   = (p1 > p2) ? p1 : p2;
            BigInteger n1     = BigInteger.Parse(StringNumber.UpPowerOfNumber(op1, prec));
            BigInteger n2     = BigInteger.Parse(StringNumber.UpPowerOfNumber(op2, prec));
            BigInteger?result = @operator switch
            {
                "+" => BigInteger.Add(n1, n2),
                "*" => BigInteger.Multiply(n1, n2),
                "-" => BigInteger.Subtract(n1, n2),
                "/" => null,
                _ => null
            };

            if (result.HasValue == false && @operator == "/")
            {
                return(StringNumber.DivideRationalNumbers(n1, n2));
            }
            else if (result.HasValue == false)
            {
                return("Err");
            }
            prec = @operator switch
            {
                "*" => prec + prec,
                "+" => prec,
                "-" => prec,
                _ => 0
            };
            norm_result = StringNumber.DownPowerOfNumber(result.ToString(), prec);
            return(StringNumber.RemoveUnnecessaryZeros(norm_result));
        }
Example #6
0
        public void Test_LoadTest()
        {
            Console.WriteLine("Test_LoadTest BEGIN");
            var sw = new Stopwatch();

            sw.Start();

            //string stringA = TestHelper.LoadStringNumber("stringA.txt");
            //string stringB = TestHelper.LoadStringNumber("stringB.txt");

            string stringA;
            string stringB;

            TestHelper.GetRandomStringNumber((long)(1024 * 1024 * 1024 / 2), out stringA, out stringB);

            Console.WriteLine($"Strings was generated, Time: {sw.Elapsed}");
            sw.Restart();


            var stringValueA = StringNumber.Parse(stringA);
            var stringValueB = StringNumber.Parse(stringB);

            //File.WriteAllText(Path.Combine(DataDirectory, "stringA.txt"), stringA);
            //File.WriteAllText(Path.Combine(DataDirectory, "stringB.txt"), stringB);

            Console.WriteLine($"Strings was parsed, Time: {sw.Elapsed}");
            sw.Restart();

            var stringValueSum = stringValueA.Increment(stringValueB);

            sw.Stop();
            Console.WriteLine($"Numbers sum was done, Time: {sw.Elapsed}");

            // хотел сравнить с BigInteger из фреймворка 4.0,
            // но я так и не дождался первого BigInteger.Parse
            //var bigIntegerA = BigInteger.Parse(stringA);
            //var bigIntegerB = BigInteger.Parse(stringB);
            //var swBigInt = new Stopwatch();
            //swBigInt.Start();
            //var bigIntegerSum = bigIntegerA + bigIntegerB;
            //swBigInt.Stop();

            Console.WriteLine("Test_LoadTest END");
        }
Example #7
0
        public void Test_Add(string valueStringA, string valueStringB, string resultString)
        {
            var sw = new Stopwatch();

            sw.Start();

            var bigNUmberA = StringNumber.Parse(valueStringA);
            var bigNUmberB = StringNumber.Parse(valueStringB);

            Console.WriteLine($"Strings was parsed, Time: {sw.Elapsed}");
            sw.Restart();

            var bigNumberSum = bigNUmberA.Increment(bigNUmberB);

            sw.Stop();

            Assert.AreEqual(resultString, bigNumberSum.Value);

            Console.WriteLine($"Numbers sum was done, Time: {sw.Elapsed}");
        }