using OpenTK.Mathematics; namespace VectorAndMatrixTests { [TestClass] public class VectorTests { [TestMethod] public void Constructor() { // Use the Assert class to test conditions MyVector myVector = new MyVector(30, 40, 0); Vector3 Vector3 = new Vector3(30, 40, 0); Assert.AreEqual(Vector3.X, myVector.X); Assert.AreEqual(Vector3.Y, myVector.Y); Assert.AreEqual(Vector3.Z, myVector.Z); } [TestMethod] public void Add() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); MyVector secondVector = new MyVector(20, 30, 0); MyVector thirdVector = firstVector.Add(secondVector); Vector3 firstVector3 = new Vector3(30, 40, 0); Vector3 secondVector3 = new Vector3(20, 30, 0); Vector3 thirdVector3 = firstVector3 + secondVector3; Assert.AreEqual(thirdVector3.X, thirdVector.X); Assert.AreEqual(thirdVector3.Y, thirdVector.Y); Assert.AreEqual(thirdVector3.Z, thirdVector.Z); Assert.AreEqual(firstVector3.X, firstVector.X); Assert.AreEqual(firstVector3.Y, firstVector.Y); Assert.AreEqual(firstVector3.Z, firstVector.Z); Assert.AreEqual(secondVector3.X, secondVector.X); Assert.AreEqual(secondVector3.Y, secondVector.Y); Assert.AreEqual(secondVector3.Z, secondVector.Z); } [TestMethod] public void Subtract() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); MyVector secondVector = new MyVector(5, 10, 0); MyVector thirdVector = firstVector.Subtract(secondVector); Vector3 firstVector3 = new Vector3(30, 40, 0); Vector3 secondVector3 = new Vector3(5, 10, 0); Vector3 thirdVector3 = firstVector3 - secondVector3; Assert.AreEqual(thirdVector3.X, thirdVector.X); Assert.AreEqual(thirdVector3.Y, thirdVector.Y); Assert.AreEqual(thirdVector3.Z, thirdVector.Z); Assert.AreEqual(firstVector3.X, firstVector.X); Assert.AreEqual(firstVector3.Y, firstVector.Y); Assert.AreEqual(firstVector3.Z, firstVector.Z); Assert.AreEqual(secondVector3.X, secondVector.X); Assert.AreEqual(secondVector3.Y, secondVector.Y); Assert.AreEqual(secondVector3.Z, secondVector.Z); } [TestMethod] public void Multiply() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); float scalar = 10; MyVector secondVector = firstVector.Multiply(scalar); Vector3 firstVector3 = new Vector3(30, 40, 0); Vector3 secondVector3 = firstVector3 * scalar; Assert.AreEqual(firstVector3.X, firstVector.X); Assert.AreEqual(firstVector3.Y, firstVector.Y); Assert.AreEqual(firstVector3.Z, firstVector.Z); Assert.AreEqual(secondVector3.X, secondVector.X); Assert.AreEqual(secondVector3.Y, secondVector.Y); Assert.AreEqual(secondVector3.Z, secondVector.Z); } [TestMethod] public void Divide() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); float scalar = 10; MyVector secondVector = firstVector.Divide(scalar); Vector3 firstVector3 = new Vector3(30, 40, 0); Vector3 secondVector3 = firstVector3 / scalar; Assert.AreEqual(firstVector3.X, firstVector.X); Assert.AreEqual(firstVector3.Y, firstVector.Y); Assert.AreEqual(firstVector3.Z, firstVector.Z); Assert.AreEqual(secondVector3.X, secondVector.X); Assert.AreEqual(secondVector3.Y, secondVector.Y); Assert.AreEqual(secondVector3.Z, secondVector.Z); } [TestMethod] public void Magnitude() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); float magnitude = firstVector.Magnitude(); Vector3 firstVector3 = new Vector3(30, 40, 0); float magnitude4 = firstVector3.Length; Assert.AreEqual(magnitude4, magnitude); } [TestMethod] public void Normalise() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); MyVector normalisedVector = firstVector.Normalise(); float magnitude = normalisedVector.Magnitude(); Vector3 firstVector3 = new Vector3(30, 40, 0); Vector3 normalisedVector3 = Vector3.Normalize(firstVector3); float magnitude4 = normalisedVector3.Length; Assert.AreEqual(normalisedVector3.X, normalisedVector.X, 0.001); Assert.AreEqual(normalisedVector3.Y, normalisedVector.Y, 0.001); Assert.AreEqual(normalisedVector3.Z, normalisedVector.Z, 0.001); Assert.AreEqual(firstVector3.X, firstVector.X); Assert.AreEqual(firstVector3.Y, firstVector.Y); Assert.AreEqual(firstVector3.Z, firstVector.Z); } [TestMethod] public void DotProduct() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, -10); MyVector secondVector = new MyVector(40, -20, 40); float dotProduct = firstVector.DotProduct(secondVector); Vector3 firstVector3 = new Vector3(30, 40, -10); Vector3 secondVector3 = new Vector3(40, -20, 40); float dotProduct4 = Vector3.Dot(firstVector3, secondVector3); Assert.AreEqual(dotProduct4, dotProduct); } [TestMethod] public void Interpolate() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); MyVector secondVector = new MyVector(60, 80, 0); float interpolation = 0.25f; MyVector interpolatedVector = firstVector.Interpolate(secondVector, interpolation); Vector3 firstVector3 = new Vector3(30, 40, 0); Vector3 secondVector3 = new Vector3(60, 80, 0); Vector3 interpolatedVector3 = Vector3.Lerp(firstVector3, secondVector3, interpolation); Assert.AreEqual(interpolatedVector3.X, interpolatedVector.X); Assert.AreEqual(interpolatedVector3.Y, interpolatedVector.Y); Assert.AreEqual(interpolatedVector3.Z, interpolatedVector.Z); Assert.AreEqual(firstVector3.X, firstVector.X); Assert.AreEqual(firstVector3.Y, firstVector.Y); Assert.AreEqual(firstVector3.Z, firstVector.Z); Assert.AreEqual(secondVector3.X, secondVector.X); Assert.AreEqual(secondVector3.Y, secondVector.Y); Assert.AreEqual(secondVector3.Z, secondVector.Z); } [TestMethod] public void AngleBetween() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); MyVector secondVector = new MyVector(-40, 30, 0); float angleBetween = firstVector.AngleBetween(secondVector); Vector3 firstVector3 = new Vector3(30, 40, 0); Vector3 secondVector3 = new Vector3(-40, 30, 0); float angleBetween3 = Vector3.CalculateAngle(firstVector3, secondVector3); Assert.AreEqual(angleBetween3, angleBetween, 0.001); } [TestMethod] public void CrossProduct() { // Use the Assert class to test conditions MyVector firstVector = new MyVector(30, 40, 0); MyVector secondVector = new MyVector(-40, 30, 0); MyVector crossProduct = firstVector.CrossProduct(secondVector); Vector3 firstVector3 = new Vector3(30, 40, 0); Vector3 secondVector3 = new Vector3(-40, 30, 0); Vector3 crossProduct3 = Vector3.Cross(firstVector3, secondVector3); Assert.AreEqual(crossProduct3.X, crossProduct.X); Assert.AreEqual(crossProduct3.Y, crossProduct.Y); Assert.AreEqual(crossProduct3.Z, crossProduct.Z); Assert.AreEqual(firstVector3.X, firstVector.X); Assert.AreEqual(firstVector3.Y, firstVector.Y); Assert.AreEqual(firstVector3.Z, firstVector.Z); Assert.AreEqual(secondVector3.X, secondVector.X); Assert.AreEqual(secondVector3.Y, secondVector.Y); Assert.AreEqual(secondVector3.Z, secondVector.Z); } } }