public void TestSort()
        {
            LinqSort exampleLinqSort = new LinqSort();

            exampleLinqSort.WoSewOrderBy();
        }
Exemple #2
0
        public ActionResult Index(CallNumbers cn, string answers)
        {
            //see if the user submitted anything
            if (!string.IsNullOrEmpty(answers))
            {
                int totalMatched = 0;

                LinqSort sort = new LinqSort();
                //now sort the list and compare
                List <string> randList   = new List <string>();
                List <string> sortedList = new List <string>();

                //add cn.RandomCallNumberList call numbers to list<string>
                foreach (var item in cn.RandomCallNumberList)
                {
                    randList.Add(item.RandCallNumber);
                }

                sortedList = sort.ReturnSortedList(randList);

                //split user's ansers and assign to list
                List <string> userAnswers = answers.Split(',').Select(sValue => sValue.Trim()).ToList();

                //initialize model lists
                cn.SortedCallNumberList   = new List <SortedCallNumbers>();
                cn.UserCallNumberList     = new List <UserCallNumbers>();
                cn.MatchedCallNumbersList = new List <MatchedCallNumbers>();

                for (int i = 0; i < sortedList.Count; i++)
                {
                    for (int j = i; j < userAnswers.Count;)
                    {
                        //used for id
                        int count = i + 1;

                        SortedCallNumbers scn = new SortedCallNumbers();
                        scn.ID = count;
                        scn.SortedCallNumber = sortedList[i];
                        cn.SortedCallNumberList.Add(scn);

                        UserCallNumbers ucn = new UserCallNumbers();
                        ucn.ID             = count;
                        ucn.UserCallNumber = userAnswers[j];
                        cn.UserCallNumberList.Add(ucn);

                        break;
                    }
                }



                //compare the sorted list and user answers
                MatchingLists ml   = new MatchingLists();
                List <string> temp = new List <string>();
                temp = ml.MatchLists(sortedList, userAnswers);
                for (int i = 0; i < temp.Count; i++)
                {
                    MatchedCallNumbers mcn = new MatchedCallNumbers();
                    mcn.ID = i + 1;
                    mcn.MatchedCallNumber = temp[i];
                    cn.MatchedCallNumbersList.Add(mcn);
                }
                //cn.MatchedList = ml.MatchLists(sortedList, userAnswers);

                //return total matching values by counting matched values in new list
                totalMatched = cn.MatchedCallNumbersList.Count();

                //display results
                cn.Result = totalMatched;
                //total mark allocation
                ViewBag.TotalMarks = cn.SortedCallNumberList.Count();
                //percentage value
                double res = (Convert.ToDouble(totalMatched) / Convert.ToDouble(cn.SortedCallNumberList.Count())) * 100;
                ViewBag.Percent = res;
            }
            else
            {
                //asign viewbag for error?
                return(RedirectToAction("Index"));
            }

            //if (TempData["SaveResult"] != null)
            //{
            //    ViewBag.SaveResult = TempData["SaveResult"].ToString();
            //}

            return(View(cn));
        }
Exemple #3
0
 public static void Main()
 {
     LinqSort.DemoLinqSort();
     LinqSearch.DemoWhere();
 }
Exemple #4
0
        static void Main(string[] args)
        {
            var modelFaker = new Faker <User>()
                             .RuleFor(o => o.Id, f => f.Random.Number(1, 650))
                             .RuleFor(o => o.Age, f => f.Random.Number(15, 90))
                             .RuleFor(o => o.Company, f => f.Company.CompanyName())
                             .RuleFor(o => o.IsMarried, f => f.Random.Bool())
                             .RuleFor(o => o.Name, f => f.Name.FullName())
                             .RuleFor(o => o.BirthDate, f => f.Date.Future(90));

            var allUserData = new List <User>();

            //string sortModelField = FluentInterfacePattern.Properties.Settings.Default.sortParameter;


            //var faker = new Faker("en");
            //var emailList = Enumerable.Range(1, 1000)
            //    .Select(_ => faker.Random)
            //    .ToList();


            for (int i = 0; i < 1000; i++)
            {
                var myModel = modelFaker.Generate();

                User tom = new UserBuilder()
                           .SetId(myModel.Id)
                           .SetName(myModel.Name)
                           .SetCompany(myModel.Company)
                           .SetAge(myModel.Age)
                           .SetIsMarried(myModel.IsMarried)
                           .SetBirthDate(myModel.BirthDate);
                allUserData.Add(tom);
            }


            //foreach (var element in allUserData)
            //{
            //    Console.WriteLine(element.Id + " " + element.Name + " " + element.Age);
            //}

            //allUserData.Sort(new Comparison<User>((x, y) => string.Compare(x.Name, y.Name, StringComparison.InvariantCulture)));
            //allUserData.Sort(new Comparison<User>((x, y) => string.Compare(x.Id.ToString(), y.Id.ToString(), StringComparison.InvariantCulture)));

            ShellSort     sortShell     = new ShellSort();
            BubbleSort    bubbleSort    = new BubbleSort();
            LinqSort      linqSort      = new LinqSort();
            CompareSort   compareSort   = new CompareSort();
            InsertionSort insertionSort = new InsertionSort();
            QuickSort     quickSort     = new QuickSort();

            var sortedShellCollection   = sortShell.ShellSortAlgorithm(allUserData);
            var sortedBubbleCollection  = bubbleSort.BubbleSortAlgorithm(allUserData);
            var sortedLinqCollection    = linqSort.LinqSortAlgorithm(allUserData);
            var sortedCompareCollection = compareSort.LinqSortAlgorithm(allUserData);
            var insertionSortCollection = insertionSort.InsertionSortAlgorithm(allUserData);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var quickSortCollection = quickSort.QuickSortAlgorithm(allUserData, 0, allUserData.Count - 1);

            sw.Stop();
            Console.WriteLine("QuickSort: " + sw.ElapsedMilliseconds);

            Printers.PrintUsers(quickSortCollection);
            Console.ReadLine();

            //============================================

            Guid orderId = Guid.Parse("9043f30c-446f-421f-af70-234fe8f57c0d");

            Order order = new OrderBuilder()
                          .InitializeOrder(orderId)
                          .ValidateOrder(orderId)
                          .ProcessOrder(orderId)
                          .SaveOrder(orderId);

            Console.ReadKey();

            //============================================

            Guid     customerId = Guid.Parse("9043f30c-446f-421f-af70-234fe8f57c0d");
            Customer customer   = new Customer();

            customer
            .InitializeOrder(customerId)
            .ValidateOrder(customerId)
            .ProcessOrder()
            .SaveOrder();
            Console.ReadKey();
        }