-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using StpFoodBlazor.Models; | ||
|
||
namespace StpFoodBlazor.Helpers | ||
{ | ||
public static class DealSorter | ||
{ | ||
public static DealEvent[] SortDealEventsByName(DealEvent[]? DealEvents) | ||
{ | ||
if (DealEvents == null) | ||
{ | ||
return []; | ||
} | ||
|
||
Array.Sort(DealEvents, static (x, y) => | ||
string.Compare(x.Name, y.Name, StringComparison.Ordinal)); | ||
return [.. DealEvents]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using StpFoodBlazor.Helpers; | ||
using StpFoodBlazor.Models; | ||
|
||
namespace StpFoodBlazorTest.Helpers | ||
{ | ||
public class DealSorterTest | ||
{ | ||
[Fact] | ||
public void SortDealEventsByName_SortsCorrectly() | ||
{ | ||
var dealEvents = new DealEvent[] | ||
{ | ||
new() { Name = "Sawatdee Saint Paul" }, | ||
new() { Name = "Asian Express" }, | ||
new() { Name = "Afro Deli" } | ||
}; | ||
var expectedOrder = new DealEvent[] | ||
{ | ||
new() { Name = "Afro Deli" }, | ||
new() { Name = "Asian Express" }, | ||
new() { Name = "Sawatdee Saint Paul" } | ||
}; | ||
|
||
var sortedDealEvents = DealSorter.SortDealEventsByName(dealEvents); | ||
|
||
for (int i = 0; i < expectedOrder.Length; i++) | ||
{ | ||
Assert.Equal(expectedOrder[i].Name, sortedDealEvents[i].Name); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SortDealEventsByName_EmptyArray() | ||
{ | ||
// Arrange | ||
var dealEvents = new DealEvent[]{}; | ||
|
||
// Act | ||
var sortedDealEvents = DealSorter.SortDealEventsByName(dealEvents); | ||
|
||
// Assert | ||
Assert.Empty(sortedDealEvents); | ||
} | ||
|
||
[Fact] | ||
public void SortDealEventsByName_SingleElement() | ||
{ | ||
var dealEvents = new DealEvent[] | ||
{ | ||
new() { Name = "Afro Deli" } | ||
}; | ||
|
||
var sortedDealEvents = DealSorter.SortDealEventsByName(dealEvents); | ||
|
||
Assert.Single(sortedDealEvents); | ||
Assert.Equal("Afro Deli", sortedDealEvents[0].Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters