您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
67 行
2.0 KiB
67 行
2.0 KiB
using System;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.Perception.Randomization.Parameters;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace RandomizationTests.ParameterTests
|
|
{
|
|
[TestFixture]
|
|
public class StructParameterTests
|
|
{
|
|
GameObject m_TestObject;
|
|
BaseStructParameterTest[] m_Tests;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
m_TestObject = new GameObject();
|
|
m_Tests = new BaseStructParameterTest[]
|
|
{
|
|
new NumericParameterTest<bool>(new BooleanParameter()),
|
|
new NumericParameterTest<int>(new IntegerParameter()),
|
|
new NumericParameterTest<float>(new FloatParameter()),
|
|
new NumericParameterTest<Vector2>(new Vector2Parameter()),
|
|
new NumericParameterTest<Vector3>(new Vector3Parameter()),
|
|
new NumericParameterTest<Vector4>(new Vector4Parameter()),
|
|
new NumericParameterTest<Color>(new ColorHsvaParameter()),
|
|
};
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
Object.DestroyImmediate(m_TestObject);
|
|
}
|
|
|
|
[Test]
|
|
public void EquivalentManagedAndNativeSamples()
|
|
{
|
|
foreach (var test in m_Tests)
|
|
test.GeneratesNativeSamples();
|
|
}
|
|
}
|
|
|
|
public abstract class BaseStructParameterTest
|
|
{
|
|
public abstract void GeneratesNativeSamples();
|
|
}
|
|
|
|
public class NumericParameterTest<T> : BaseStructParameterTest where T : struct
|
|
{
|
|
NumericParameter<T> m_Parameter;
|
|
|
|
public NumericParameterTest(NumericParameter<T> parameter)
|
|
{
|
|
m_Parameter = parameter;
|
|
}
|
|
|
|
public override void GeneratesNativeSamples()
|
|
{
|
|
var nativeSamples = m_Parameter.Samples(TestValues.TestSampleCount, out var handle);
|
|
handle.Complete();
|
|
Assert.AreEqual(nativeSamples.Length, TestValues.TestSampleCount);
|
|
nativeSamples.Dispose();
|
|
}
|
|
}
|
|
}
|