/// <summary>
 /// Initializes a new instance of the <see cref="Scoreboard"/> class.
 /// </summary>
 /// <param name="printer">The object used to show messages.</param>
 /// <param name="sorter">The object used to sort scores.</param>
 /// <param name="scoresDataManager">The object from which scores are read and written in.</param>
 public Scoreboard(IPrinter printer, ISorter sorter, IDataManager<Dictionary<string, int>> scoresDataManager)
 {
     this.Score = new Dictionary<string, int>();
     this.printer = printer;
     this.sorter = sorter;
     this.scoresDataManager = scoresDataManager;
 }
        public static void Sort(int[][] array, ISorter ISort, bool ascendingOrder = true)
        {
            if (array == null)
                throw new NullReferenceException("Array is null");
            if (array.Length == 0)
                throw new InvalidOperationException("Array contains no elements");

            int[] criteria = ISort.Criterion(array);

            if (criteria == null)
                throw new NullReferenceException("Criteria is null");
            if (criteria.Length == 0)
                throw new InvalidOperationException("Criteria array contains no elements");

            for (int i = 0; i < criteria.Length - 1; i++)
            {
                for (int j = 0; j < criteria.Length - i - 1; j++)
                {
                    if (ascendingOrder && firstNumBigger(criteria[j], criteria[j + 1]))
                    {
                        swap(ref criteria[j], ref criteria[j + 1]);
                        swap(ref array[j], ref array[j + 1]);
                    }
                    else
                    {
                        if (!ascendingOrder && !firstNumBigger(criteria[j], criteria[j + 1]))
                        {
                            swap(ref criteria[j], ref criteria[j + 1]);
                            swap(ref array[j], ref array[j + 1]);
                        }
                    }
                }
            }
        }
 public void ChangeAlgorithm(ISorter sorter)
 {
     if (sorter is null)
     {
         return;
     }
     _sorter = sorter;
 }
示例#4
0
 internal static InstanceSorterFactory From <TRequest, TEntity>(
     ISorter <TRequest, TEntity> sorter)
     where TEntity : class
 {
     return(new InstanceSorterFactory(
                sorter,
                new FunctionSorter((request, queryable) => sorter.Sort((TRequest)request, (IQueryable <TEntity>)queryable))));
 }
示例#5
0
 /// <summary>
 ///   Sort the list using the specified sorter.
 /// </summary>
 /// <param name="sorter"> The sorter to use in the sorting process. </param>
 public void Sort(ISorter <T> sorter)
 {
     if (sorter == null)
     {
         throw new ArgumentNullException("sorter");
     }
     sorter.Sort(this);
 }
示例#6
0
        public IEnumerable <IVehicleModel> FindModel(IFilter filter, ISorter sorter, IPager pager)
        {
            var models = context.VehicleModels.Where(m => string.IsNullOrEmpty(filter.Search) ? m != null : m.Name.Contains(filter.Search))
                         .Where(m => filter.MakeId == null ?  m != null : m.MakeId == filter.MakeId).Include("Make")
                         .OrderByDescending(x => sorter.SortDirection == "dsc" ? x.Name : "")
                         .OrderBy(x => string.IsNullOrEmpty(sorter.SortDirection) || sorter.SortDirection == "asc" ? x.Name : "");

            return(mapper.Map <IEnumerable <IVehicleModel> >(models).ToPagedList(pager.CurrentPage, pager.PageSize));
        }
示例#7
0
        public SorintCanvasVisualization(Canvas canvas, ISorter <double> sorter)
        {
            Contract.Ensures(canvas != null, "canvas can not be null.");
            Contract.Ensures(sorter != null, "sorter can not be null.");

            _canvas  = canvas;
            _sorter  = sorter;
            _element = new Dictionary <int, NumberBar>();
        }
