浏览代码
[MLA-1879] culture-invariant sorting for sensors and actuators (#5194)
/check-for-ModelOverriders
[MLA-1879] culture-invariant sorting for sensors and actuators (#5194)
/check-for-ModelOverriders
GitHub
4 年前
当前提交
5415b004
共有 8 个文件被更改,包括 113 次插入 和 10 次删除
-
3com.unity.ml-agents/CHANGELOG.md
-
10com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
-
2com.unity.ml-agents/Runtime/Agent.cs
-
7com.unity.ml-agents/Runtime/Inference/BarracudaModelExtensions.cs
-
13com.unity.ml-agents/Runtime/Sensors/ISensor.cs
-
28com.unity.ml-agents/Tests/Editor/Actuators/ActuatorManagerTests.cs
-
57com.unity.ml-agents/Tests/Runtime/Sensor/SensorUtilTests.cs
-
3com.unity.ml-agents/Tests/Runtime/Sensor/SensorUtilTests.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Globalization; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using Unity.MLAgents.Sensors; |
|||
using Unity.MLAgents.Utils.Tests; |
|||
|
|||
namespace Unity.MLAgents.Tests |
|||
{ |
|||
|
|||
[TestFixture] |
|||
public class SensorUtilTests |
|||
{ |
|||
internal class TempCulture : IDisposable |
|||
{ |
|||
private CultureInfo m_OriginalCulture; |
|||
|
|||
internal TempCulture(CultureInfo newCulture) |
|||
{ |
|||
m_OriginalCulture = CultureInfo.CurrentCulture; |
|||
CultureInfo.CurrentCulture = newCulture; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
CultureInfo.CurrentCulture = m_OriginalCulture; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Test that sensors sort by name consistently across culture settings.
|
|||
/// Example strings and cultures taken from
|
|||
/// https://docs.microsoft.com/en-us/globalization/locale/sorting-and-string-comparison
|
|||
/// </summary>
|
|||
/// <param name="culture"></param>
|
|||
[TestCase("da-DK")] |
|||
[TestCase("en-US")] |
|||
public void TestSortCulture(string culture) |
|||
{ |
|||
List<ISensor> sensors = new List<ISensor>(); |
|||
var sensor0 = new TestSensor("Apple"); |
|||
var sensor1 = new TestSensor("Æble"); |
|||
sensors.Add(sensor0); |
|||
sensors.Add(sensor1); |
|||
|
|||
var originalCulture = CultureInfo.CurrentCulture; |
|||
CultureInfo.CurrentCulture = new CultureInfo(culture); |
|||
SensorUtils.SortSensors(sensors); |
|||
CultureInfo.CurrentCulture = originalCulture; |
|||
|
|||
Assert.AreEqual(sensor1, sensors[0]); |
|||
Assert.AreEqual(sensor0, sensors[1]); |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 929b34a718bc42c8aa75a3e1c8c11103 |
|||
timeCreated: 1617049947 |
撰写
预览
正在加载...
取消
保存
Reference in new issue