Tanoda
TransformUtilTests.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using NUnit.Framework;
11
12namespace Leap.Unity.Tests {
13
14 public class TransformUtilTests {
15
16 private GameObject _gameObject;
17 private GameObject _child;
18
19 [SetUp]
20 public void Setup() {
21 _gameObject = new GameObject("__TEST OBJECT__");
22 _child = new GameObject("__CHILD OBJECT__");
23 _child.transform.SetParent(_gameObject.transform);
24 _gameObject.transform.rotation = Quaternion.Euler(45, 123, 888);
25 _child.transform.rotation = Quaternion.Euler(2, 44, 99);
26 }
27
28 [TearDown]
29 public void Teardown() {
30 Object.DestroyImmediate(_child);
31 Object.DestroyImmediate(_gameObject);
32 _child = null;
33 _gameObject = null;
34 }
35
36 [Test]
37 public void TransformRotationTest() {
38 AssertAlmostEqual(_gameObject.transform.TransformRotation(_child.transform.localRotation),
39 _child.transform.rotation);
40 }
41
42 [Test]
44 AssertAlmostEqual(_gameObject.transform.InverseTransformRotation(_child.transform.rotation),
45 _child.transform.localRotation);
46 }
47
48 private static void AssertAlmostEqual(Quaternion a, Quaternion b) {
49 for (int i = 0; i < 4; i++) {
50 Assert.That(a[i], Is.EqualTo(b[i]).Within(10).Ulps);
51 }
52 }
53 }
54}
UnityEngine.Object Object