示例#8
0
        private static void TestSorter(ISorter <int> sorter)
        {
            // Test Reverse sequential list
            var list = GetReverseSequentialTestList();

            sorter.Sort(list, SortOrder.Ascending);
            AssertGeneralTestListSorted(list);

            // Test sequential list
            list = GetSequentialTestList();
            sorter.Sort(list, SortOrder.Descending);
            AssertGeneralTestListReverseSorted(list);

            // Test already sorted list
            list = GetSortedList();
            sorter.Sort(list);
            AssertGeneralTestListSorted(list);

            // Test already reverse sorted list
            list = GetReverseSortedList();
            sorter.Sort(list, SortOrder.Descending);
            AssertGeneralTestListReverseSorted(list);

            // Test half sequential list
            list = GetHalfSequentialList();
            sorter.Sort(list);
            AssertGeneralTestListSorted(list);

            // Test half sequential list reversed
            list = GetHalfSequentialList();
            sorter.Sort(list, SortOrder.Descending);
            AssertGeneralTestListReverseSorted(list);

            // Test double numbers
            list = GetDoubleNumbers();
            sorter.Sort(list);
            AssertDoubleNumbersList(list);

            // Test reversed double numbers
            list = GetDoubleNumbers();
            sorter.Sort(list, SortOrder.Descending);
            AssertDoubleNumbersReversedList(list);

            // Test with list with one item in it
            list = GetSingleItemList();
            sorter.Sort(list);
            AssertSingleList(list);

            // Test with list with one item in it
            list = GetSingleItemList();
            sorter.Sort(list, SortOrder.Descending);
            AssertSingleList(list);

            // Test empty List
            list = new List <int>();
            sorter.Sort(list, SortOrder.Descending);
        }
        public static void Sort(this int[][] array, ISorter sorter, Compare comparator)
        {
            if (array == null)
                throw new NullReferenceException();
            if (sorter == null || comparator == null)
                throw new ArgumentNullException();

            sorter.Sort(array, comparator);
        }
示例#10
0
 private void ResetSortingBtnClick(object sender, RoutedEventArgs e)
 {
     MusicsFromPlaylist.ItemsSource = new List <Song>();
     sorter = new Sorter(unsortedSongList);
     MusicsFromPlaylist.ItemsSource = unsortedSongList;
     SortTitleBtn.IsEnabled         = true;
     SortDurationBtn.IsEnabled      = true;
     SortDateBtn.IsEnabled          = true;
 }
示例#11
0
        /// <summary>
        /// Sorts all descendants using the specified sorter.
        /// </summary>
        /// <param name="sorter">The sorter to use in the sorting process.</param>
        /// <param name="comparer">The comparer.</param>
        public void SortAllDescendants(ISorter <GeneralTree <T> > sorter, IComparer <GeneralTree <T> > comparer)
        {
            childNodes.Sort(sorter, comparer);

            for (int i = 0; i < childNodes.Count; i++)
            {
                childNodes[i].SortAllDescendants(sorter, comparer);
            }
        }
示例#12
0
 public static IStagedSorter ToStagedSorter(this ISorter sorter)
 {
     return(new StagedSorterImpl
            (
                guid: sorter.Guid,
                keyCount: sorter.KeyCount,
                sorterStages: sorter.KeyPairs.ToSorterStages(sorter.KeyCount)
            ));
 }
示例#13
0
        private void DoTest(ISorter sorter)
        {
            int[] array = { 38, 27, 43, 3, 9, 82, 10 };
            int[] expectedSortedArray = { 3, 9, 10, 27, 38, 43, 82 };

            sorter.Sort(array);

            Assert.Equal(expectedSortedArray, array);
        }
示例#14
0
 public void Sort()
 {
     if (Sorter == null)
     {
         Sorter = new DefaultSorter();
     }
     Array.Resize(ref data, Count);
     Sorter.Sort(data, null);
 }
示例#15
0
        private static double Sort <T>(ISorter <T> sorter, T[] data)
        {
            stopwatch.Reset();
            stopwatch.Start();
            sorter.Sort(data);
            stopwatch.Stop();

            return(stopwatch.Elapsed.TotalMilliseconds);
        }
