Skip to content

Commit 999916f

Browse files
authored
Merge pull request #278 from tier4/feature/regression_tests_framework
Regression tests with Unity Test Framework
2 parents d5d74d6 + 8ff6f3a commit 999916f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+6020
-0
lines changed

Assets/AWSIM/AWSIM.asmdef

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "AWSIM"
3+
}

Assets/AWSIM/AWSIM.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/RGLUnityPlugin/AWSIM.asmref

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"reference": "GUID:6adb9a5fec9cc8c478d3d8da6e48fe3b"
3+
}

Assets/RGLUnityPlugin/AWSIM.asmref.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Ros2ForUnity/AWSIM.asmref

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"reference": "GUID:6adb9a5fec9cc8c478d3d8da6e48fe3b"
3+
}

Assets/Ros2ForUnity/AWSIM.asmref.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
512 Bytes
Binary file not shown.

Assets/Tests.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Tests/EditMode.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using NUnit.Framework;
2+
using UnityEngine;
3+
using AWSIM;
4+
using UnityEngine.TestTools.Utils;
5+
6+
public class GnssSensorTest
7+
{
8+
FloatEqualityComparer floatComparer;
9+
Vector3EqualityComparer v3Comparer;
10+
11+
[OneTimeSetUp]
12+
public void OneTimeSetUp()
13+
{
14+
floatComparer = new FloatEqualityComparer(10e-6f);
15+
v3Comparer = new Vector3EqualityComparer(10e-6f);
16+
}
17+
18+
[Test]
19+
public void MgrsZero()
20+
{
21+
bool dataReceived = false;
22+
GameObject go = new GameObject();
23+
var sensor = go.AddComponent<GnssSensor>();
24+
sensor.OutputHz = 1;
25+
go.AddComponent<Environment>();
26+
27+
sensor.OnOutputData += (GnssSensor.OutputData data) =>
28+
{
29+
dataReceived = true;
30+
Assert.That(data.MgrsPosition, Is.EqualTo(Vector3.zero).Using(v3Comparer));
31+
};
32+
33+
sensor.Call("Start");
34+
sensor.SetPrivateFieldValue<float>("timer", 1.0f);
35+
sensor.Call("FixedUpdate");
36+
37+
Assert.IsTrue(dataReceived);
38+
UnityEngine.Object.DestroyImmediate(go);
39+
}
40+
41+
static Vector3[] gnssMgrsNonZeroValues = new Vector3[] {
42+
Vector3.one,
43+
new Vector3(-1.0f, 2.0f, 0.0f),
44+
Vector3.up
45+
};
46+
47+
[Test]
48+
public void MgrsNonZero([ValueSource("gnssMgrsNonZeroValues")] Vector3 value)
49+
{
50+
bool dataReceived = false;
51+
GameObject go = new GameObject();
52+
var sensor = go.AddComponent<GnssSensor>();
53+
var env = go.AddComponent<Environment>();
54+
env.SetPrivateFieldValue<Vector3>("mgrsOffsetPosition", value);
55+
56+
sensor.OnOutputData += (GnssSensor.OutputData data) =>
57+
{
58+
dataReceived = true;
59+
Assert.That(data.MgrsPosition, Is.EqualTo(value).Using(v3Comparer));
60+
};
61+
62+
sensor.Call("Start");
63+
sensor.SetPrivateFieldValue<float>("timer", 1.0f);
64+
sensor.Call("FixedUpdate");
65+
66+
Assert.IsTrue(dataReceived);
67+
UnityEngine.Object.DestroyImmediate(go);
68+
}
69+
70+
public static object[] gnssTranslateCases =
71+
{
72+
new object[] { new Vector3(1.0f, 0.0f, 1.0f), new Vector3(1.0f, -1.0f, 0.0f) },
73+
new object[] { new Vector3(-1.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f) },
74+
new object[] { new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(-1.0f, 1.0f, -1.0f) },
75+
};
76+
[TestCaseSource(nameof(gnssTranslateCases))]
77+
public void Translate(Vector3 translate, Vector3 expectedResult)
78+
{
79+
bool dataReceived = false;
80+
GameObject go = new GameObject();
81+
var sensor = go.AddComponent<GnssSensor>();
82+
sensor.OutputHz = 1;
83+
var env = go.AddComponent<Environment>();
84+
85+
go.transform.Translate(translate);
86+
87+
sensor.OnOutputData += (GnssSensor.OutputData data) =>
88+
{
89+
dataReceived = true;
90+
Assert.That(data.MgrsPosition, Is.EqualTo(expectedResult).Using(v3Comparer));
91+
};
92+
93+
sensor.Call("Start");
94+
sensor.SetPrivateFieldValue<float>("timer", 1.0f);
95+
sensor.Call("FixedUpdate");
96+
97+
Assert.IsTrue(dataReceived);
98+
UnityEngine.Object.DestroyImmediate(go);
99+
}
100+
}

