-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from nowsprinting/feature/gameobjectname_comparer
Add GameObjectNameComparer
- Loading branch information
Showing
7 changed files
with
117 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,23 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using UnityEngine; | ||
|
||
namespace TestHelper.Comparers | ||
{ | ||
/// <summary> | ||
/// Compare GameObjects by name. | ||
/// </summary> | ||
public class GameObjectNameComparer : IComparer<GameObject> | ||
{ | ||
/// <inheritdoc/> | ||
[SuppressMessage("ReSharper", "PossibleNullReferenceException")] | ||
public int Compare(GameObject x, GameObject y) | ||
{ | ||
return string.Compare(x.name, y.name, StringComparison.Ordinal); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,53 @@ | ||
// Copyright (c) 2023 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
namespace TestHelper.Comparers | ||
{ | ||
[TestFixture] | ||
public class GameObjectNameComparerTest | ||
{ | ||
[Test] | ||
public void UsingWithEqualTo_CompareGameObjectsByName() | ||
{ | ||
var actual = new GameObject("test object"); | ||
|
||
Assert.That(actual, Is.EqualTo(new GameObject("test object")).Using(new GameObjectNameComparer())); | ||
} | ||
|
||
[Test] | ||
public void UsingWithEqualTo_NotEqualName_Failure() | ||
{ | ||
var actual = new GameObject("actual object"); | ||
|
||
Assert.That(() => | ||
{ | ||
Assert.That(actual, Is.EqualTo(new GameObject("expected object")).Using(new GameObjectNameComparer())); | ||
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo( | ||
$" Expected: <expected object (UnityEngine.GameObject)>{Environment.NewLine} But was: <actual object (UnityEngine.GameObject)>{Environment.NewLine}")); | ||
} | ||
|
||
[Test] | ||
public void UsingWithCollection_CompareGameObjectsByName() | ||
{ | ||
var actual = new[] { new GameObject("test1"), new GameObject("test2"), new GameObject("test3"), }; | ||
|
||
Assert.That(actual, Does.Contain(new GameObject("test3")).Using(new GameObjectNameComparer())); | ||
} | ||
|
||
[Test] | ||
public void UsingWithCollection_NotContain_Failure() | ||
{ | ||
var actual = new[] { new GameObject("test1"), new GameObject("test2"), new GameObject("test3"), }; | ||
|
||
Assert.That(() => | ||
{ | ||
Assert.That(actual, Does.Contain(new GameObject("test4")).Using(new GameObjectNameComparer())); | ||
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo( | ||
$" Expected: collection containing <test4 (UnityEngine.GameObject)>{Environment.NewLine} But was: < <test1 (UnityEngine.GameObject)>, <test2 (UnityEngine.GameObject)>, <test3 (UnityEngine.GameObject)> >{Environment.NewLine}")); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.