public void GetDivisors()
 {
     //GetDivisors
     CM.Models.MyModels mm = new MyModels();
     Assert.AreEqual("1,2,3,4,5,6,10,12,15,20,30,60", String.Join(",", mm.GetDivisors(60)));
     Assert.AreEqual("1,2,3,6,7,14,21,42", String.Join(",", mm.GetDivisors(42)));
     Assert.AreEqual("1", String.Join(",", mm.GetDivisors(1)));
 }
        public void MostCommon()
        {
            CM.Models.MyModels mm = new MyModels();

            //Most Common
            int[] arrResult = new int[] { 4, 5 };
            int[] arrIn = new int[] { 1, 2, 3, 4, 5, 5, 4 };
            Assert.AreEqual(String.Join(",", arrResult), String.Join(",", mm.GetMostCommon(arrIn)));
        }
예제 #3
0
        public ActionResult Index(FormCollection formdata)
        {
            try
            {
                CM.Models.MyModels mm = new MyModels();

                //Last Data Element Contains our Button Name
                if (formdata[formdata.Count - 1] == "Check IsNullOrEmpty")
                {
                    string s = formdata[0];
                    CM.Models.MyModels.ResultString = s.IsNullOrEmpty().ToString();

                }
                else if (formdata[formdata.Count - 1] == "Show Positive Divisors")
                {
                    CM.Models.MyModels.Input = int.Parse(formdata[0]);

                    var iEnum = mm.GetDivisors(int.Parse(formdata[0]));

                    CM.Models.MyModels.DivResultString = String.Join(",", iEnum);
                }
                else if (formdata[formdata.Count - 1] == "Calculate Area")
                {
                    //Calc Triangle Area
                    CM.Models.Triangle triangle = new CM.Models.Triangle();
                    CM.Models.Triangle.Side1 = (float)Convert.ToDecimal(formdata[0]);
                    CM.Models.Triangle.Side2 = (float)Convert.ToDecimal(formdata[1]);
                    CM.Models.Triangle.Side3 = (float)Convert.ToDecimal(formdata[2]);

                    triangle.calcArea();
                }
                else if (formdata[formdata.Count - 1] == "Show Most Common Numbers")
                {
                    CM.Models.MyModels.InputArray = formdata[0];

                    IList<int> iList = new List<int>();

                    var sArray = formdata[0].Split(",".ToCharArray());

                    foreach (var newArrayItem in sArray)
                        iList.Add(int.Parse(newArrayItem));

                    CM.Models.MyModels.ResultArray = String.Join(",",mm.GetMostCommon(iList.ToArray()));
                }

            }
            catch (Exception ex){//Catch all errors
                ViewBag.Exception = ex.Message;
            }
            return View();
        }