Assets/Tests/EditMode/GnssSensorTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using NUnit.Framework;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
using UnityEngine.TestTools.Utils;
6+
using AWSIM;
7+
8+
public class ImuSensorTest
9+
{
10+
FloatEqualityComparer floatComparer;
11+
Vector3EqualityComparer v3Comparer;
12+
13+
[OneTimeSetUp]
14+
public void OneTimeSetUp()
15+
{
16+
floatComparer = new FloatEqualityComparer(10e-6f);
17+
v3Comparer = new Vector3EqualityComparer(10e-6f);
18+
}
19+
20+
[Test]
21+
public void Gravity()
22+
{
23+
bool dataReceived = false;
24+
GameObject go = new GameObject();
25+
var sensor = go.AddComponent<ImuSensor>();
26+
sensor.EnableGravity = true;
27+
28+
sensor.OnOutputData += (ImuSensor.OutputData data) => {
29+
dataReceived = true;
30+
Assert.That(data.LinearAcceleration.y, Is.EqualTo(Physics.gravity.y).Using(floatComparer));
31+
};
32+
33+
sensor.Call("Start");
34+
sensor.SetPrivateFieldValue<float>("timer", 1.0f);
35+
sensor.Call("FixedUpdate");
36+
37+
Assert.IsTrue(dataReceived);
38+
UnityEngine.Object.DestroyImmediate(go);
39+
}
40+
41+
[Test]
42+
public void NoGravity()
43+
{
44+
bool dataReceived = false;
45+
GameObject go = new GameObject();
46+
var sensor = go.AddComponent<ImuSensor>();
47+
sensor.EnableGravity = false;
48+
49+
sensor.OnOutputData += (ImuSensor.OutputData data) => {
50+
dataReceived = true;
51+
Assert.That(data.LinearAcceleration, Is.EqualTo(Vector3.zero).Using(v3Comparer));
52+
};
53+
54+
sensor.Call("Start");
55+
sensor.SetPrivateFieldValue<float>("timer", 1.0f);
56+
sensor.Call("FixedUpdate");
57+
58+
Assert.IsTrue(dataReceived);
59+
UnityEngine.Object.DestroyImmediate(go);
60+
}
61+
}

Assets/Tests/EditMode/ImuSensorTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Tests/EditMode/Tests.asmdef

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "Tests",
3+
"rootNamespace": "",
4+
"references": [
5+
"UnityEngine.TestRunner",
6+
"UnityEditor.TestRunner",
7+
"AWSIM",
8+
"AccessExtensions"
9+
],
10+
"includePlatforms": [
11+
"Editor"
12+
],
13+
"excludePlatforms": [],
14+
"allowUnsafeCode": true,
15+
"overrideReferences": true,
16+
"precompiledReferences": [
17+
"nunit.framework.dll",
18+
"autoware_auto_vehicle_msgs_assembly.dll",
19+
"autoware_auto_planning_msgs_assembly.dll",
20+
"autoware_auto_geometry_msgs_assembly.dll",
21+
"autoware_auto_mapping_msgs_assembly.dll",
22+
"geometry_msgs_assembly.dll",
23+
"nav_msgs_assembly.dll",
24+
"std_msgs_assembly.dll",
25+
"builtin_interfaces_assembly.dll",
26+
"action_msgs_assembly.dll",
27+
"autoware_auto_control_msgs_assembly.dll",
28+
"autoware_auto_perception_msgs_assembly.dll",
29+
"autoware_common_msgs_assembly.dll",
30+
"autoware_perception_msgs_assembly.dll",
31+
"sensor_msgs_assembly.dll"
32+
],
33+
"autoReferenced": true,
34+
"defineConstraints": [
35+
"UNITY_INCLUDE_TESTS"
36+
],
37+
"versionDefines": [],
38+
"noEngineReferences": false
39+
}

