Skip to content

Commit

Permalink
G-8: Provide generic vector assert
Browse files Browse the repository at this point in the history
# Why
We want to support all Godot vector types.

# What
Replaced the hard coded Vector2 and Vector3 assert by a generic vector assert to support all godot vector types
  • Loading branch information
Nullpointer committed Feb 29, 2024
1 parent bd8e300 commit 1adf50d
Show file tree
Hide file tree
Showing 15 changed files with 951 additions and 511 deletions.
474 changes: 474 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"ms-dotnettools.csharp",
"EditorConfig.EditorConfig",
"selcukermaya.se-csproj-extensions",
"josefpihrt-vscode.roslynator",
"streetsidesoftware.code-spell-checker",
"DavidAnson.vscode-markdownlint"
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"[csharp]": {
"editor.codeActionsOnSave": {
"source.addMissingImports": "explicit",
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": false
},
"csharp.semanticHighlighting.enabled": true,
"editor.semanticHighlighting.enabled": true,
"editor.formatOnSave": true,
"terminal.integrated.tabs.title": "${task}",
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableMsBuildLoadProjectsOnDemand": false,
"omnisharp.maxFindSymbolsItems": 3000,
"omnisharp.organizeImportsOnFormat": true,
"omnisharp.useModernNet": true,
"dotnet.unitTests.runSettingsPath": "./test/.runsettings"
}
39 changes: 34 additions & 5 deletions api/src/Assertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace GdUnit4
{
using System.Diagnostics.CodeAnalysis;
using Asserts;

/// <summary>
Expand Down Expand Up @@ -56,19 +55,29 @@ public sealed class Assertions
/// <returns></returns>
public static IEnumerableAssert AssertArray(IEnumerable? current) => new EnumerableAssert(current);

/// <summary>
/// An assertion method for all Godot vector types.
/// </summary>
/// <typeparam name="T">The type of Godot vector.</typeparam>
/// <param name="vector">The vector value to verify.</param>
/// <returns>An instance of IVectorAssert for further assertions.</returns>
public static IVectorAssert<T> AssertVector<T>(T vector) where T : notnull, IEquatable<T> => new VectorAssert<T>(vector);

/// <summary>
/// An Assertion to verify Godot.Vector2 values
/// </summary>
/// <param name="current">The current vector2 value to verify</param>
/// <returns></returns>
public static IVector2Assert AssertVec2(Godot.Vector2 current) => new Vector2Assert(current);
[Obsolete("AssertVec2 is deprecated, please use AssertVector instead.")]
public static IVectorAssert<Godot.Vector2> AssertVec2(Godot.Vector2 current) => AssertVector<Godot.Vector2>(current);

/// <summary>
/// An Assertion to verify Godot.Vector3 values
/// </summary>
/// <param name="current">The current vector3 value to verify</param>
/// <returns></returns>
public static IVector3Assert AssertVec3(Godot.Vector3 current) => new Vector3Assert(current);
[Obsolete("AssertVec3 is deprecated, please use AssertVector instead.")]
public static IVectorAssert<Godot.Vector3> AssertVec3(Godot.Vector3 current) => AssertVector<Godot.Vector3>(current);

/// <summary>
/// An Assertion used by test generation to notify the test is not yet implemented
Expand Down Expand Up @@ -103,6 +112,7 @@ public sealed class Assertions
public static INumberAssert<double> AssertThat(double current) => new NumberAssert<double>(current);
public static INumberAssert<decimal> AssertThat(decimal current) => new NumberAssert<decimal>(current);


public static IDictionaryAssert<K, V> AssertThat<K, V>(IDictionary<K, V>? current) where K : notnull
=> new DictionaryAssert<K, V>(current?.ToDictionary(e => e.Key, e => e.Value));

Expand All @@ -112,8 +122,18 @@ public sealed class Assertions
public static IDictionaryAssert<TKey, TValue> AssertThat<[Godot.MustBeVariant] TKey, [Godot.MustBeVariant] TValue>(Godot.Collections.Dictionary<TKey, TValue>? current) where TKey : notnull
=> new DictionaryAssert<TKey, TValue>(current);

public static IVector2Assert AssertThat(Godot.Vector2 current) => new Vector2Assert(current);
public static IVector3Assert AssertThat(Godot.Vector3 current) => new Vector3Assert(current);

/// <summary>
/// The dynamic assertions for all Godot vector types.
/// </summary>
/// <param name="current">The vector value to verify.</param>
/// <returns>An instance of IVectorAssert for further assertions.</returns>
public static IVectorAssert<Godot.Vector2> AssertThat(Godot.Vector2 current) => new VectorAssert<Godot.Vector2>(current);
public static IVectorAssert<Godot.Vector2I> AssertThat(Godot.Vector2I current) => new VectorAssert<Godot.Vector2I>(current);
public static IVectorAssert<Godot.Vector3> AssertThat(Godot.Vector3 current) => new VectorAssert<Godot.Vector3>(current);
public static IVectorAssert<Godot.Vector3I> AssertThat(Godot.Vector3I current) => new VectorAssert<Godot.Vector3I>(current);
public static IVectorAssert<Godot.Vector4> AssertThat(Godot.Vector4 current) => new VectorAssert<Godot.Vector4>(current);
public static IVectorAssert<Godot.Vector4I> AssertThat(Godot.Vector4I current) => new VectorAssert<Godot.Vector4I>(current);


/// <summary>
Expand Down Expand Up @@ -233,5 +253,14 @@ public static dynamic AssertThat<T>(T? current)
/// Builds an extractor by given method name and optional arguments
/// </summary>
public static IValueExtractor Extr(string methodName, params object[] args) => new ValueExtractor(methodName, args);


/// <summary>
/// Provides the expected line number via compile state.
/// Is primary designed to use on internal test coverage to validate the reported error line is correct.
/// </summary>
/// <param name="lineNumber"></param>
/// <returns></returns>
internal static int ExpectedLineNumber([System.Runtime.CompilerServices.CallerLineNumber] int lineNumber = 0) => lineNumber - 1;
}
}
79 changes: 0 additions & 79 deletions api/src/IVector2Assert.cs

