}
// TODO: update this function once the perception camera doesn't skip the first frame
IEnumerator CreateNewScenario ( )
IEnumerator CreateNewScenario ( int totalIterations , int framesPerIteration )
yield return null ;
m_Scenario . constants . totalIterations = totalIterations ;
m_Scenario . constants . framesPerIteration = framesPerIteration ;
yield return null ; // Skip Start() frame
yield return null ; // Skip first Update() frame
yield return CreateNewScenario ( ) ;
yield return CreateNewScenario ( 1 0 , 1 0 ) ;
m_Scenario . serializedConstantsFileName = "perception_serialization_test" ;
var constants = new FixedLengthScenario . Constants
[UnityTest]
public IEnumerator IterationsCanLastMultipleFrames ( )
{
yield return CreateNewScenario ( ) ;
const int testIterationFrameCount = 5 ;
m_Scenario . constants . framesPerIteration = testIterationFrameCount ;
for ( var i = 0 ; i < testIterationFrameCount ; i + + )
const int frameCount = 5 ;
yield return CreateNewScenario ( 1 , frameCount ) ;
for ( var i = 0 ; i < frameCount ; i + + )
{
Assert . AreEqual ( 0 , m_Scenario . currentIteration ) ;
yield return null ;
[UnityTest]
public IEnumerator FinishesWhenIsScenarioCompleteIsTrue ( )
{
yield return CreateNewScenario ( ) ;
const int testIterationTotal = 5 ;
m_Scenario . constants . framesPerIteration = 1 ;
m_Scenario . constants . totalIterations = testIterationTotal ;
for ( var i = 0 ; i < testIterationTotal ; i + + )
const int iterationCount = 5 ;
yield return CreateNewScenario ( iterationCount , 1 ) ;
for ( var i = 0 ; i < iterationCount ; i + + )
{
Assert . False ( m_Scenario . isScenarioComplete ) ;
yield return null ;
[UnityTest]
public IEnumerator AppliesParametersEveryFrame ( )
{
yield return CreateNewScenario ( ) ;
m_Scenario . constants . framesPerIteration = 5 ;
m_Scenario . constants . totalIterations = 1 ;
var config = m_TestObject . AddComponent < ParameterConfiguration > ( ) ;
var parameter = config . AddParameter < Vector3Parameter > ( ) ;
parameter . x = new UniformSampler ( 1 , 2 ) ;
m_TestObject , m_TestObject . transform , "position" , ParameterApplicationFrequency . EveryFrame ) ;
var initialPosition = new Vector3 ( ) ;
m_TestObject . transform . position = initialPosition ;
var initialPosition = Vector3 . zero ;
yield return CreateNewScenario ( 1 , 5 ) ;
// ReSharper disable once Unity.InefficientPropertyAccess
Assert . AreNotEqual ( initialPosition , m_TestObject . transform . position ) ;
// ReSharper disable once Unity.InefficientPropertyAccess
initialPosition = m_TestObject . transform . position ;
// ReSharper disable once Unity.InefficientPropertyAccess
Assert . AreNotEqual ( initialPosition , m_TestObject . transform . position ) ;
}
parameter . z = new UniformSampler ( 1 , 2 ) ;
var transform = m_TestObject . transform ;
transform . p osition = new Vector3 ( ) ;
var prevP osition = new Vector3 ( ) ;
transform . position = prevPosition ;
yield return CreateNewScenario ( ) ;
m_Scenario . constants . framesPerIteration = 2 ;
m_Scenario . constants . totalIterations = 2 ;
yield return CreateNewScenario ( 2 , 2 ) ;
yield return new WaitForEndOfFrame ( ) ;
var initial Position = transform . position ;
Assert . AreNotEqual ( new Vector3 ( ) , initialPosition ) ;
Assert . AreNotEqual ( prevPosition , transform . position ) ;
// ReSharper disable once Unity.InefficientPropertyAccess
prev Position = transform . position ;
yield return new WaitForEndOfFrame ( ) ;
yield return null ;
// ReSharper disable once Unity.InefficientPropertyAccess
Assert . AreEqual ( prevPosition , transform . position ) ;
var nextPosition = transform . position ;
Assert . AreEqual ( initialPosition , nextPosition ) ;
prevPosition = transform . position ;
yield return new WaitForEndOfFrame ( ) ;
yield return null ;
Assert . AreNotEqual ( next Position, transform . position ) ;
Assert . AreNotEqual ( prev Position, transform . position ) ;
}
[UnityTest]
yield return CreateNewScenario ( ) ;
m_Scenario . constants . framesPerIteration = 2 ;
m_Scenario . constants . totalIterations = 2 ;
// Skip first frame
yield return new WaitForEndOfFrame ( ) ;
yield return CreateNewScenario ( 2 , 2 ) ;
yield return new WaitForEndOfFrame ( ) ;
yield return null ;
yield return new WaitForEndOfFrame ( ) ;
yield return null ;
Assert . AreEqual ( DatasetCapture . SimulationState . SequenceTime , 0 ) ;
}