-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
53dd97c
commit 2aa4281
Showing
11 changed files
with
768 additions
and
300 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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" | ||
] | ||
} |
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,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" | ||
} |
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 |
---|---|---|
@@ -1,96 +1,87 @@ | ||
namespace GdUnit4.Asserts; | ||
using System; | ||
|
||
namespace GdUnit4.Asserts | ||
internal class VectorAssert<T> : AssertBase<T>, IVectorAssert<T> where T : notnull, IEquatable<T> | ||
{ | ||
|
||
class GodotVector<T> : IComparable<T> | ||
public VectorAssert(T current) : base(current) | ||
{ | ||
private T _value; | ||
|
||
public GodotVector(T vector) | ||
{ | ||
_value = vector; | ||
} | ||
|
||
public int CompareTo(T? other) | ||
{ | ||
if (other is Godot.Vector2 lv2 && _value is Godot.Vector2 rv2) | ||
return lv2 == rv2 ? 0 : lv2 < rv2 ? 1 : -1; | ||
if (other is Godot.Vector2I lv2i && _value is Godot.Vector2I rv2i) | ||
return lv2i == rv2i ? 0 : lv2i < rv2i ? 1 : -1; | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
internal class VectorAssert<T> : AssertBase<T>, IVectorAssert<T> where T : notnull, IEquatable<T> | ||
public IVectorAssert<T> IsBetween(T from, T to) | ||
{ | ||
private new GodotVector<T> Current { get; set; } | ||
if (CompareTo(Current, from) < 0 || CompareTo(Current, to) > 0) | ||
ThrowTestFailureReport(AssertFailures.IsBetween(Current, from, to), Current, from); | ||
return this; | ||
} | ||
|
||
public VectorAssert(T current) : base(current) | ||
{ | ||
Current = new GodotVector<T>(current); | ||
} | ||
public new IVectorAssert<T> IsEqual(T expected) => (IVectorAssert<T>)base.IsEqual(expected); | ||
|
||
public IVectorAssert<T> IsBetween(T from, T to) | ||
public IVectorAssert<T> IsEqualApprox(T expected, T approx) | ||
{ | ||
if (Current is Godot.Vector2 cur && expected is Godot.Vector2 e && approx is Godot.Vector2 a) | ||
{ | ||
if (Current.CompareTo(from) < 0 || Current.CompareTo(to) > 0) | ||
ThrowTestFailureReport(AssertFailures.IsBetween(base.Current, from, to), base.Current, from); | ||
return this; | ||
var from = e - a; | ||
var to = e + a; | ||
if (cur < from || cur > to) | ||
ThrowTestFailureReport(AssertFailures.IsBetween(Current, from, to), Current, from); | ||
} | ||
return this; | ||
} | ||
|
||
public new IVectorAssert<T> IsEqual(T expected) => (IVectorAssert<T>)base.IsEqual(expected); | ||
|
||
public IVectorAssert<T> IsEqualApprox(T expected, T approx) | ||
{ | ||
if (base.Current is Godot.Vector2 cur && expected is Godot.Vector2 e && approx is Godot.Vector2 a) | ||
{ | ||
Godot.Vector2 from = e - a; | ||
Godot.Vector2 to = e + a; | ||
if (cur < from || cur > to) | ||
ThrowTestFailureReport(AssertFailures.IsBetween(base.Current, from, to), base.Current, from); | ||
} | ||
return this; | ||
} | ||
public IVectorAssert<T> IsGreater(T expected) | ||
{ | ||
if (CompareTo(Current, expected) <= 0) | ||
ThrowTestFailureReport(AssertFailures.IsGreater(Current!, expected), Current, expected); | ||
return this; | ||
} | ||
|
||
public IVectorAssert<T> IsGreater(T expected) | ||
{ | ||
if (Current.CompareTo(expected) <= 0) | ||
ThrowTestFailureReport(AssertFailures.IsGreater(base.Current!, expected), base.Current, expected); | ||
return this; | ||
} | ||
public IVectorAssert<T> IsGreaterEqual(T expected) | ||
{ | ||
if (CompareTo(Current, expected) < 0) | ||
ThrowTestFailureReport(AssertFailures.IsGreaterEqual(Current!, expected), Current, expected); | ||
return this; | ||
} | ||
|
||
public IVectorAssert<T> IsGreaterEqual(T expected) | ||
{ | ||
if (Current.CompareTo(expected) < 0) | ||
ThrowTestFailureReport(AssertFailures.IsGreaterEqual(base.Current!, expected), Current, expected); | ||
return this; | ||
} | ||
public IVectorAssert<T> IsLess(T expected) | ||
{ | ||
if (CompareTo(Current, expected) >= 0) | ||
ThrowTestFailureReport(AssertFailures.IsLess(Current!, expected), Current, expected); | ||
return this; | ||
} | ||
|
||
public IVectorAssert<T> IsLess(T expected) | ||
{ | ||
if (Current.CompareTo(expected) >= 0) | ||
ThrowTestFailureReport(AssertFailures.IsLess(base.Current!, expected), base.Current, expected); | ||
return this; | ||
} | ||
public IVectorAssert<T> IsLessEqual(T expected) | ||
{ | ||
if (CompareTo(Current, expected) > 0) | ||
ThrowTestFailureReport(AssertFailures.IsLessEqual(Current!, expected), Current, expected); | ||
return this; | ||
} | ||
|
||
public IVectorAssert<T> IsLessEqual(T expected) | ||
{ | ||
if (Current.CompareTo(expected) > 0) | ||
ThrowTestFailureReport(AssertFailures.IsLessEqual(base.Current!, expected), base.Current, expected); | ||
return this; | ||
} | ||
public IVectorAssert<T> IsNotBetween(T from, T to) | ||
{ | ||
if (CompareTo(Current, from) >= 0 && CompareTo(Current, to) <= 0) | ||
ThrowTestFailureReport(AssertFailures.IsNotBetween(Current, from, to), Current, from); | ||
return this; | ||
} | ||
|
||
public IVectorAssert<T> IsNotBetween(T from, T to) | ||
{ | ||
if (Current.CompareTo(from) >= 0 && Current.CompareTo(to) <= 0) | ||
ThrowTestFailureReport(AssertFailures.IsNotBetween(base.Current, from, to), base.Current, from); | ||
return this; | ||
} | ||
|
||
public new IVectorAssert<T> IsNotEqual(T expected) => (IVectorAssert<T>)base.IsNotEqual(expected); | ||
public new IVectorAssert<T> IsNotEqual(T expected) => (IVectorAssert<T>)base.IsNotEqual(expected); | ||
|
||
public new IVectorAssert<T> OverrideFailureMessage(string message) => (IVectorAssert<T>)base.OverrideFailureMessage(message); | ||
public new IVectorAssert<T> OverrideFailureMessage(string message) => (IVectorAssert<T>)base.OverrideFailureMessage(message); | ||
|
||
private static int CompareTo(T? left, T right) | ||
{ | ||
if (left == null) | ||
return -1; | ||
return (left, right) switch | ||
{ | ||
(Godot.Vector2 l, Godot.Vector2 r) => l == r ? 0 : l > r ? 1 : -1, | ||
(Godot.Vector2I l, Godot.Vector2I r) => l == r ? 0 : l > r ? 1 : -1, | ||
(Godot.Vector3 l, Godot.Vector3 r) => l == r ? 0 : l > r ? 1 : -1, | ||
(Godot.Vector3I l, Godot.Vector3I r) => l == r ? 0 : l > r ? 1 : -1, | ||
(Godot.Vector4 l, Godot.Vector4 r) => l == r ? 0 : l > r ? 1 : -1, | ||
(Godot.Vector4I l, Godot.Vector4I r) => l == r ? 0 : l > r ? 1 : -1, | ||
_ => 0 | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.