-
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
54 changed files
with
887 additions
and
671 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
namespace Smab.Helpers; | ||
|
||
public static class DateTimeExtensions { | ||
internal static readonly string DD_MMM_YYYY = "dd MMM, yyyy"; | ||
internal static readonly string DD_MMMM_YYYY = "dd MMMM, yyyy"; | ||
private const string DD_MMM_YYYY = "dd MMM, yyyy"; | ||
private const string DD_MMMM_YYYY = "dd MMMM, yyyy"; | ||
|
||
public static string ToDateLongMonthYearString(this DateTime dateTime) => dateTime.ToString(DD_MMMM_YYYY); | ||
public static string ToDateLongMonthYearString(this DateOnly dateOnly) => dateOnly.ToString(DD_MMMM_YYYY); | ||
|
||
public static string ToDateShortMonthYearString(this DateTime dateTime) => dateTime.ToString(DD_MMM_YYYY); | ||
public static string ToDateShortMonthYearString(this DateOnly dateOnly) => dateOnly.ToString(DD_MMM_YYYY); | ||
} |
4 changes: 1 addition & 3 deletions
4
src/Smab.Helpers/HtmlHelpers/HtmlHelper.cs → src/Smab.Helpers/HtmlHelpers/HasClass.cs
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
namespace Smab.Helpers; | ||
|
||
public static class HtmlHelper { | ||
|
||
public static class HtmlHelpers { | ||
public static bool HasClass(this string classString, string className) | ||
=> classString.Split(' ').Contains(className, StringComparer.InvariantCultureIgnoreCase); | ||
|
||
} |
4 changes: 1 addition & 3 deletions
4
...mab.Helpers/Interfaces/ISimpleParsable.cs → ...lpers/InterfaceHelpers/ISimpleParsable.cs
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
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,4 @@ | ||
namespace Smab.Helpers; | ||
public static partial class LinqHelpers { | ||
public static bool IsIn<T>(this T value, IEnumerable<T> values) => values.Contains(value); | ||
} |
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,15 @@ | ||
using System.Numerics; | ||
|
||
namespace Smab.Helpers; | ||
|
||
public static partial class MathsHelpers { | ||
|
||
/// <summary> | ||
/// Finds the mean average and returns it as a double | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="numbers"></param> | ||
/// <returns></returns> | ||
public static double Mean<T>(this IEnumerable<T> numbers) where T : INumber<T> | ||
=> numbers.Select(n => Convert.ToDouble(n)).Average(); | ||
} |
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,27 @@ | ||
namespace Smab.Helpers; | ||
|
||
public static partial class MathsHelpers { | ||
/// <summary> | ||
/// Returns the values occurring the most times | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="array"></param> | ||
/// <returns></returns> | ||
public static IEnumerable<T> Modes<T>(this T[] array) { | ||
(T Key, int Count)[] counts = array | ||
.GroupBy(x => x) | ||
.Select(g => (g.Key, Count: g.Count())) | ||
.ToArray(); | ||
|
||
int maxCount = counts.Max(c => c.Count); | ||
|
||
IEnumerable<T>? modes = counts | ||
.Where(m => m.Count == maxCount) | ||
.Select(item => item.Key); | ||
|
||
foreach (T item in modes) { | ||
yield return item; | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace Smab.Helpers; | ||
public static partial class MathsHelpers { | ||
public static IEnumerable<Point> Transpose(this IEnumerable<Point> points) => points.Select(p => p.Transpose()); | ||
public static IEnumerable<Point> Transpose(this IEnumerable<Point> points) => points.Select(point => point.Transpose()); | ||
|
||
public static (T Item1, T Item2) Transpose<T>(this (T Item1, T Item2) item) => (item.Item2, item.Item1); | ||
} |
8 changes: 1 addition & 7 deletions
8
...b.Helpers/ParsingHelpers/BinaryHelpers.cs → ...Helpers/ParsingHelpers/AsBinaryFromHex.cs
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 |
---|---|---|
@@ -1,15 +1,9 @@ | ||
using System.Numerics; | ||
|
||
namespace Smab.Helpers; | ||
namespace Smab.Helpers; | ||
public static partial class ParsingHelpers { | ||
public static string AsBinaryFromHex(this string input) | ||
=> string.Join( | ||
string.Empty, | ||
input.Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0'))); | ||
public static string AsBinaryFromHex(this IEnumerable<string> input) | ||
=> string.Join(string.Empty, input.Select(AsBinaryFromHex)); | ||
|
||
|
||
public static T FromBinaryAs<T>(this string input, char zeroChar = '.', char oneChar = '#') where T : INumber<T> | ||
=> T.CreateChecked(T.Parse(input.Replace(zeroChar, '0').Replace(oneChar, '1'), System.Globalization.NumberStyles.BinaryNumber, null)); | ||
} |
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
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,7 @@ | ||
using System.Numerics; | ||
|
||
namespace Smab.Helpers; | ||
public static partial class ParsingHelpers { | ||
public static T FromBinaryAs<T>(this string input, char zeroChar = '.', char oneChar = '#') where T : INumber<T> | ||
=> T.CreateChecked(T.Parse(input.Replace(zeroChar, '0').Replace(oneChar, '1'), System.Globalization.NumberStyles.BinaryNumber, null)); | ||
} |
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 |
---|---|---|
@@ -1,26 +1,15 @@ | ||
namespace Smab.Helpers; | ||
public static partial class ParsingHelpers { | ||
public static string[] TrimmedSplit(this string s, string? separator = null) => | ||
s.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
|
||
public static string[] TrimmedSplit(this string s, char[]? separator) => | ||
s.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
|
||
public static string[] TrimmedSplit(this string s, char separator) | ||
=> s.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
|
||
public static string[] TrimmedSplit(this string s, char separator, int count) | ||
=> s.Split(separator, count, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
|
||
public static string[] TrimmedSplit(this string s, char[]? separator, int count) | ||
=> s.Split(separator, count, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
|
||
public static string[] TrimmedSplit(this string s, string[]? separator) | ||
=> s.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
|
||
public static string[] TrimmedSplit(this string s, string? separator, int count) | ||
=> s.Split(separator, count, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
|
||
public static string[] TrimmedSplit(this string s, string[]? separator, int count) | ||
=> s.Split(separator, count, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); | ||
private const StringSplitOptions RemoveEmptyAndTrim = StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries; | ||
|
||
public static string[] TrimmedSplit(this string s, string? separator = null) => s.Split(separator, RemoveEmptyAndTrim); | ||
|
||
public static string[] TrimmedSplit(this string s, char separator) => s.Split(separator, RemoveEmptyAndTrim); | ||
public static string[] TrimmedSplit(this string s, char[]? separator) => s.Split(separator, RemoveEmptyAndTrim); | ||
public static string[] TrimmedSplit(this string s, string[]? separator) => s.Split(separator, RemoveEmptyAndTrim); | ||
|
||
public static string[] TrimmedSplit(this string s, char separator, int count) => s.Split(separator, count, RemoveEmptyAndTrim); | ||
public static string[] TrimmedSplit(this string s, char[]? separator, int count) => s.Split(separator, count, RemoveEmptyAndTrim); | ||
public static string[] TrimmedSplit(this string s, string? separator, int count) => s.Split(separator, count, RemoveEmptyAndTrim); | ||
public static string[] TrimmedSplit(this string s, string[]? separator, int count) => s.Split(separator, count, RemoveEmptyAndTrim); | ||
} |
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...HelperMethodTests/AlgorithmHelperTests.cs → ...orithmHelperTests/AlgorithmHelperTests.cs
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
2 changes: 1 addition & 1 deletion
2
.../HelperMethodTests/SequenceHelperTests.cs → ...gorithmHelperTests/SequenceHelperTests.cs
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
14 changes: 14 additions & 0 deletions
14
test/Smab.Helpers.Test/DateTimeHelpers/DateTimeHelperTests.cs
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,14 @@ | ||
namespace Smab.Helpers.Test.DateTimeHelpers; | ||
public class DateTimeHelperTests { | ||
[Fact] | ||
public void MonthYear_Formats_ShouldBe() { | ||
DateTime dateTime = new(2024, 02, 15, 13, 01, 04); | ||
DateOnly dateOnly = new(2024, 09, 15); | ||
|
||
dateTime.ToDateLongMonthYearString().ShouldBe("15 February, 2024"); | ||
dateOnly.ToDateLongMonthYearString().ShouldBe("15 September, 2024"); | ||
|
||
dateTime.ToDateShortMonthYearString().ShouldBe("15 Feb, 2024"); | ||
dateOnly.ToDateShortMonthYearString().ShouldBe("15 Sept, 2024"); | ||
} | ||
} |
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,11 @@ | ||
namespace Smab.Helpers.Test.GridHelperTests; | ||
public class Create2dArray { | ||
[Fact] | ||
public void Create2dArray_ShouldBe() { | ||
char[,] array = ArrayHelpers.Create2dArray(5, 10, 'x'); | ||
Assert.Equal(5, array.GetUpperBound(0) + 1); | ||
Assert.Equal(10, array.GetUpperBound(1) + 1); | ||
Assert.Equal('x', array[0, 0]); | ||
Assert.Equal('x', array[3, 5]); | ||
} | ||
} |
Oops, something went wrong.