コード例 #1
0
        public void TestCase()
        {
            var calc = new BaseCalculator();

            Assert.AreEqual(7, calc.Calculate("3+2*2"));
            var str = new StringBuilder();
            var op  = new char[4] {
                '-', '+', '*', '/'
            };
            var r = new Random();

            for (int i = 0; i < 100000; i++)
            {
                str.Append(1 + r.Next(9));
                str.Append(op[r.Next(4)]);
            }
            var h = new Hashtable();

            str.Remove(str.Length - 1, 1);
            calc.Calculate(str.ToString());
        }
コード例 #2
0
ファイル: Processor.cs プロジェクト: vijaysingh2000/pic
        public void Start()
        {
            string[] arrLines    = File.ReadAllLines(this._fileName);
            string[] headerItems = null;

            _backgroundWorker.ReportProgress(0, arrLines.Length);

            for (int iloop = 0; iloop < arrLines.Length; iloop++)
            {
                _backgroundWorker.ReportProgress(iloop + 1, $"Processing line number {iloop}");

                string line = arrLines[iloop];

                if (iloop == 0)
                {
                    headerItems = line.Split(',');

                    string newLine = line + ",Premium Calculated" + Environment.NewLine;
                    File.AppendAllText(_newFileName, newLine);
                }
                else
                {
                    Dictionary <string, string> parameters = new Dictionary <string, string>();

                    if (headerItems == null)
                    {
                        return;
                    }

                    string[] lineItems = line.Split(',');

                    for (int jLoop = 0; jLoop < lineItems.Length; jLoop++)
                    {
                        string key   = headerItems[jLoop];
                        string value = lineItems[jLoop];

                        parameters.Add(key.Trim().ToUpper(), value);
                    }

                    double calculatedValue = _companyCalculator.Calculate(parameters, _companyMetaData);

                    string newLine = line + "," + calculatedValue.ToString() + Environment.NewLine;
                    File.AppendAllText(_newFileName, newLine);
                }
            }
        }