diff --git a/.gitignore b/.gitignore
index 3831d65f88..3d42e0c8a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,7 @@ source/*.xml
#InnoSetup Output Folder
[Oo]utput/
+
+#NuGet for MS Unit Tests
+packages
+!packages/repositories.config
diff --git a/OpenBVE.sln b/OpenBVE.sln
index 7571bcde31..0c40eb266a 100644
--- a/OpenBVE.sln
+++ b/OpenBVE.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.26430.15
+VisualStudioVersion = 15.0.27004.2006
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{16553295-E70F-4596-AA78-848EEA576C4A}"
EndProject
@@ -40,6 +40,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DevTools", "DevTools", "{3D
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarXMLConvertor", "source\CarXMLConvertor\CarXMLConvertor.csproj", "{55901EEC-6FB3-4FB6-BDD9-C0E1042F3FBB}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenBve.Tests", "Tests\OpenBve.Tests.csproj", "{844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -198,6 +200,18 @@ Global
{55901EEC-6FB3-4FB6-BDD9-C0E1042F3FBB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{55901EEC-6FB3-4FB6-BDD9-C0E1042F3FBB}.Release|x86.ActiveCfg = Release|Any CPU
{55901EEC-6FB3-4FB6-BDD9-C0E1042F3FBB}.Release|x86.Build.0 = Release|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Debug|x86.Build.0 = Debug|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Release|x86.ActiveCfg = Release|Any CPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -210,4 +224,7 @@ Global
{06D89847-9C7A-47D5-8C7A-95AEBFFF5F1E} = {16553295-E70F-4596-AA78-848EEA576C4A}
{E9B64673-65B7-4D77-A4DB-4B441A7C9197} = {3D6660F8-52D2-4A30-8F1E-1922DDCF10F9}
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {FF9D9023-8499-47CB-A371-870A0E911645}
+ EndGlobalSection
EndGlobal
diff --git a/Tests/OpenBve.Tests.csproj b/Tests/OpenBve.Tests.csproj
new file mode 100644
index 0000000000..25320bd913
--- /dev/null
+++ b/Tests/OpenBve.Tests.csproj
@@ -0,0 +1,73 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {844BB77E-DC64-4405-8E20-8BA0EFCEAE7D}
+ Library
+ Properties
+ OpenBve.Tests
+ OpenBve.Tests
+ v4.6.1
+ 512
+ {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 15.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
+ False
+ UnitTest
+
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll
+
+
+ ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {27134980-4415-4375-a564-40a9014dfa5f}
+ OpenBveApi
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Tests/Properties/AssemblyInfo.cs b/Tests/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000000..12cec514d9
--- /dev/null
+++ b/Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,20 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("UnitTestProject1")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("UnitTestProject1")]
+[assembly: AssemblyCopyright("Copyright © 2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+[assembly: ComVisible(false)]
+
+[assembly: Guid("844bb77e-dc64-4405-8e20-8ba0efceae7d")]
+
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Tests/Vector3.cs b/Tests/Vector3.cs
new file mode 100644
index 0000000000..a9a5026f84
--- /dev/null
+++ b/Tests/Vector3.cs
@@ -0,0 +1,148 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using OpenBveApi.Math;
+
+namespace OpenBve.Tests
+{
+ using System;
+
+ [TestClass]
+ public class Vector3Tests
+ {
+ /// Tests the equality operator
+ [TestMethod]
+ public void Equals()
+ {
+ Vector3 v1 = new Vector3(0, 0, 0);
+ Vector3 v2 = new Vector3(0, 0, 0);
+ Assert.AreEqual(v1, v2);
+ Assert.IsTrue(v1 == v2);
+ Assert.IsFalse(v1 != v2);
+
+ v2 = new Vector3(3, 1, 5);
+ Assert.AreNotEqual(v1, v2);
+ Assert.IsFalse(v1 == v2);
+ Assert.IsTrue(v1 != v2);
+ }
+
+ /// Tests the addition operators
+ [TestMethod]
+ public void Addition()
+ {
+ //Simple addition
+ Vector3 v1 = new Vector3(4, 6, 2);
+ Vector3 v2 = new Vector3(1, 5, 7);
+ Vector3 v3 = v1 + v2;
+ Assert.AreEqual(new Vector3(5, 11, 9), v3);
+ v3 = v2 + v1;
+ Assert.AreEqual(new Vector3(5, 11, 9), v3);
+
+ //Vector and scalar
+ v1 = new Vector3(7, 18, 4);
+ v1 += 5;
+ Assert.AreEqual(new Vector3(12, 23, 9), v1);
+
+ //Scalar and vector
+ v1 = new Vector3(5, 13, 9);
+ v2 = 5 + v1;
+ Assert.AreEqual(new Vector3(10, 18, 14), v2);
+
+ }
+
+ /// Tests the subtraction operators
+ [TestMethod]
+ public void Subtraction()
+ {
+ //Simple subtraction
+ Vector3 v1 = new Vector3(4, 6, 2);
+ Vector3 v2 = new Vector3(1, 5, 7);
+ Vector3 v3 = v1 - v2;
+ Assert.AreEqual(new Vector3(3, 1, -5), v3);
+ v3 = v2 - v1;
+ Assert.AreEqual(new Vector3(-3, -1, 5), v3);
+
+ //Vector and scalar
+ v1 = new Vector3(7, 18, 4);
+ v1 -= 5;
+ Assert.AreEqual(new Vector3(2, 13, -1), v1);
+
+ //Scalar and vector
+ v1 = new Vector3(5, 13, 9);
+ v2 = 5 - v1;
+ Assert.AreEqual(new Vector3(0, -8, -4), v2);
+ }
+
+ /// Tests the negation operator
+ [TestMethod]
+ public void Negation()
+ {
+ Vector3 v1 = new Vector3(8, 13, 27);
+ v1 = -v1;
+ Assert.AreEqual(new Vector3(-8, -13, -27), v1);
+
+ v1 = new Vector3(-12, -2, -30);
+ v1 = -v1;
+ Assert.AreEqual(new Vector3(12, 2, 30), v1);
+
+ v1 = new Vector3(-24, 27, -15);
+ v1 = -v1;
+ Assert.AreEqual(new Vector3(24, -27, 15), v1);
+ }
+
+ /// Tests the multiplication operator
+ [TestMethod]
+ public void Multiplication()
+ {
+ //Mutliplication
+ Vector3 v1 = new Vector3(4, 6, 2);
+ Vector3 v2 = new Vector3(1, 5, 7);
+ Vector3 v3 = v1 * v2;
+ Assert.AreEqual(new Vector3(4, 30, 14), v3);
+
+ v1 = new Vector3(8, 12 , 9);
+ v2 = v1 * 12.5;
+ Assert.AreEqual(new Vector3(100, 150, 112.5), v2);
+
+ v1 = new Vector3(14, 3.5, 8);
+ v2 = 3.5 * v1;
+ Assert.AreEqual(new Vector3(49, 12.25, 28), v2);
+ }
+
+ /// Tests the division operator
+ [TestMethod]
+ public void Division()
+ {
+ Vector3 v1 = new Vector3(0, 0, 0);
+ Vector3 v2 = new Vector3(1, 5, 7);
+ Vector3 v3 = v1 / v2;
+ Assert.AreEqual(new Vector3(0, 0, 0), v3);
+
+ v1 = new Vector3(1, 6, 4);
+ v2 = new Vector3(2, 3, 5);
+ v3 = v1 / v2;
+ Assert.AreEqual(new Vector3(0.5, 2, 0.8), v3);
+
+ v1 = new Vector3(15.3, 9, 20.5);
+ v2 = v1 / 10;
+ Assert.AreEqual(new Vector3(1.53, 0.9, 2.05), v2);
+ }
+
+ /// Tests the division by zero vector exception
+ [TestMethod]
+ [ExpectedException(typeof(DivideByZeroException))]
+ public void DivisionByZeroVector()
+ {
+ Vector3 v1 = new Vector3(1, 5, 7);
+ Vector3 v2 = new Vector3(0, 0, 0);
+ Vector3 v3 = v1 / v2;
+ }
+
+ /// Tests the division by zero exception
+ [TestMethod]
+ [ExpectedException(typeof(DivideByZeroException))]
+ public void DivisionByZero()
+ {
+ Vector3 v1 = new Vector3(1, 5, 7);
+ Vector3 v3 = v1 / 0;
+ }
+ }
+}
diff --git a/Tests/packages.config b/Tests/packages.config
new file mode 100644
index 0000000000..d8c1b9099c
--- /dev/null
+++ b/Tests/packages.config
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/source/OpenBveApi/Vector2.cs b/source/OpenBveApi/Vector2.cs
index 86813c484d..a9df094629 100644
--- a/source/OpenBveApi/Vector2.cs
+++ b/source/OpenBveApi/Vector2.cs
@@ -1,6 +1,4 @@
-#pragma warning disable 0660, 0661
-
-using System;
+using System;
namespace OpenBveApi.Math {
/// Represents a two-dimensional vector.
@@ -168,10 +166,43 @@ public Vector2(double x, double y) {
if (a.Y != b.Y) return true;
return false;
}
-
-
+
+ /// Returns the hashcode for this instance.
+ /// An integer containing the unique hashcode for this instance.
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return (this.X.GetHashCode() * 397) ^ this.Y.GetHashCode();
+ }
+ }
+
+ /// Indicates whether this instance and a specified object are equal.
+ /// The object to compare to.
+ /// True if the instances are equal; false otherwise.
+ public override bool Equals(object obj)
+ {
+ if (!(obj is Vector2))
+ {
+ return false;
+ }
+
+ return this.Equals((Vector2)obj);
+ }
+
+ /// Checks whether the current vector is equal to the specified vector.
+ /// The specified vector.
+ /// Whether the two vectors are equal.
+ public bool Equals(Vector2 b)
+ {
+ if (this.X != b.X) return false;
+ if (this.Y != b.Y) return false;
+ return true;
+ }
+
+
// --- instance functions ---
-
+
/// Normalizes the vector.
/// Raised when the vector is a null vector.
public void Normalize() {
diff --git a/source/OpenBveApi/Vector3.cs b/source/OpenBveApi/Vector3.cs
index 4da859394b..877b5b1be6 100644
--- a/source/OpenBveApi/Vector3.cs
+++ b/source/OpenBveApi/Vector3.cs
@@ -1,6 +1,4 @@
-#pragma warning disable 0660, 0661
-
-using System;
+using System;
namespace OpenBveApi.Math {
/// Represents a three-dimensional vector.
@@ -185,7 +183,44 @@ public static Vector3 LinearInterpolate(Vector3 Vector1, Vector3 Vector2, double
if (a.Z != b.Z) return false;
return true;
}
-
+
+ /// Returns the hashcode for this instance.
+ /// An integer representing the unique hashcode for this instance.
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ var hashCode = this.X.GetHashCode();
+ hashCode = (hashCode * 397) ^ this.Y.GetHashCode();
+ hashCode = (hashCode * 397) ^ this.Z.GetHashCode();
+ return hashCode;
+ }
+ }
+
+ /// Indicates whether this instance and a specified object are equal.
+ /// The object to compare to.
+ /// True if the instances are equal; false otherwise.
+ public override bool Equals(object obj)
+ {
+ if (!(obj is Vector3))
+ {
+ return false;
+ }
+
+ return this.Equals((Vector3)obj);
+ }
+
+ /// Checks whether the current vector is equal to the specified vector.
+ /// The specified vector.
+ /// Whether the two vectors are equal.
+ public bool Equals(Vector3 b)
+ {
+ if (this.X != b.X) return false;
+ if (this.Y != b.Y) return false;
+ if (this.Z != b.Z) return false;
+ return true;
+ }
+
/// Checks whether the two specified vectors are unequal.
/// The first vector.
/// The second vector.