Skip to content

Commit

Permalink
test: add ImageTransformationOptions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Jul 30, 2023
1 parent 40ee502 commit 698d2e2
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Assets/MediaPipeUnity/Samples/Mediapipe.Unity.Sample.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Mediapipe.Unity.Sample",
"rootNamespace": "",
"references": [
"GUID:04c4d86a70aa56c55a78c61f1ab1a56d"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/MediaPipeUnity/Tests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/MediaPipeUnity/Tests/EditMode.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions Assets/MediaPipeUnity/Tests/EditMode/ImageTransformationOptionsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) 2023 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

using NUnit.Framework;

namespace Mediapipe.Unity.Sample.Tests
{
public class ImageTransformationOptionsTest
{
// raw -> unrotated -> flip -> input image -> rotated
// a---------b a---------b c---------d a---------b a---------b
// | | | | | v | | | | |
// | ^ | | ^ | | | | ^ | | ^ |
// c---------d c---------d a---------b c---------d c---------d
[TestCase(false, false, RotationAngle.Rotation0, false, true, RotationAngle.Rotation0)]
// raw -> unrotated -> flip -> input image -> rotated
// a---------b a---------b a---------b a---------b a---------b
// | | | | | | | | | |
// | ^ | | ^ | | ^ | | ^ | | ^ |
// c---------d c---------d c---------d c---------d c---------d
[TestCase(false, true, RotationAngle.Rotation0, false, false, RotationAngle.Rotation0)]
// raw -> unrotated -> flip -> input image -> rotated
// a---------b a---------b d---------c b---------a b---------a
// | | | | | v | | | | |
// | ^ | | ^ | | | | ^ | | ^ |
// c---------d c---------d b---------a d---------c d---------c
[TestCase(true, false, RotationAngle.Rotation0, true, true, RotationAngle.Rotation0)]
// raw -> unrotated -> flip -> input image -> rotated
// a---------b a---------b b---------a b---------a b---------a
// | | | | | | | | | |
// | ^ | | ^ | | ^ | | ^ | | ^ |
// c---------d c---------d d---------c d---------c d---------c
[TestCase(true, true, RotationAngle.Rotation0, true, false, RotationAngle.Rotation0)]
// raw -> unrotated -> flip -> input image -> rotated
// b-----d a---------b b---------a d---------c b-----d
// | | | | | | | < | | |
// | ^ | | > | | < | | | | ^ |
// a-----c c---------d d---------c b---------a a-----c
[TestCase(false, false, RotationAngle.Rotation90, true, false, RotationAngle.Rotation270)]
// raw -> unrotated -> flip -> input image -> rotated
// b-----d a---------b d---------c d---------c b-----d
// | | | | | < | | < | | |
// | ^ | | > | | | | | | ^ |
// a-----c c---------d b---------a b---------a a-----c
[TestCase(false, true, RotationAngle.Rotation90, true, true, RotationAngle.Rotation270)]
// raw -> unrotated -> flip -> input image -> rotated
// b-----d a---------b d---------c b---------a d-----b
// | | | > | | | | < | | |
// | ^ | | | | < | | | | ^ |
// a-----c c---------d b---------a d---------c c-----a
[TestCase(true, false, RotationAngle.Rotation90, true, true, RotationAngle.Rotation270)]
// raw -> unrotated -> flip -> input image -> rotated
// b-----d a---------b b---------a b---------a d-----b
// | | | > | | < | | < | | |
// | ^ | | | | | | | | ^ |
// a-----c c---------d d---------c d---------c c-----a
[TestCase(true, true, RotationAngle.Rotation90, true, false, RotationAngle.Rotation270)]
// raw -> unrotated -> flip -> input image -> rotated
// d---------c a---------b c---------d a---------b d---------c
// | | | v | | | | v | | |
// | ^ | | | | ^ | | | | ^ |
// b---------a c---------d a---------b c---------d b---------a
[TestCase(false, false, RotationAngle.Rotation180, false, true, RotationAngle.Rotation180)]
// raw -> unrotated -> flip -> input image -> rotated
// d---------c a---------b a---------b a---------b d---------c
// | | | v | | v | | v | | |
// | ^ | | | | | | | | ^ |
// b---------a c---------d c---------d c---------d b---------a
[TestCase(false, true, RotationAngle.Rotation180, false, false, RotationAngle.Rotation180)]
// raw -> unrotated -> flip -> input image -> rotated
// d---------c a---------b d---------c b---------a c---------d
// | | | v | | | | v | | |
// | ^ | | | | ^ | | | | ^ |
// b---------a c---------d b---------a d---------c a---------b
[TestCase(true, false, RotationAngle.Rotation180, true, true, RotationAngle.Rotation180)]
// raw -> unrotated -> flip -> input image -> rotated
// d---------c a---------b b---------a b---------a c---------d
// | | | v | | v | | v | | |
// | ^ | | | | | | | | ^ |
// b---------a c---------d d---------c d---------c a---------b
[TestCase(true, true, RotationAngle.Rotation180, true, false, RotationAngle.Rotation180)]
// raw -> unrotated -> flip -> input image -> rotated
// c-----a a---------b b---------a d---------c c-----a
// | | | < | | > | | | | |
// | ^ | | | | | | > | | ^ |
// d-----b c---------d d---------c b---------a d-----b
[TestCase(false, false, RotationAngle.Rotation270, true, false, RotationAngle.Rotation90)]
// raw -> unrotated -> flip -> input image -> rotated
// c-----a a---------b d---------c d---------c c-----a
// | | | < | | | | | | |
// | ^ | | | | > | | > | | ^ |
// d-----b c---------d b---------a b---------a d-----b
[TestCase(false, true, RotationAngle.Rotation270, true, true, RotationAngle.Rotation90)]
// raw -> unrotated -> flip -> input image -> rotated
// c-----a a---------b d---------c b---------a a-----c
// | | | | | > | | | | |
// | ^ | | < | | | | > | | ^ |
// d-----b c---------d b---------a d---------c b-----d
[TestCase(true, false, RotationAngle.Rotation270, true, true, RotationAngle.Rotation90)]
// raw -> unrotated -> flip -> input image -> rotated
// c-----a a---------b b---------a b---------a a-----c
// | | | | | | | | | |
// | ^ | | < | | > | | > | | ^ |
// d-----b c---------d d---------c d---------c b-----d
[TestCase(true, true, RotationAngle.Rotation270, true, false, RotationAngle.Rotation90)]
public void TestBuild(
bool shouldFlipHorizontally, bool isFlippedVertically, RotationAngle rotationAngle,
bool flipHorizontally, bool flipVertically, RotationAngle expectedRotationAngle)
{
var options = ImageTransformationOptions.Build(shouldFlipHorizontally, isFlippedVertically, rotationAngle);
Assert.AreEqual(flipHorizontally, options.flipHorizontally);
Assert.AreEqual(flipVertically, options.flipVertically);
Assert.AreEqual(expectedRotationAngle, options.rotationAngle);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "MediaPipe.Unity.Sample.Tests.EditMode",
"rootNamespace": "",
"references": [
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:04c4d86a70aa56c55a78c61f1ab1a56d",
"GUID:f32148de13e8ca8369101d3ef3260930"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": true,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"Mediapipe.Runtime",
"Unity.PerformanceTesting"
"Mediapipe.Runtime"
],
"includePlatforms": [
"Editor"
Expand Down

0 comments on commit 698d2e2

Please sign in to comment.