Exemplo n.º 1
0
        public ActionResult _UnitTesting02()
        {
            //
            string htmlNewLine = @"<br/>";
            //
            StringBuilder stringArray = new StringBuilder();
            //
            int    ARRAY_SIZE = 25;
            Random rand       = new Random();

            //
            int[] arr = new int[ARRAY_SIZE];
            //
            int[] randomArray = AlgorithmManager.FisherYates(ARRAY_SIZE, rand);
            //
            for (int i = 0; i < ARRAY_SIZE; i++)
            {
                stringArray.Append(string.Format("{0}{1}", ((i == 0) ? "" : @"|"), randomArray[i].ToString()));
            }
            //
            string unsortedList = stringArray.ToString();
            //
            AlgorithmManager am = new AlgorithmManager
                                  (
                unsortedList
                , ARRAY_SIZE
                                  );
            //
            string sortedList = am.BubbleSort();

            //
            ViewBag.Message = HttpUtility.HtmlEncode(unsortedList).Replace(@"|", htmlNewLine);
            //
            return(View());
        }
Exemplo n.º 2
0
        //
        public string _GetSort(ushort p_sortAlgoritm)
        {
            //
            string status = "OK";

            //
            try
            {
                //--------------------------------------------------
                // DECLARACION DE VARIABLES
                //--------------------------------------------------
                //
                string unsortedList = Session["unsortedList"].ToString();
                //
                AlgorithmManager am = new AlgorithmManager
                                      (
                    unsortedList
                    , ARRAY_SIZE
                                      );
                //
                switch (p_sortAlgoritm)
                {
                case 1:     // BUBBLE SORT
                    am.BubbleSort();
                    break;

                case 2:     // QUICK SORT
                    am.QuickSort();
                    break;

                case 3:     // TREE SORT
                    am.TreeSort();
                    break;
                }
                //
                string sortedList = string.Empty;
                //
                foreach (string sortStep in am.SortSteps)
                {
                    sortedList += string.Format("■|{0}|", sortStep);
                }
                //
                string sortedListEncoded = HttpUtility.HtmlEncode(sortedList).Replace("|", "<br/>");
                //
                status = sortedListEncoded;
                //
            }
            catch (Exception ex)
            {
                LogModel.Log(string.Format("SORT_BENCHMARK_ERROR. ='{0}'-'{1}'"
                                           , ex.Message
                                           , ex.StackTrace)
                             , string.Empty
                             , LogModel.LogType.Error);
            }
            //--------------------------------------------------
            // LOG
            //--------------------------------------------------
#if DEBUG
            LogModel.Log(string.Format("SORT_BENCHMARK . GET SORT : {0}", status));
#endif
            //
            return(status);
        }