public void SortHandler_Handle_SequenceHasNumbers_ReturnsSortResultWithExpectedValues() { IStringToCollectionParser <decimal> parser = new StubIStringToCollectionParser <decimal>() { ParseStringToCollectionString = (strSeq) => new decimal[] { 2, 1, 3 } }; IStepCounter stepCounter = new StubIStepCounter() { CountSwapOperation = () => { }, CountCompareOperation = () => { } }; ISortStrategyFactory factory = new StubISortStrategyFactory() { CreateSortSortAlgorithmEnumSortTypeEnumIStepCounter = (alg, type, counter) => new StubISortStrategy() { SortIEnumerableOfDecimal = (seq) => new StubISortResult() { CompareOperationsCountGet = () => 2, SwapOperationsCountGet = () => 1, SortedNumbersGet = () => new decimal[] { 1, 2, 3 } } } }; decimal[] expectedSequence = new decimal[] { 1, 2, 3 }; int expectedCompareCount = 2; int expectedSwapCount = 1; var handler = new SortHandler(parser, factory); ISortResult sortResult = handler.Handle("2 1 3", SortAlgorithmEnum.InsertionSort, SortTypeEnum.Ascending, stepCounter); Assert.AreEqual(expectedCompareCount, sortResult.CompareOperationsCount, "Comapare operations are not equal"); Assert.AreEqual(expectedSwapCount, sortResult.SwapOperationsCount, "Swap counts are not equal"); CollectionAssert.AreEqual(expectedSequence, sortResult.SortedNumbers.ToArray(), "Sequences are not equal."); }
public MainView() { InitializeComponent(); var sortHandler = new SortHandler(); var sortableData = new SortableData(length: 100); DataContext = new SortViewModel(ColPlot, sortHandler, sortableData); }
private void SortExecutionTimeTest(Stopwatch sw, int[] randomData, SortHandler sortHandler, string sortHandlerName) { var testData = (int[])randomData.Clone(); sw.Restart(); sortHandler(testData); sw.Stop(); _testOutputHelper.WriteLine((sortHandlerName + "耗时: ").PadRight(20, ' ') + sw.Elapsed); }
// Start is called before the first frame update void Start() { sortType = 0; controller = ScriptableObject.CreateInstance <ObjectListController>(); sortHandler = gameObject.AddComponent <SortHandler>(); stats = new SortStats(statsSize, statsAccesses, statsCompares, statsSwaps, statsDelay, controller.GetSize(), delay); OnSetup(); OnDelayUpdate(1); }
public void SortHandler_Handle_StepCounterIsNull_ThrowArgumentNullException() { IStringToCollectionParser <decimal> parser = new StubIStringToCollectionParser <decimal>(); string sequence = "1 2"; ISortStrategyFactory factory = new StubISortStrategyFactory(); var handler = new SortHandler(parser, factory); Assert.ThrowsException <ArgumentNullException>(() => handler.Handle(sequence, SortAlgorithmEnum.InsertionSort, SortTypeEnum.Ascending, null)); }
public static void Run(IComparable[] a, SortHandler sortMethod) { if (sortMethod == null) { throw new ArgumentNullException("sortMethod"); } sortMethod(a); Show(a); Console.WriteLine("Shorted:" + IsSorted(a).ToString()); }
public void RegisterHandler(string type) { switch (type) { case "Name": sortHandler = SortByName; break; case "Author": sortHandler = SortByAuthor; break; case "Publisher": sortHandler = SortByPublisher; break; } }
protected BaseLister(Workspace workspace, Options options, CommandRepository commandRepository) { Workspace = workspace; SortHandler = new SortHandler(this); NotificationHost = workspace.NotificationHost; GotView += GotTheView; Options = options; Options.PropertyChanged += Options_PropertyChanged; CommandRepository = commandRepository; PropertyProvider = GetPropertyProvider(); _loadingSpinnerTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; _loadingSpinnerTimer.Tick += LoadingSpinnerTimer_Tick; }
private void Sort_Test(SortHandler sortHandler) { int[] testData = null; int[] expectedData = null; sortHandler(testData); Assert.Equal(expectedData, testData); testData = new int[0]; expectedData = new int[0]; sortHandler(testData); Assert.Equal(expectedData, testData); testData = new int[] { 1 }; expectedData = new int[] { 1 }; sortHandler(testData); Assert.Equal(expectedData, testData); testData = new int[] { 2, 1 }; expectedData = new int[] { 1, 2 }; sortHandler(testData); Assert.Equal(expectedData, testData); testData = new int[] { 2, 1, 3 }; expectedData = new int[] { 1, 2, 3 }; sortHandler(testData); Assert.Equal(expectedData, testData); testData = new int[] { 4, 1, 3, 2 }; expectedData = new int[] { 1, 2, 3, 4 }; sortHandler(testData); Assert.Equal(expectedData, testData); testData = new int[] { 8, 1, 4, 1, 3, 2 }; expectedData = new int[] { 1, 1, 2, 3, 4, 8 }; sortHandler(testData); Assert.Equal(expectedData, testData); testData = GetRandomData(10000); expectedData = testData.OrderBy(p => p).ToArray(); sortHandler(testData); Assert.Equal(expectedData, testData); }
public QuickBubbleSorter(SortHandler handler) { itsSortHandler = handler; }
/** FAST */ bool ClickSortBar(Context cr, double x, double y) { cr.NewPath (); cr.MoveTo (0.0, 0.0); TextExtents te; cr.Color = ActiveColor; cr.RelMoveTo ( 0.0, ToolbarLabelFontSize * 0.4 ); Helpers.DrawText (cr, ToolbarTitleFontFamily, ToolbarTitleFontSize, SortLabel); cr.RelMoveTo ( 0.0, ToolbarLabelFontSize * -0.4 ); foreach (SortHandler sf in SortFields) { cr.Color = (SortField == sf) ? ActiveColor : InActiveColor; te = Helpers.GetTextExtents ( cr, ToolbarLabelFontFamily, ToolbarLabelFontSize, sf.Name); if (Helpers.CheckTextExtents(cr, te, x, y)) { SortField = sf; ResetZoom (); UpdateLayout (); return true; } Helpers.DrawText (cr, ToolbarLabelFontFamily, ToolbarLabelFontSize, sf.Name); Helpers.DrawText (cr, ToolbarLabelFontFamily, ToolbarLabelFontSize, " "); } return false; }
/** BLOCKING - startup dir latency */ public Filezoo(string dirname) { Selection = new Dictionary<string, bool> (); Renderer = new FSDraw (); clipboard = Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true)); SortField = SortFields[0]; SizeField = SizeFields[0]; Zoomer = new FlatZoomer (); Gdk.Colormap cm = Screen.RgbaColormap; if (cm != null && Screen.IsComposited) { Widget.DefaultColormap = cm; Colormap = cm; UseRgbaVisuals = true; } SetCurrentDir (dirname); Helpers.StartupProfiler.Time ("SetCurrentDir"); CanFocus = true; KeyPressEvent += delegate (object o, KeyPressEventArgs args) { Cancelled = true; Gdk.ModifierType state = args.Event.State; switch (args.Event.Key) { case Gdk.Key.Control_L: case Gdk.Key.Control_R: state |= Gdk.ModifierType.ControlMask; break; case Gdk.Key.Shift_L: case Gdk.Key.Shift_R: state |= Gdk.ModifierType.ShiftMask; break; case Gdk.Key.Alt_L: case Gdk.Key.Alt_R: state |= Gdk.ModifierType.Mod1Mask; break; } SetCursor (state); }; KeyReleaseEvent += delegate (object o, KeyReleaseEventArgs args) { Cancelled = true; if (args.Event.Key == Gdk.Key.Escape && Selection.Count > 0) { ClearSelection (); args.RetVal = true; } else if ((args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask) { switch (args.Event.Key) { case Gdk.Key.x: CutSelection(CurrentDirPath); break; case Gdk.Key.c: CopySelection(CurrentDirPath); break; case Gdk.Key.v: PasteSelection(CurrentDirPath); break; } } else { switch (args.Event.Key) { case Gdk.Key.Delete: TrashSelection (); break; case Gdk.Key.BackSpace: GoToParent (); break; case Gdk.Key.Home: SetCurrentDir (Helpers.HomeDir); break; } } Gdk.ModifierType state = args.Event.State; switch (args.Event.Key) { case Gdk.Key.Control_L: case Gdk.Key.Control_R: state &= ~Gdk.ModifierType.ControlMask; break; case Gdk.Key.Shift_L: case Gdk.Key.Shift_R: state &= ~Gdk.ModifierType.ShiftMask; break; case Gdk.Key.Alt_L: case Gdk.Key.Alt_R: state &= ~Gdk.ModifierType.Mod1Mask; break; } SetCursor (state); }; DragDataGet += delegate (object o, DragDataGetArgs args) { string items = "file://" + DragSourcePath; if (Selection.Count > 0 && Selection.ContainsKey(DragSourcePath)) items = GetSelectionData (); args.SelectionData.Set(args.SelectionData.Target, 8, System.Text.Encoding.UTF8.GetBytes(items)); args.SelectionData.Text = items; }; DragEnd += delegate { GetSelectionData (); Cancelled = true; dragInProgress = false; DragSourceEntry = null; DragSourcePath = null; }; /** DESCTRUCTIVE */ DragDataReceived += delegate (object sender, DragDataReceivedArgs e) { Cancelled = true; string targetPath = FindHit (Width, Height, e.X, e.Y, 8).Target.FullName; HandleSelectionData (e.SelectionData, e.Context.SuggestedAction, targetPath); }; Gtk.Drag.DestSet (this, DestDefaults.All, target_table, Gdk.DragAction.Move | Gdk.DragAction.Copy | Gdk.DragAction.Ask ); AddEvents((int)( Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.ScrollMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.KeyPressMask | Gdk.EventMask.KeyReleaseMask | Gdk.EventMask.LeaveNotifyMask )); ThreadStart ts = new ThreadStart (PreDrawCallback); Thread t = new Thread(ts); t.IsBackground = true; t.Start (); System.Timers.Timer t1 = new System.Timers.Timer(50); t1.Elapsed += new ElapsedEventHandler (CheckUpdates); System.Timers.Timer t2 = new System.Timers.Timer(1000); t2.Elapsed += new ElapsedEventHandler (LongMonitor); t1.Enabled = true; t2.Enabled = true; GLib.Timeout.Add (10, new GLib.TimeoutHandler(CheckRedraw)); Helpers.StartupProfiler.Total ("Pre-drawing startup"); }
static void Main(string[] args) { MyDatabase db = new MyDatabase(); var unsortedList = new List <TShirt>(db.TShirts); Console.WriteLine("Unsorted List:\n"); foreach (var shirt in unsortedList) { shirt.Output(); } ITShirtSort bubbleSortAscBySize = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Size, false); ITShirtSort bubbleSortDescBySize = new BubbleSort(OrderMethod.Descending, OrderByProperty.Size, false); ITShirtSort bubbleSortAscByColor = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Color, false); ITShirtSort bubbleSortDescByColor = new BubbleSort(OrderMethod.Descending, OrderByProperty.Color, false); ITShirtSort bubbleSortAscByFabric = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Fabric, false); ITShirtSort bubbleSortDescByFabric = new BubbleSort(OrderMethod.Descending, OrderByProperty.Fabric, false); ITShirtSort bubbleSortAscAll = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Size, true); ITShirtSort bubbleSortDescAll = new BubbleSort(OrderMethod.Descending, OrderByProperty.Size, true); ITShirtSort quickSortAscBySize = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Size, false); ITShirtSort quickSortDescBySize = new BubbleSort(OrderMethod.Descending, OrderByProperty.Size, false); ITShirtSort quickSortAscByColor = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Color, false); ITShirtSort quickSortDescByColor = new BubbleSort(OrderMethod.Descending, OrderByProperty.Color, false); ITShirtSort quickSortAscByFabric = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Fabric, false); ITShirtSort quickSortDescByFabric = new BubbleSort(OrderMethod.Descending, OrderByProperty.Fabric, false); ITShirtSort quickSortAscAll = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Size, true); ITShirtSort quickSortDescAll = new BubbleSort(OrderMethod.Descending, OrderByProperty.Size, true); ITShirtSort bucketSortAscBySize = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Size, false); ITShirtSort bucketSortDescBySize = new BubbleSort(OrderMethod.Descending, OrderByProperty.Size, false); ITShirtSort bucketSortAscByColor = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Color, false); ITShirtSort bucketSortDescByColor = new BubbleSort(OrderMethod.Descending, OrderByProperty.Color, false); ITShirtSort bucketSortAscByFabric = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Fabric, false); ITShirtSort bucketSortDescByFabric = new BubbleSort(OrderMethod.Descending, OrderByProperty.Fabric, false); ITShirtSort bucketSortAscAll = new BubbleSort(OrderMethod.Ascending, OrderByProperty.Size, true); ITShirtSort bucketSortDescAll = new BubbleSort(OrderMethod.Descending, OrderByProperty.Size, true); SortHandler sorter0 = new SortHandler(bubbleSortAscBySize, unsortedList); SortHandler sorter1 = new SortHandler(bubbleSortDescBySize, unsortedList); SortHandler sorter2 = new SortHandler(bubbleSortAscByColor, unsortedList); SortHandler sorter3 = new SortHandler(bubbleSortDescByColor, unsortedList); SortHandler sorter4 = new SortHandler(bubbleSortAscByFabric, unsortedList); SortHandler sorter5 = new SortHandler(bubbleSortDescByFabric, unsortedList); SortHandler sorter6 = new SortHandler(bubbleSortAscAll, unsortedList); SortHandler sorter7 = new SortHandler(bubbleSortDescAll, unsortedList); SortHandler sorter8 = new SortHandler(quickSortAscBySize, unsortedList); SortHandler sorter9 = new SortHandler(quickSortDescBySize, unsortedList); SortHandler sorter10 = new SortHandler(quickSortAscByColor, unsortedList); SortHandler sorter11 = new SortHandler(quickSortDescByColor, unsortedList); SortHandler sorter12 = new SortHandler(quickSortAscByFabric, unsortedList); SortHandler sorter13 = new SortHandler(quickSortDescByFabric, unsortedList); SortHandler sorter14 = new SortHandler(quickSortAscAll, unsortedList); SortHandler sorter15 = new SortHandler(quickSortDescAll, unsortedList); SortHandler sorter16 = new SortHandler(bucketSortAscBySize, unsortedList); SortHandler sorter17 = new SortHandler(bucketSortDescBySize, unsortedList); SortHandler sorter18 = new SortHandler(bucketSortAscByColor, unsortedList); SortHandler sorter19 = new SortHandler(bucketSortDescByColor, unsortedList); SortHandler sorter20 = new SortHandler(bucketSortAscByFabric, unsortedList); SortHandler sorter21 = new SortHandler(bucketSortDescByFabric, unsortedList); SortHandler sorter22 = new SortHandler(bucketSortAscAll, unsortedList); SortHandler sorter23 = new SortHandler(bucketSortDescAll, unsortedList); // Use a sorter between 0 and 23 to view the sorted list sorter0.Sort(); Console.WriteLine("\nSorted List:\n"); foreach (var shirt in unsortedList) { shirt.Output(); } }
public BubbleSorter(SortHandler handler) { itsSortHandler = handler; }