Assets/Tests/EditMode/Tests.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using NUnit.Framework;
2+
using AWSIM;
3+
using AWSIM.TrafficSimulation;
4+
using UnityEngine.TestTools.Utils;
5+
6+
using UnityEngine;
7+
8+
namespace Traffic
9+
{
10+
public class TrafficPrimitives
11+
{
12+
Vector3EqualityComparer v3Comparer;
13+
14+
[OneTimeSetUp]
15+
public void OneTimeSetUp() {
16+
// floatComparer = new FloatEqualityComparer(10e-6f);
17+
v3Comparer = new Vector3EqualityComparer(10e-6f);
18+
}
19+
20+
[Test]
21+
public void StopLineCentrerPoint()
22+
{
23+
StopLine stopLine = StopLine.Create(Vector3.zero, new Vector3(1, 0, 0));
24+
Assert.That(stopLine.CenterPoint, Is.EqualTo(new Vector3(0.5f, 0, 0)).Using(v3Comparer));
25+
}
26+
27+
28+
static Vector3[][] trafficLaneWaypoints = new Vector3[][] {
29+
new Vector3[] {new Vector3(0,0,0), new Vector3(1,0,0), new Vector3(2,0,0) },
30+
new Vector3[] {new Vector3(-1,0,1), new Vector3(1,0,1), new Vector3(2,0,2) },
31+
new Vector3[] {new Vector3(0,0,1), new Vector3(0,0,2), new Vector3(0,0,1) },
32+
new Vector3[] {new Vector3(-10,0,10), new Vector3(0,0,0), new Vector3(10,0,-10) },
33+
};
34+
[Test]
35+
public void TrafficLanePositions([ValueSource("trafficLaneWaypoints")] Vector3[] waypoints)
36+
{
37+
TrafficLane trafficLane = TrafficLane.Create(waypoints, TrafficLane.TurnDirectionType.STRAIGHT);
38+
Assert.That(trafficLane.transform.position, Is.EqualTo(waypoints[0]));
39+
}
40+
41+
[Test]
42+
public void TrafficLaneWithStopLine()
43+
{
44+
var waypoints = new Vector3[] {new Vector3(0, 0, -1.0f), new Vector3(0, 0, 0), new Vector3(0, 0, 1.0f) };
45+
TrafficLane trafficLane = TrafficLane.Create(waypoints, TrafficLane.TurnDirectionType.STRAIGHT);
46+
StopLine stopLine = StopLine.Create(new Vector3(-0.5f, 0, 0.2f), new Vector3(0.5f, 0, 0.2f));
47+
trafficLane.StopLine = stopLine;
48+
Assert.That(trafficLane.GetStopPoint(), Is.EqualTo(new Vector3(0.0f, 0, 0.2f)).Using(v3Comparer));
49+
}
50+
51+
[Test]
52+
public void TrafficLaneWithoutStopLine()
53+
{
54+
var waypoints = new Vector3[] {new Vector3(0, 0, -1.0f), new Vector3(0, 0, 0), new Vector3(0, 0, 1.0f) };
55+
TrafficLane trafficLane = TrafficLane.Create(waypoints, TrafficLane.TurnDirectionType.STRAIGHT);
56+
Assert.That(trafficLane.GetStopPoint(), Is.EqualTo(waypoints[0]).Using(v3Comparer));
57+
}
58+
}
59+
}
60+

Assets/Tests/EditMode/TrafficEditTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)