Skip to content

Commit c1cc5b7

Browse files
committed
Added unit tests for VectorExtensions
1 parent 11f0e24 commit c1cc5b7

File tree

6 files changed

+157
-0
lines changed

6 files changed

+157
-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: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 Vector3Collection_Average_Empty()
82+
{
83+
var vectors = new Vector3[] { };
84+
Assert.That(VectorExtensions.Average(vectors), Is.EqualTo(Vector3.zero));
85+
}
86+
87+
[Test]
88+
public void Vector3Collection_Average()
89+
{
90+
var vectors = new Vector3[] { new Vector3(1f, 2f, 3f), new Vector3(2f, 3f, 4f) };
91+
Assert.That(VectorExtensions.Average(vectors), Is.EqualTo(new Vector3(1.5f, 2.5f, 3.5f)));
92+
}
93+
94+
[Test]
95+
public void Vector3Collection_Median_Empty()
96+
{
97+
var vectors = new Vector3[] { };
98+
Assert.That(VectorExtensions.Median(vectors), Is.EqualTo(Vector3.zero));
99+
}
100+
101+
[Test]
102+
public void Vector3Collection_Median()
103+
{
104+
var vectors = new Vector3[] { new Vector3(10f, 10f, 10f), new Vector3(1f, 1f, 1f), new Vector3(5f, 5f, 5f) };
105+
Assert.That(VectorExtensions.Median(vectors), Is.EqualTo(new Vector3(5f, 5f, 5f)));
106+
}
107+
108+
}
109+
}

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.

0 commit comments

Comments
 (0)