Example #1
0
 public void AddNumbersGreaterThan1000Test()
 {
     Assert.AreEqual(3, StringAdd.Add("//;\n1;2000;2"));
     Assert.AreEqual(28, StringAdd.Add("//z\n2z9\n5,7,5,1001"));
     Assert.AreEqual(1038, StringAdd.Add("//-\n2,9\n5,7-1-2-3-4-5-1000"));
     Assert.AreEqual(2, StringAdd.Add("1001,2"));
 }
Example #2
0
        public void AddNumbersWithDifferentSingleCharacterDelimetersTest()
        {
            Assert.AreEqual(3, StringAdd.Add("//;\n1;2"));
            Assert.AreEqual(23, StringAdd.Add("//z\n2z9\n5,7"));
            Assert.AreEqual(38, StringAdd.Add("//-\n2,9\n5,7-1-2-3-4-5"));

            // Test that the empty case doesn't cause an argument out of range exception.
            Assert.AreEqual(3, StringAdd.Add("//\n1,2"));
        }
Example #3
0
        public void AddNegativeNumbersExceptionTest()
        {
            var ex = Assert.ThrowsException <NegativesNotAllowed>(() => StringAdd.Add("10,9,8,44,12,-20,5,10,-2"));

            Assert.AreEqual("negatives not allowed -20 -2", ex.Message);

            ex = Assert.ThrowsException <NegativesNotAllowed>(() => StringAdd.Add("//;\n-1;-2,-3,-4,-5,-6,-7;-8,-9,-10"));
            Assert.AreEqual("negatives not allowed -1 -2 -3 -4 -5 -6 -7 -8 -9 -10", ex.Message);
        }
Example #4
0
        public void AddNumbersLongStringPerformanceTest()
        {
            const long MillisecondsPerSeconds = 1000;
            string     longStr    = "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&";
            Stopwatch  stopwatch1 = Stopwatch.StartNew();

            Assert.AreEqual(68, StringAdd.Add("//[" + longStr + "]\n9" + longStr + "10" + longStr + "11" + longStr + "12" + longStr + "5" + longStr + "6" + longStr + "7" + longStr + "8"));
            stopwatch1.Stop();
            Assert.IsTrue(stopwatch1.ElapsedMilliseconds < MillisecondsPerSeconds, stopwatch1.ElapsedMilliseconds.ToString());
        }
Example #5
0
        public void AddStringsTest()
        {
            var sln = new StringAdd();

            foreach (var itr in datas)
            {
                var rst = sln.AddStrings(itr.Input1, itr.Input2);
                Assert.IsTrue(string.Equals(rst, itr.Result));
            }
        }
Example #6
0
        public void AddNumbersWithMalformedString()
        {
            // Should just return 0 since nothing is summed.
            Assert.AreEqual(0, StringAdd.Add("ausdioausdioasudoiasudio"));

            // We can just trim out the extra brackets and continue in case the user makes a mistake.
            Assert.AreEqual(6, StringAdd.Add("//[[[[[[[[[*][%]\n1*2%3"));

            // This is invalid and should throw an exception.
            Assert.ThrowsException <ArgumentException>(() => StringAdd.Add("////////1,2"));
        }
Example #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int    n = 1000;
            string s = "moon   ";

            IntAddcs a = new IntAddcs();

            n = a.IntTest(n);

            StringAdd b = new StringAdd();

            s = b.StrTest(s);

            Response.Write("n=" + n.ToString() + "</br>" + "s=" + s);
        }
Example #8
0
        public void AddManyNumbersTest()
        {
            string testString = string.Empty;
            int    sum        = 0;

            // Test with 10 numbers and calculate a sum of them as well to check.
            for (int i = 0; i < 10; i++)
            {
                sum += i;

                // Check if final number so it doesn't add comma at the end.
                if (i == 9)
                {
                    testString += i.ToString();
                }
                else
                {
                    testString += i.ToString() + ",";
                }
            }

            Assert.AreEqual(sum, StringAdd.Add(testString));

            // Reset the sum and string.
            testString = string.Empty;
            sum        = 0;

            // Test with 100 numbers and calculate a sum of them as well to check.
            for (int i = 0; i < 100; i++)
            {
                sum += i;

                // Check if final number so it doesn't add comma at the end.
                if (i == 99)
                {
                    testString += i.ToString();
                }
                else
                {
                    testString += i.ToString() + ",";
                }
            }

            Assert.AreEqual(sum, StringAdd.Add(testString));
        }
Example #9
0
 public void AddTwoNumbersTest()
 {
     Assert.AreEqual(3, StringAdd.Add("1,2"));
     Assert.AreEqual(999, StringAdd.Add("0,999"));
     Assert.AreEqual(22, StringAdd.Add("10,12"));
 }
Example #10
0
 public void AddOneNumberTest()
 {
     Assert.AreEqual(1, StringAdd.Add("1"));
     Assert.AreEqual(0, StringAdd.Add("0"));
     Assert.AreEqual(999, StringAdd.Add("999"));
 }
Example #11
0
 public void AddStringEmptyTest()
 {
     Assert.AreEqual(0, StringAdd.Add(string.Empty));
 }
Example #12
0
 public void Cleanup()
 {
     StringAdd.ClearCache();
 }
Example #13
0
 public void AddNumbersWithDuplicateDelimiters()
 {
     Assert.AreEqual(15, StringAdd.Add("//[*][*][&][&]\n1*2*3&4&5"));
 }
Example #14
0
 public void AddNumbersThatAllowMultipleDelimitersWithVaryingLengthsTest()
 {
     Assert.AreEqual(6, StringAdd.Add("//[***][%%%]\n1***2%%%3"));
     Assert.AreEqual(28, StringAdd.Add("//[**][%%%][&][aaaa][b][c-a]\n1**2%%%3&4aaaa5b6c-a7"));
 }
Example #15
0
 public void AddNumbersThatAllowMultipleDelimitersTest()
 {
     Assert.AreEqual(6, StringAdd.Add("//[*][%]\n1*2%3"));
     Assert.AreEqual(28, StringAdd.Add("//[*][%][&][a][b][c]\n1*2%3&4a5b6c7"));
 }
Example #16
0
 public void AddNumbersWithDelimitersOfAnylengthTest()
 {
     Assert.AreEqual(6, StringAdd.Add("//[***]\n1***2***3"));
     Assert.AreEqual(6, StringAdd.Add("//[;]\n1;2;3"));
     Assert.AreEqual(21, StringAdd.Add("//[;()]\n1;()2;()3,4,5\n6"));
 }
Example #17
0
 public void AddNumbersWithEmptyBracket()
 {
     Assert.AreEqual(3, StringAdd.Add("//\n1,2"));
     Assert.AreEqual(15, StringAdd.Add("//[*][][&][]\n1*2*3&4&5"));
 }
Example #18
0
 public void AddNumbersWithNewLineCharactersTest()
 {
     Assert.AreEqual(6, StringAdd.Add("1\n2,3"));
     Assert.AreEqual(37, StringAdd.Add("5\n6\n2,5,9\n10"));
 }