This file was deleted.

79 changes: 0 additions & 79 deletions api/src/IVector3Assert.cs

This file was deleted.

79 changes: 79 additions & 0 deletions api/src/IVectorAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
namespace GdUnit4.Asserts;
using System;

/// <summary> An Assertion tool to verify Godot.Vector values </summary>
public interface IVectorAssert<T> : IAssertBase<T> where T : IEquatable<T>
{
/// <summary>
/// Verifies that the current value is equal to expected one.
/// </summary>
/// <param name="expected">The expected value</param>
/// <returns>IVectorAssert</returns>
public new IVectorAssert<T> IsEqual(T expected);

/// <summary>
/// Verifies that the current value is not equal to expected one.
/// </summary>
/// <param name="expected">The expected value</param>
/// <returns>IVectorAssert</returns>
public new IVectorAssert<T> IsNotEqual(T expected);

/// <summary>
/// Verifies that the current and expected value are approximately equal.
/// </summary>
/// <param name="expected">The expected value</param>
/// <param name="approx">The approximal value</param>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsEqualApprox(T expected, T approx);

/// <summary>
/// Verifies that the current value is less than the given one.
/// </summary>
/// <param name="expected">The expected value</param>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsLess(T expected);

/// <summary>
/// Verifies that the current value is less than or equal the given one.
/// </summary>
/// <param name="expected">The expected value</param>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsLessEqual(T expected);

/// <summary>
/// Verifies that the current value is greater than the given one.
/// </summary>
/// <param name="expected">The expected value</param>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsGreater(T expected);

/// <summary>
/// Verifies that the current value is greater than or equal the given one.
/// </summary>
/// <param name="expected">The expected value</param>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsGreaterEqual(T expected);

/// <summary>
/// Verifies that the current value is between the given boundaries (inclusive).
/// </summary>
/// <param name="min">The minimal value</param>
/// <param name="max">The maximal value</param>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsBetween(T min, T max);

/// <summary>
/// Verifies that the current value is not between the given boundaries (inclusive).
/// </summary>
/// <param name="min">The minimal value</param>
/// <param name="max">The maximal value</param>
/// <returns>IVectorAssert</returns>
public IVectorAssert<T> IsNotBetween(T min, T max);

/// <summary>
/// Overrides the default failure message by given custom message.
/// </summary>
/// <param name="message">The message to replace the default message</param>
/// <returns>IVectorAssert</returns>
new IVectorAssert<T> OverrideFailureMessage(string message);
}
Loading

0 comments on commit 1adf50d

Please sign in to comment.