Skip to content

Commit 33a127f

Browse files
author
Stephen Hodgson
authored
Merge pull request #427 from aalmada/UnitTests
Added unit tests for VectorExtensions
2 parents 77235f0 + b72f108 commit 33a127f

File tree

8 files changed

+209
-0
lines changed

8 files changed

+209
-0
lines changed

Assets/HoloToolkit-UnitTests.meta

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

Assets/HoloToolkit-UnitTests/Editor.meta

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

Assets/HoloToolkit-UnitTests/Editor/Utilities.meta

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

Assets/HoloToolkit-UnitTests/Editor/Utilities/Extensions.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using NUnit.Framework;
6+
using UnityEngine;
7+
8+
namespace HoloToolkit.Unity.Tests
9+
{
10+
public class VectorExtensionsTests
11+
{
12+
[Test]
13+
public void Vector2_Mul()
14+
{
15+
Vector2 value = new Vector2(2f, 3f);
16+
Vector2 scale = new Vector2(2f, 3f);
17+
Vector2 expected = new Vector2(4f, 9f);
18+
Assert.That(value.Mul(scale), Is.EqualTo(expected));
19+
}
20+
21+
[Test]
22+
public void Vector2_Div()
23+
{
24+
Vector2 value = new Vector2(2f, 3f);
25+
Vector2 scale = new Vector2(2f, 3f);
26+
Vector2 expected = new Vector2(1f, 1f);
27+
Assert.That(value.Div(scale), Is.EqualTo(expected));
28+
}
29+
30+
[Test]
31+
public void Vector3_Mul()
32+
{
33+
Vector3 value = new Vector3(2f, 3f, 4f);
34+
Vector3 scale = new Vector3(2f, 3f, 4f);
35+
Vector3 expected = new Vector3(4f, 9f, 16f);
36+
Assert.That(value.Mul(scale), Is.EqualTo(expected));
37+
}
38+
39+
[Test]
40+
public void Vector3_Div()
41+
{
42+
Vector3 value = new Vector3(2f, 3f, 4f);
43+
Vector3 scale = new Vector3(2f, 3f, 4f);
44+
Vector3 expected = new Vector3(1f, 1f, 1f);
45+
Assert.That(value.Div(scale), Is.EqualTo(expected));
46+
}
47+
48+
[Test]
49+
public void Vector3_RotateAround_Quaternion()
50+
{
51+
Vector3 point = new Vector3(0f, 0f, 0f);
52+
Vector3 pivot = new Vector3(1f, 1f, 1f);
53+
Quaternion rotation = Quaternion.AngleAxis(180f, new Vector3(0f, 0f, 1f));
54+
Vector3 expected = new Vector3(2f, 2f, 0f);
55+
Assert.That(point.RotateAround(pivot, rotation), Is.EqualTo(expected).Within(1f).Ulps);
56+
}
57+
58+
[Test]
59+
public void Vector3_RotateAround_Euler()
60+
{
61+
Vector3 point = new Vector3(0f, 0f, 0f);
62+
Vector3 pivot = new Vector3(1f, 1f, 1f);
63+
Vector3 rotation = new Vector3(0f, 0f, 180f);
64+
Vector3 expected = new Vector3(2f, 2f, 0f);
65+
Assert.That(point.RotateAround(pivot, rotation), Is.EqualTo(expected).Within(1f).Ulps);
66+
}
67+
68+
[Test]
69+
public void Vector3_TransformPoint()
70+
{
71+
throw new NotImplementedException();
72+
}
73+
74+
[Test]
75+
public void Vector3_InverseTransformPoint()
76+
{
77+
throw new NotImplementedException();
78+
}
79+
80+
[Test]
81+
public void Vector2Collection_Average_Empty()
82+
{
83+
var vectors = new Vector2[] { };
84+
Assert.That(VectorExtensions.Average(vectors), Is.EqualTo(Vector2.zero));
85+
}
86+
87+
[Test]
88+
public void Vector3Collection_Average_Empty()
89+
{
90+
var vectors = new Vector3[] { };
91+
Assert.That(VectorExtensions.Average(vectors), Is.EqualTo(Vector3.zero));
92+
}
93+
94+
[Test]
95+
public void Vector2Collection_Average()
96+
{
97+
var vectors = new Vector2[] { new Vector2(1f, 2f), new Vector2(2f, 3f) };
98+
Assert.That(VectorExtensions.Average(vectors), Is.EqualTo(new Vector2(1.5f, 2.5f)));
99+
}
100+
101+
[Test]
102+
public void Vector3Collection_Average()
103+
{
104+
var vectors = new Vector3[] { new Vector3(1f, 2f, 3f), new Vector3(2f, 3f, 4f) };
105+
Assert.That(VectorExtensions.Average(vectors), Is.EqualTo(new Vector3(1.5f, 2.5f, 3.5f)));
106+
}
107+
108+
[Test]
109+
public void Vector2Collection_Median_Empty()
110+
{
111+
var vectors = new Vector2[] { };
112+
Assert.That(VectorExtensions.Median(vectors), Is.EqualTo(Vector2.zero));
113+
}
114+
115+
[Test]
116+
public void Vector3Collection_Median_Empty()
117+
{
118+
var vectors = new Vector3[] { };
119+
Assert.That(VectorExtensions.Median(vectors), Is.EqualTo(Vector3.zero));
120+
}
121+
122+
[Test]
123+
public void Vector2Collection_Median()
124+
{
125+
var vectors = new Vector2[] { new Vector3(10f, 10f), new Vector2(1f, 1f), new Vector2(5f, 5f) };
126+
Assert.That(VectorExtensions.Median(vectors), Is.EqualTo(new Vector2(5f, 5f)));
127+
}
128+
129+
[Test]
130+
public void Vector3Collection_Median()
131+
{
132+
var vectors = new Vector3[] { new Vector3(10f, 10f, 10f), new Vector3(1f, 1f, 1f), new Vector3(5f, 5f, 5f) };
133+
Assert.That(VectorExtensions.Median(vectors), Is.EqualTo(new Vector3(5f, 5f, 5f)));
134+
}
135+
136+
}
137+
}

Assets/HoloToolkit-UnitTests/Editor/Utilities/Extensions/VectorExtensionsTests.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# HoloToolkit-UnitTests
2+
This folder will host unit tests that test individual HoloToolkit-Unity components.
3+
4+
#### Creating a unit test:
5+
6+
1. Unit tests can be located anywhere under an Editor folder but consider placing it under the HoloToolkit-UnitTests\Editor folder so that HoloToolkit-Unity can be easily deployed without the tests if required.
7+
2. Use the **NUnit 2.6.4** features to create the tests.
8+
3. Cover us much as possible the new code so that other people can test your code even without knowing its internals.
9+
4. Execute all the tests before submitting a pull request.
10+
11+
#### Running the unit tests:
12+
13+
1. Unit tests execution is integrated into the Unity editor (since 5.3).
14+
2. Open the **Editor Tests** window by clicking on the menu item **Window** | **Editor Tests Runner**.
15+
3. Click on the buttons **Run All**, **Run Selected** or **Run Failed** to run the tests.
16+

Assets/HoloToolkit-UnitTests/README.md.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.

0 commit comments

Comments
 (0)