-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
Add simple unit tests to project
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,26 @@ | ||
{ | ||
"name": "AGXUnityEditorTests", | ||
"rootNamespace": "", | ||
"references": [ | ||
"UnityEngine.TestRunner", | ||
"UnityEditor.TestRunner", | ||
"AGXUnity", | ||
"AGXUnityEditor", | ||
"TestingCommon" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using AGXUnity; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
using Assembly = System.Reflection.Assembly; | ||
|
||
namespace AGXUnityTesting | ||
{ | ||
public class EditorMetadataTests | ||
{ | ||
[Test] | ||
public void ScriptsHaveHelpURLs() | ||
{ | ||
var asm = Assembly.GetAssembly(typeof(RigidBody)); | ||
List<Type> missing = new List<Type>(); | ||
foreach ( var t in asm.ExportedTypes ) { | ||
if ( | ||
( | ||
t.IsSubclassOf( typeof( ScriptComponent ) ) || | ||
t.IsSubclassOf( typeof( ScriptAsset ) ) | ||
) && !t.IsAbstract ) { | ||
var help = t.GetCustomAttribute<HelpURLAttribute>(false); | ||
var hide = t.GetCustomAttribute<HideInInspector>(); | ||
if ( help == null && hide == null ) | ||
missing.Add( t ); | ||
} | ||
} | ||
|
||
if ( missing.Count > 0 ) { | ||
var errStr = $"The following classes are missing the HelpURL Attribute: \n"; | ||
foreach ( var t in missing ) { | ||
errStr += t.Name + "\n"; | ||
} | ||
Assert.Fail( errStr ); | ||
} | ||
} | ||
|
||
private void CheckScriptIconsInDirectory( string path ) | ||
{ | ||
if ( System.IO.Directory.Exists( path ) ) { | ||
foreach ( var subfile in System.IO.Directory.EnumerateFiles( path ) ) | ||
CheckScriptIconsInDirectory( subfile ); | ||
} | ||
else if ( path.EndsWith( ".cs" ) ) { | ||
var mi = AssetImporter.GetAtPath( path ) as MonoImporter; | ||
Assert.NotNull( mi.GetIcon(), $"Script file '{path}' has no icon" ); | ||
} | ||
|
||
} | ||
|
||
[Test] | ||
public void ScriptsHaveIcons() | ||
{ | ||
var sourceDir = AGXUnityEditor.IO.Utils.AGXUnitySourceDirectory; | ||
CheckScriptIconsInDirectory( sourceDir ); | ||
} | ||
} | ||
} |
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,123 @@ | ||
using AGXUnity.Model; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
namespace AGXUnityTesting | ||
{ | ||
public class TerrainGetSetTests | ||
{ | ||
private DeformableTerrain testTerrain; | ||
private Terrain unityTerrain; | ||
|
||
private const float HEIGHT_DELTA = 0.0005f; | ||
|
||
private float GetHeight( int x, int y, bool normalize = false ) | ||
{ | ||
var heightScale = normalize ? unityTerrain.terrainData.size.y : 1; | ||
var res = unityTerrain.terrainData.heightmapResolution; | ||
return ( 2 + Mathf.Sin( (float)y / res ) + Mathf.Cos( (float)x / res ) ) / heightScale; | ||
} | ||
|
||
private float RescaleUnityHeight( float height, bool normalized = false ) | ||
{ | ||
return height * ( normalized ? unityTerrain.terrainData.size.y : 1.0f ); | ||
} | ||
|
||
[SetUp] | ||
public void SetupWireScene() | ||
{ | ||
GameObject go = new GameObject("Test terrain"); | ||
|
||
unityTerrain = go.AddComponent<Terrain>(); | ||
unityTerrain.terrainData = new TerrainData(); | ||
unityTerrain.terrainData.size = new Vector3( 30, 20, 30 ); | ||
unityTerrain.terrainData.heightmapResolution = 33; | ||
|
||
float [,] heights = new float[33,33]; | ||
for ( int y = 0; y < 33; y++ ) | ||
for ( int x = 0; x < 33; x++ ) | ||
heights[ y, x ] = GetHeight( x, y, true ); | ||
|
||
unityTerrain.terrainData.SetHeights( 0, 0, heights ); | ||
|
||
testTerrain = go.AddComponent<DeformableTerrain>(); | ||
testTerrain.MaximumDepth = 2; | ||
} | ||
|
||
[Test] | ||
public void TestTerrainGetSingleHeight() | ||
{ | ||
var height = testTerrain.GetHeight( 16, 16 ); | ||
var expected = 2 + Mathf.Sin( (float)16 / 33 ) + Mathf.Cos( (float)16 /33 ); | ||
Assert.AreEqual( expected, height, HEIGHT_DELTA ); | ||
} | ||
|
||
[Test] | ||
public void TestTerrainGetMultipleHeights() | ||
{ | ||
var height = testTerrain.GetHeights( 10, 10, 10, 10 ); | ||
for ( int y = 0; y < 10; y++ ) | ||
for ( int x = 0; x < 10; x++ ) | ||
Assert.AreEqual( GetHeight( x+10, y+10 ), height[ y, x ], HEIGHT_DELTA ); | ||
} | ||
|
||
[Test] | ||
public void TestSetSingleHeight() | ||
{ | ||
testTerrain.SetHeight( 16, 16, 5f ); | ||
var result = testTerrain.GetHeight( 16, 16 ); | ||
|
||
Assert.AreEqual( 5f, result, HEIGHT_DELTA ); | ||
} | ||
|
||
[Test] | ||
public void TestSetSingleHeightIsPropagated() | ||
{ | ||
testTerrain.SetHeight( 16, 16, 5f ); | ||
|
||
var result = unityTerrain.terrainData.GetHeight( 16, 16 ); | ||
|
||
Assert.AreEqual( 5f, RescaleUnityHeight( result ), HEIGHT_DELTA ); | ||
} | ||
|
||
[Test] | ||
public void TestSetMultipleHeights() | ||
{ | ||
var source = new float[10,10]; | ||
var expected = new float[10,10]; | ||
for ( int y = 0; y < 10; y++ ) { | ||
for ( int x = 0; x < 10; x++ ) { | ||
source[ y, x ] = GetHeight( x, y ); | ||
expected[ y, x ] = GetHeight( x, y ); | ||
} | ||
} | ||
|
||
testTerrain.SetHeights( 10, 10, source ); | ||
var results = testTerrain.GetHeights( 10, 10, 10, 10 ); | ||
|
||
for ( int y = 0; y < 10; y++ ) | ||
for ( int x = 0; x < 10; x++ ) | ||
Assert.AreEqual( expected[ y, x ], results[ y, x ], HEIGHT_DELTA ); | ||
} | ||
|
||
[Test] | ||
public void TestSetMultipleHeightsArePropagated() | ||
{ | ||
var source = new float[10,10]; | ||
var expected = new float[10,10]; | ||
for ( int y = 0; y < 10; y++ ) { | ||
for ( int x = 0; x < 10; x++ ) { | ||
source[ y, x ] = GetHeight( x, y ); | ||
expected[ y, x ] = GetHeight( x, y ); | ||
} | ||
} | ||
testTerrain.SetHeights( 10, 10, source ); | ||
|
||
var results = unityTerrain.terrainData.GetHeights( 10, 10, 10, 10 ); | ||
|
||
for ( int y = 0; y < 10; y++ ) | ||
for ( int x = 0; x < 10; x++ ) | ||
Assert.AreEqual( expected[ y, x ], RescaleUnityHeight( results[ y, x ], true ), HEIGHT_DELTA ); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,27 @@ | ||
{ | ||
"name": "AGXUnityTests", | ||
"rootNamespace": "", | ||
"references": [ | ||
"UnityEngine.TestRunner", | ||
"UnityEditor.TestRunner", | ||
"AGXUnity", | ||
"TestingCommon" | ||
], | ||
"includePlatforms": [ | ||
"Editor", | ||
"LinuxStandalone64", | ||
"WindowsStandalone64" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS" | ||
], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.