浏览代码

added tests

/generic-asset-sources
sleal-unity 4 年前
当前提交
f7eac831
共有 4 个文件被更改,包括 21 次插入11 次删除
  1. 1
      com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetListElement.cs
  2. 2
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSource.cs
  3. 2
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/LocalAssetSourceLocation.cs
  4. 27
      com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests/LocalAssetSourceTests.cs

1
com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetListElement.cs


{
var optionProperty = m_Property.GetArrayElementAtIndex(optionsIndex + i);
optionProperty.objectReferenceValue = assets[i];
m_Property.GetArrayElementAtIndex(i).floatValue = 0;
}
m_Property.serializedObject.ApplyModifiedProperties();

2
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSource.cs


public T SampleAsset()
{
CheckIfInitialized();
return assetSourceLocation.LoadAsset<T>((int)(m_Sampler.Sample() * count));
return count == 0 ? null : assetSourceLocation.LoadAsset<T>((int)(m_Sampler.Sample() * count));
}
/// <summary>

2
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/LocalAssetSourceLocation.cs


/// <summary>
/// The list of local assets available from this source
/// </summary>
[SerializeField] public List<Object> assets;
public List<Object> assets = new List<Object>();
/// <inheritdoc/>
public override int count => assets.Count;

27
com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests/LocalAssetSourceTests.cs


using NUnit.Framework;
using UnityEngine;
using UnityEngine.Perception.Randomization;
using UnityEngine.Perception.Randomization.Randomizers.SampleRandomizers.Tags;
namespace RandomizationTests.AssetSourceTests
{

public override void Preprocess(GameObject asset)
{
throw new System.NotImplementedException();
asset.AddComponent<RotationRandomizerTag>();
}
}

{
assetRole = null,
assetSourceLocation = new LocalAssetSourceLocation()
};
public AssetSource<Material> materialSource = new AssetSource<Material>
{
assetRole = null,
assetRole = new TestAssetRole(),
assetSourceLocation = new LocalAssetSourceLocation()
};
}

public void TearDown()
{
Object.DestroyImmediate(m_TestObject);
}
[Test]
public void GetZeroCountWithoutThrowingException()
{
Assert.DoesNotThrow(() =>
{
var count = m_Behaviour.gameObjectSource.count;
});
}
[Test]
public void SampleFromEmptySourceReturnsNull()
{
Assert.IsNull(m_Behaviour.gameObjectSource.SampleAsset());
Assert.IsNull(m_Behaviour.gameObjectSource.SampleInstance());
}
}
}
正在加载...
取消
保存