示例#16
0
 public SortResult(ISorter sorter, double sortedness, bool[] stageUse,
                   ISortable sortable, IPermutation result)
 {
     Sortedness = sortedness;
     StageUse   = stageUse;
     Sortable   = sortable;
     Result     = result;
     Sorter     = sorter;
 }
示例#17
0
        private TimeSpan TimeOperation(int[] arr, ISorter algorithm)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            algorithm.Sort(arr);
            stopWatch.Stop();
            return(stopWatch.Elapsed);
        }
        public static ISorter <T> CreateSorter <TSorter, T>()
            where T : IComparable
            where TSorter : ISorter <T>
        {
            ISorter <T>     sorter      = Activator.CreateInstance <TSorter>();
            AsyncSorter <T> asyncSorter = new AsyncSorter <T>(sorter);

            return(asyncSorter);
        }
示例#19
0
        private static void TestSortersAllPermutations(SortableCollection <int> collection)
        {
            Console.WriteLine("All items before sorting:");
            collection.PrintAllItemsOnConsole();
            Console.WriteLine();
            Console.WriteLine("Calculating time (Permutation without repetitions) ...");

            var copy = collection.GetCopy();

            stopWatch.Reset();
            sorter = new SelectionSorter <int>();
            Console.WriteLine("========================SelectionSorter result=================================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("SelectionSorter:    " + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new UpgradedSelectionSorter <int>();
            Console.WriteLine("========================UpgradedSelectionSorter result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("UpgradedSelection  :" + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new QuickSorter <int>();
            Console.WriteLine("========================Quicksorter result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("Quicksorter:        " + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new MergeSorter <int>();
            Console.WriteLine("========================MergeSorter result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("MergeSorter:        " + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new MergeInsertionSorter <int>();
            Console.WriteLine("========================MergeInsertSorter result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("MergeInsertSorter:  " + stopWatch.Elapsed);
            Console.WriteLine();

            copy = collection.GetCopy();
            stopWatch.Reset();
            sorter = new InsertionSorter <int>();
            Console.WriteLine("========================Insertion result=========================");
            GeneratePermutationsAndSort(copy, 0);
            Console.WriteLine("Insertion:          " + stopWatch.Elapsed);
            Console.WriteLine();
        }
示例#20
0
        private void GraphPoints(uint count)
        {
            chart1.ResetAutoValues();

            int[] points;
            switch (comboBox1.SelectedItem.ToString())
            {
            case "Random":
                points = GetRandomPoints(count);
                break;

            case "Sorted":
                points = GetSortedPoints(count);
                break;

            case "Reversed":
                points = GetReversedPoints(count);
                break;

            default:
                points = new int[0];
                break;
            }

            ISorter <int>[] algorithms = new ISorter <int>[]
            {
                new BubbleSort <int>(),
                new InsertionSort <int>(),
                new MergeSort <int>(),
                new SelectionSort <int>(),
                new QuickSort <int>(),
            };

            foreach (ISorter <int> algorithm in algorithms)
            {
                this.Text = string.Format("Running algorithm: {0}", algorithm.GetType().Name);

                int[] cloned = new int[points.Length];
                Array.Copy(points, cloned, points.Length);

                algorithm.Sort(cloned);

                Series series = chart1.Series.Add(algorithm.GetType().Name);

                if (cbOperation.SelectedItem.ToString() == "Comparisons")
                {
                    series.Points.Add(new double[] { algorithm.Comparisons });
                }
                else
                {
                    series.Points.Add(new double[] { algorithm.Swaps });
                }
            }

            this.Text = string.Format("Ready");
        }
示例#21
0
        private static void PrintResult(ISorter sorter, Stopwatch stopwatch, IEnumerable <int> sorted)
        {
            Console.WriteLine($"{sorter.GetType().Name}\t\tElapsed: {stopwatch.Elapsed}");

            /* foreach (var number in sorted)
             * {
             *   Console.Write($"{number} ");
             * }
             * Console.WriteLine("");*/
        }
示例#22
0
        public void Sort(ISorter <GeneralTree <T> > sorter, SortOrder order)
        {
            #region Validation

            Guard.ArgumentNotNull(sorter, "sorter");

            #endregion

            childNodes.Sort(sorter, order);
        }
示例#23
0
        public void SetUp(int testIndex, ISorter sorter)
        {
            Random rnd = new Random();
            this.list = new ArrayList();

            for (int i = 0; i < this.CollectionCount(testIndex); ++i)
            {
                this.list.Add(rnd.Next());
            }
        }
示例#24
0
        public void TestRandomSequence(ISorter <double> sorter)
        {
            var input    = new double[] { 4.5, 1.5, 2.5, 3.5, 5.5 };
            var expected = Enumerable
                           .Range(1, 5)
                           .Select(x => x + 0.5)
                           .ToArray();

            SorterTestsHelper.TestSorter(input, expected, sorter);
        }
示例#25
0
        public void TestSortedSequence(ISorter <double> sorter)
        {
            var baseSequense = Enumerable
                               .Range(1, testLength)
                               .Select(x => x + 0.5);
            var input    = baseSequense.ToArray();
            var expected = baseSequense.ToArray();

            SorterTestsHelper.TestSorter(input, expected, sorter);
        }
示例#26
0
 public DataComparer(DataComparerConfig config, ISorter sorter, IRowComparerFactory rowComparerFactory,
                     IKeyMapperFactory keyMapperFactory, IValueMapperFactory valueMapperFactory)
 {
     _sorter             = sorter;
     _rowComparerFactory = rowComparerFactory;
     _keyMapperFactory   = keyMapperFactory;
     _valueMapperFactory = valueMapperFactory;
     Config     = config;
     _stopwatch = new Stopwatch();
 }
示例#27
0
 public void TearDown(ISorter sorter)
 {
     // checking up
     for (int i = 0; i < this.list.Count - 1; ++i)
     {
         if ((int)this.list[i] > (int)this.list[i + 1])
         {
             throw new Exception("list not sorted");
         }
     }
 }
        public IPagedList <IVoziloMarka> DohvatiMarke(ISorter sorter, IFilter filter, INumerer stranica)
        {
            //Numerer strIspis = (Numerer)stranica;
            //Sorter sorter = (Sorter)sort;
            IQueryable <IVoziloMarka> upit      = null;
            IPagedList <IVoziloMarka> kolekcija = null;

            //sorter.Poredak = (sorter.Poredak == "A") ? "ASC" : "DESC";
            //sorter.Poredak = (sorter.Poredak == "A") ? "OrderBy" : "OrderByDescending";

            //var parametar = Expression.Parameter(typeof(VoziloMarka), "item");      //  -- kreiranje parametra
            //var izraz = Expression.Property(parametar, sorter.Stupac);
            //var konverzija = Expression.Convert(izraz, typeof(object));
            //var lambda = Expression.Lambda<Func<VoziloMarka, object>>(konverzija, parametar);
            //var lambda = Expression.Lambda(izraz, parametar);
            //MethodCallExpression ispis = null;
            //PropertyInfo svojstvo = typeof(VoziloMarka).GetProperty(sorter.Stupac);

            //string upit = "SELECT * FROM VoziloMarkas" ORDER BY " + sorter.Stupac + " " + sorter.Poredak + "; ";
            //List<VoziloMarka> kolekcija = _db.VoziloMarke.SqlQuery("SELECT* FROM VoziloMarkas " + sorter.Sort + "; ").ToList();

            //kolekcija = _db.VoziloMarke.SqlQuery("SELECT * FROM VoziloMarkas WHERE Naziv LIKE '%" + filter.Naziv + "%' " + sorter.Sort + " ;").ToList();
            //kolekcija = (from item in _db.VoziloMarke where item.Naziv.ToLower().Contains(filter.Naziv.ToLower()) select item).OrderBy(x => x.GetType().ToString() == sorter.Stupac);
            //upit = (from item in _db.VoziloMarke where item.Naziv.ToLower().Contains(filter.PretragaUpita.ToLower()) select item);

            //NAPOMENA: CIJELI UVJET SVEDEN NA SAMO SLJEDEĆU LINIJU KODA
            upit = (String.IsNullOrEmpty(filter.PretragaUpita))? _db.VoziloMarke : _db.VoziloMarke.Where(x => x.Naziv.ToLower().Contains(filter.PretragaUpita.ToLower()));

            //ispis = Expression.Call(typeof(Queryable), sorter.Poredak, new[] { typeof(VoziloMarka), izraz.Type }, upit.Expression, Expression.Quote(lambda));

            switch (sorter.Stupac)
            {
            case "Id":
                upit = (sorter.Poredak == "A") ? upit.OrderBy(x => x.Id) : upit.OrderByDescending(x => x.Id);
                break;

            case "Naziv":
                upit = (sorter.Poredak == "A") ? upit.OrderBy(x => x.Naziv) : upit.OrderByDescending(x => x.Naziv);
                break;

            case "Kratica":
                upit = (sorter.Poredak == "A") ? upit.OrderBy(x => x.Kratica) : upit.OrderByDescending(x => x.Kratica);
                break;
            }
            //kolekcija = upit.Provider.CreateQuery<VoziloMarka>(ispis).Skip((strIspis.Str - 1) * strIspis.BrRedova).Take(strIspis.BrRedova).ToList();
            //kolekcija = upit.OrderBy(sorter.Stupac + " " + sorter.Poredak).Skip((strIspis.Str - 1) * strIspis.BrRedova).Take(strIspis.BrRedova).ToList();
            //OrderBy(lambda,Compile())
            //OrderBy(item => svojstvo.GetValue(item))
            //OrderBy(item => item.GetType().GetProperty(property).GetValue(item))

            kolekcija = upit.ToPagedList(stranica.Str, stranica.BrRedova);

            return(kolekcija);
        }
        public static void TestStringSorter(ISorter<string> sorter)
        {
            string[] array = new string[] { "foo", "fOo2", "Fuzzle", "FOb", "zander", "Alphabet", "QuiRk", "foo", "fiddle", "fast", "finagle", "g1", "gross", "g3", "gimpy", "horse", "hippo", "igloo", "rascal", "splurge" };

            sorter.Sort(array);

            for (int i = 0; i < array.Length - 1; i++)
            {
                Assert.IsTrue(array[i].CompareTo(array[i + 1]) <= 0);
            }
        }
示例#30
0
 /// <summary>
 /// Creates a new QueryableOperator with start, limit, default sorter, sorters and filters.
 /// </summary>
 /// <param name="start">The paging start value.</param>
 /// <param name="limit">The paging limit value.</param>
 /// <param name="defaultSorter">The default sorter.</param>
 /// <param name="filters">The filters.</param>
 /// <param name="sorters">The sorters.</param>
 public QueryableOperator(int start, int limit, ISorter defaultSorter, IList <IFilter> filters = null, IList <ISorter> sorters = null)
 {
     Contract.Requires(start >= 0, "The start value must be greater than or equal to zero.");
     Contract.Requires(limit >= 0, "The limit must be greater than or equal to zero.");
     Contract.Requires(defaultSorter != null, "The default sorter must not be null.");
     this.Filters       = filters ?? new List <IFilter>();
     this.Sorters       = sorters ?? new List <ISorter>();
     this.Start         = start;
     this.Limit         = limit;
     this.DefaultSorter = defaultSorter;
 }
 public void TearDown(ISorter <int> sorter)
 {
     // checking up
     for (int i = 0; i < this.list.Count - 1; ++i)
     {
         if (this.list[i] > this.list[i + 1])
         {
             throw new Exception("list not sorted");
         }
     }
 }
示例#32
0
 public SorterEvalSetImpl
 (
     ISorter sorter,
     IEnumerable <ISorterEval> sorterOnSwitchableGroups
 )
 {
     _sorter = sorter;
     _sorterOnSwitchableGroups = sorterOnSwitchableGroups.ToDictionary(t => t.SwitchableGroupGuid);
     _switchUseList            = _sorterOnSwitchableGroups.Values.Select(T => T.SwitchUseList).VectorSumDouble();
     _switchesUsed             = SwitchUseList.Count(T => T > 0);
 }
        public static void TestStringSorter(ISorter <string> sorter)
        {
            string[] array = new string[] { "foo", "fOo2", "Fuzzle", "FOb", "zander", "Alphabet", "QuiRk", "foo", "fiddle", "fast", "finagle", "g1", "gross", "g3", "gimpy", "horse", "hippo", "igloo", "rascal", "splurge" };

            sorter.Sort(array);

            for (int i = 0; i < array.Length - 1; i++)
            {
                Assert.IsTrue(array[i].CompareTo(array[i + 1]) <= 0);
            }
        }
示例#34
0
        public static SorterToJson ToJsonAdapter(this ISorter sorter)
        {
            var chromosomeUintToJson = new SorterToJson
            {
                Guid     = sorter.Guid,
                Sequence = sorter.KeyPairs.Select(kp => kp.Index).ToList(),
                KeyCount = sorter.KeyCount
            };

            return(chromosomeUintToJson);
        }
示例#35
0
        public static Tuple <ISorter, ISorter> Recombine(this IRando randy, ISorter sorterA, ISorter sorterB)
        {
            var aList = sorterA.SorterStages.ToList();
            var bList = sorterB.SorterStages.ToList();

            var combies = aList.Recombo(bList, crossPt: randy.NextUint(sorterA.StageCount));

            return(new Tuple <ISorter, ISorter>(
                       combies.Item1.ToSorter(Guid.NewGuid(), Guid.Empty),
                       combies.Item1.ToSorter(Guid.NewGuid(), Guid.Empty)));
        }
        public TBuilder SortWith <TBaseRequest>(ISorter <TBaseRequest, TEntity> sorter)
        {
            if (!typeof(TBaseRequest).IsAssignableFrom(typeof(TRequest)))
            {
                throw new ContravarianceException(nameof(SortWith), typeof(TBaseRequest), typeof(TRequest));
            }

            Sorter = InstanceSorterFactory.From(sorter);

            return((TBuilder)this);
        }
        public static void TestInt32Sorter(ISorter<int> sorter)
        {
            int[] array = new int[randomProvider.Next(2, 1000)];
            for (int i = 0; i < array.Length; ++i)
            {
                array[i] = randomProvider.Next(1000);
            }

            sorter.Sort(array);

            for (int i = 0; i < array.Length - 1; i++)
            {
                Assert.IsTrue(array[i] <= array[i + 1]);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HangmanGame"/> class.
 /// Provides methods for running the game, ending the game and executing commands.
 /// </summary>
 /// <param name="printer">The object used to show messages.</param>
 /// <param name="sorter">The object used to sort scores.</param>
 /// <param name="scoresDataManager">The object from which scores are read and written in.</param>
 /// <param name="gameStateManager">The object used to save the current game state.</param>
 /// <param name="commandFactory">The object used to deal with commands needed.</param>
 /// <param name="commandExecutioner">The object used for the execution of commands.</param>
 /// <param name="wordProvider">The object that provides the word for the current game.</param>
 public HangmanGame(
     IPrinter printer,
     ISorter sorter,
     IDataManager<Dictionary<string, int>> scoresDataManager,
     IDataManager<SaveLoadManager> gameStateManager,
     CommandFactory commandFactory,
     ICommandInvoker commandExecutioner,
     IWordProvider wordProvider)
 {
     this.printer = printer;
     this.context = new GameContext(wordProvider, new Scoreboard(printer, sorter, scoresDataManager));
     this.commandFactory = new CommandFactory();
     this.gameSaver = new SaveLoadManager(this.printer, gameStateManager);
     this.commandExecutioner = new HangmanCommandInvoker();
 }
 public static void Sort(this int[][] targetArray, ISortComparer comparer, ISorter sorter)
 {
     if (targetArray == null)
     {
         throw new ArgumentNullException("targetArray");
     }
     if (comparer == null)
     {
         throw new ArgumentNullException("comparer");
     }
     if (sorter == null)
     {
         throw new ArgumentNullException("sorter");
     }
     sorter.Sort(targetArray, comparer.Compare);
 }
示例#40
0
        public static void SortPlot(ISorter sorter, int elements, string name)
        {
            Random randint = new Random();
            Stopwatch watch = new Stopwatch();
            StreamWriter file = new StreamWriter(@"ChristianMunoz_RunningTimes.txt", true);
            long time = watch.ElapsedMilliseconds;
            int[] list;

            while(elements > 0)
            {
                list = new int[elements];

                for (int i = 0; i < list.Length; i++)
                    list[i] = randint.Next(1, elements);

                if (name == "Merge Sort")
                {
                    watch.Reset();
                    watch.Start();
                    sorter.sort(list, 0, list.Length - 1);
                    watch.Stop();
                    time = watch.ElapsedMilliseconds;
                    Console.WriteLine("Sort: {0}, Element count: {1}, Time in Milliseconds: {2}", name, elements, time);
                }

                else
                {
                    watch.Reset();
                    watch.Start();
                    sorter.sort(list, 0, list.Length);
                    watch.Stop();
                    time = watch.ElapsedMilliseconds;
                    Console.WriteLine("Sort: {0}, Element count: {1}, Time in Milliseconds: {2}", name, elements, time);
                }

                file.WriteLine("Sort: {0}, Element count: {1}, Time in Milliseconds: {2}", name, elements, time);

                elements -= 10000;
            }
            Console.WriteLine();
            file.WriteLine();
            file.Close();
        }
示例#41
0
        static void TestSorter(ISorter<int> sorter)
        {
            var arr = new[]
            { 8, 4, 3, 2, 5, 9, 6, 7, 1 };
            //{ 1, 2, 3, 4, 5, 7, 8, 9 };
            //{ 3, 2, 1, 9, 8, 7 };
            //{1, 6, 5, 5, 2, 1, 2, 6, 5, 5, 6};

            var list = new List<int>(arr);

            foreach (var i in list)
                Console.Write(" " + i);

            Console.WriteLine();

            sorter.Sort(list);

            foreach (var i in list)
                Console.Write(" " + i);
            /*
            // Test Reverse sequential list
            list = GetReverseSequentialTestList();
            sorter.Sort(list);
            AssertGeneralTestListSorted(list);
            */
            /*
            // Test allready sorted list
            list = GetSortedList();
            sorter.Sort(list);
            AssertGeneralTestListSorted(list);
            */
            // Test half sequential list
            //list = GetHalfSequentialList();
            //sorter.Sort(list);
            //AssertGeneralTestListSorted(list);
            /*
            // Test double numbers
            //list = GetDoubleNumbers();
            //sorter.Sort(list);
            //AssertDoubleNumbersList(list);
            */
        }
示例#42
0
        public void SetUp(int testIndex, ISorter<int> sorter)
        {
            Random rnd = new Random();

            this.list = new List<int>();

            //this.list = Enumerable.Range(0, this.CollectionCount(testIndex)).Reverse().ToList();

            int value = 0;

            for (int i = 0; i < this.CollectionCount(testIndex); ++i)
            {
                //this.list.Add(rnd.Next());
                value =
                    rnd.Next(100) < 80
                    ? value + rnd.Next(100)
                    : value - rnd.Next(100);
                this.list.Add(value);
            }
        }
 public HomeController(ISorter sorter)
 {
     _sorter = sorter;
 }      
示例#44
0
 static Program()
 {
     IContainer container = DependencyResolver.Container;
     _sorter = container.GetInstance<ISorter>();
 }
 static void RunSorter(int[] ints, ISorter sorter, string name)
 {
     sorter.sort(ints);
     AssertIfSorted(ints, name);
 }
示例#46
0
        private bool SortingCorrect(ISorter sorter)
        {
            var rand = new Random();
            int[] lengths = { 0, 1, 64, 65, 66, 67, 1023 };
            int length = -1;
            try
            {
                for (int j = 0; j < lengths.Length; ++j)
                {
                    length = lengths[j];
                    var nums = new int[length];
                    for (int i = 0; i < length; ++i)
                    {
                        nums[i] = rand.Next(int.MinValue, int.MaxValue);
                    }
                    sorter.Numbers = nums;
                    sorter.Sort();
                }
                sorter.Reset();
            }
            catch (SorterBase.NotSortedException)
            {
                Trace.TraceWarning("{0} failed with length {1}.", sorter.Name, length);
                return false;
            }

            return true;
        }
 public DependencyInjectionSortingEvaluator(ISorter sorter)
 {
     this.sorter = sorter;
 }
 private void InitializeSorter(ISorter<int> sorter)
 {
     this.sorter = sorter;
 }
示例#49
0
 public SorterTestBubble(ISorter sorter)
     : base(sorter)
 {
 }
示例#50
0
 public Apriori()
 {
     _sorter = ContainerProvider.Container.GetExportedValue<ISorter>();
 }
 public static void TestInt32SorterWhenCollectionIsNull(ISorter<int> sorter)
 {
     int[] numbers = null;
     sorter.Sort(numbers);
 }
示例#52
0
 public void TestFixtureSetUp()
 {
     _container = DependencyResolver.Container;
     _sorter = _container.GetInstance<ISorter>();
 }
示例#53
0
 public void Sort(ISorter sorter)
 {
     sorter.Sort(this.list);
 }
 static void TestSorter(ISorter sorter, string name)
 {
     a (name);
     int[] ints = new int[] { 5, 22, 7, 84, -2 };
     RunSorter(ints, sorter, name);
 }
 // Stopwatches the time it takes to do various sorts. Uses iterations to increase accuracy.
 public static double TimeSort( string name, ISorter SortFunction, int iterations = 100000)
 {
     Stopwatch watch = new Stopwatch ();
     int[] array = new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
     watch.Start ();
     for ( int i =0;i<iterations;i++ ){
         SortFunction.sort (array);
         // Reset
         array = new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
     }
     array = new int[]{ 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
     for ( int i =0;i<iterations;i++ ){
         SortFunction.sort (array);
         // Reset
         array = new int[]{ 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
     }
     array = new int[]{ 20, 1, 19, 2, 18, 3, 17, 4, 16, 5, 15, 6, 14, 7, 13, 8, 12, 9, 11, 10 };
     for ( int i =0;i<iterations;i++ ){
         SortFunction.sort (array);
         // Reset
         array = new int[]{ 20, 1, 19, 2, 18, 3, 17, 4, 16, 5, 15, 6, 14, 7, 13, 8, 12, 9, 11, 10 };
     }
     watch.Stop ();
     double time = ((double)watch.ElapsedMilliseconds)/(iterations);
     Console.WriteLine ( name +"\t took an average of " + time + " miliseconds.");
     return time;
 }
 internal SorterTest(ISorter<double> sorter)
 {
     Sorter = sorter;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScoreBoard" /> class.
 /// </summary>
 /// <param name="maxPlayers">Integer number.</param>
 public ScoreBoard(int maxPlayers)
 {
     this.sorter = new ComparerSorter();
     this.leaderBoard = this.ReadScores();
     this.MaxPlayers = maxPlayers;
 }
 public ClassLogic(ISorter sorter)
 {
     _sorter = sorter;
 }