您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
57 行
1.7 KiB
57 行
1.7 KiB
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]);
|
|
}
|
|
|
|
}
|
|
}
|