Skip to content

Toolbox library with handy classes, extension methods, etc.

License

Notifications You must be signed in to change notification settings

eduherminio/SheepTools

Repository files navigation

SheepTools

GitHub Actions Azure DevOps

Code coverage Sonar Quality Sonar vulnerabilities Sonar bugs Sonar code smells

SheepTools Nuget API
SheepTools.Moq Nuget API
SheepTools.XUnit Nuget API

SheepTools is a .NET toolbox library (yet another!) which contains handy classes, extension methods, etc.

It's divided in different libraries so that using the general purpose, main one doesn't imply adding any transitive dependencies to your project.

I'm more than happy to accept suggestions, comments, or addition proposals.

Relevant info

  • .NET Standard 2.0 and 2.1 were supported until v0.2.x.
  • Nullable is enabled from v0.2.x.

Content


SheepTools

Nuget

Point

2D Point class with an optional string Id.

IntPoint

Slim 2D Point class, using ints and without an optional string Value

IntPointWithValue

Slim 2D Point class, using ints and with and optional string Id

Point3D

3D point class with an optional string Id.

Line

2D (straight) line class.

BitMatrix

Class to work with bidimensional matrixes of bits.

BitArrayComparer

IEqualityComparer<BitArray> implementation

TreeNode

Tree node class with a generic key.

Node

Tree node class with a string key.

Essentially, TreeNode<string>.

Maths

General math algorithms

  • LeastCommonMultiple(this IEnumerable<ulong>)
  • LeastCommonMultiple(ulong, ulong)
  • GreatestCommonDivisor(this IEnumerable<ulong>)
  • GreatestCommonDivisor(ulong, ulong)

Ensure

Assert-style class that throws exceptions when things don't go as expected.

  • Equal() / NotEqual()
  • Equals() / NotEquals()
  • True() / False()
  • Null() / NotNull()
  • Empty() / NotEmpty()
  • NullOrEmpty() / NotNullOrEmpty()
  • NullOrWhiteSpace() / NotNullOrWhiteSpace()
  • Count<T>(int, IEnumerable<T>, Func<T, bool>)

RangeHelpers

Helper class to generate ranges of numbers before having to check if it was (a, b), [a, b] or (a, b] in Microsoft documentation every time I use Enumberable.Range.

  • GenerateRange(int, int) -> [a, b]

LinearInterpolation

Helper methods to interpolate 2D points

  • InterpolateLinearly(double, double, double, double, double)
  • InterpolateYLinearly(double, Point, point)
  • InterpolateXLinearly(double, Point, point)

AssemblyExtensions

  • GetTypes<TAttribute>()
  • GetTypesAndAttributes<TAttribute>()
  • GetAssemblies<TInterface>()

BitArrayExtensions

  • Reverse()
  • ToBitString()

CharExtensions

  • GetDirection()

CollectionExtensions

  • AddRange()
  • RemoveAll()

DateTimeExtensions

  • IsAfterNow()
  • IsAfter(DateTime)
  • MillisecondsFromEpoch()
  • StringId()

DictionaryExtensions

  • AddOrUpdate(TKey, TValue, Func<TKey, TValue, TValue>)
  • AddOrUpdate(TKey, Func<TKey, TValue>, Func<TKey, TValue, TValue>)
  • AddOrUpdate(TKey, Func<TKey, TArg, TValue>, Func<TKey, TValue, TArg, TValue>, TArg)

DirectionExtensions

  • TurnLeft()
  • TurnRight()
  • Turn180()
  • Opposite()

DoubleExtensions

  • DoubleEquals(double, precision)

EnumerableExtensions

  • ForEach()
  • IsNullOrEmpty()
  • IntersectAll()

IntExtensions

  • Factorial()
  • Clamp(int, int)

NumericExtensions

  • Clamp<T>(T, T)

StopwatchExtensions

  • ElapsedMilliseconds()
  • ToFriendlyString()

StringExtensions

  • IsEmpty()
  • IsWhiteSpace()
  • HasWhiteSpaces()
  • Truncate(int)
  • ReverseString()
  • ToBitArray(char = '1')
  • ToBoolEnumerable(char = '1')
  • RemoveBlanksAndMakeInvariant()
  • IsPalindrome()

Vector2Extensions

  • Move(Direction, int)
  • Move(char, int)
  • DistanceTo()
  • ManhattanDistance()
  • ChebyshevDistance()
  • RotateCounterclockwise()
  • RotateClockwise()
  • ToFriendlyString()

SheepTools.Moq

Nuget

Depends on Moq and Microsoft.Extensions.Logging.

MoqLoggerExtensions

Helps verifying ILogger invocations.

  • VerifyLog(LogLevel, Message, Times)

  • VerifyLog<TException>(LogLevel, Exception, Message, Times)

MoqGenericLoggerExtensions

Helps verifying ILogger<T> invocations.

  • VerifyLog<T>(LogLevel, Message, Times)

  • VerifyLog<T, TException>(LogLevel, Exception, Message, Times)

SheepTools.XUnit

Nuget

Depends on XUnit.

Asssert

  • DoesNotThrow(Action)
  • DoesNotThrow(Func<object)
  • DoesNotThrowAsync(Func<Task>)