From ab692f94a73bf4203760408d3fb406ddc38ca47e Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Tue, 14 Jan 2020 12:47:19 -0500 Subject: [PATCH] Add unit tests for History class. Also introduce .editorconfig file and update .csproj files. GitOrigin-RevId: 60369ee53b0fe53135f4c2b7403284eabced3755 --- SharedTests/HistoryTests.cs | 47 +++++++++++++++++ SharedTests/Properties/AssemblyInfo.cs | 20 ++++++++ SharedTests/SharedTests.csproj | 70 ++++++++++++++++++++++++++ SharedTests/packages.config | 5 ++ 4 files changed, 142 insertions(+) create mode 100644 SharedTests/HistoryTests.cs create mode 100644 SharedTests/Properties/AssemblyInfo.cs create mode 100644 SharedTests/SharedTests.csproj create mode 100644 SharedTests/packages.config diff --git a/SharedTests/HistoryTests.cs b/SharedTests/HistoryTests.cs new file mode 100644 index 0000000..c16b746 --- /dev/null +++ b/SharedTests/HistoryTests.cs @@ -0,0 +1,47 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace SemiColinGames.Tests { + [TestClass] + public class HistoryTests { + [TestMethod] + public void TestLength() { + var h = new History(3); + Assert.AreEqual(3, h.Length); + } + + [TestMethod] + public void TestGetFromEmpty() { + var ints = new History(3); + Assert.AreEqual(0, ints[0]); + Assert.AreEqual(0, ints[1]); + Assert.AreEqual(0, ints[2]); + + var objects = new History(1); + Assert.AreEqual(null, objects[0]); + } + + [TestMethod] + public void TestAdds() { + var h = new History(3); + Assert.AreEqual("0 0 0", String.Format("{0} {1} {2}", h[0], h[1], h[2])); + h.Add(2); + Assert.AreEqual("2 0 0", String.Format("{0} {1} {2}", h[0], h[1], h[2])); + h.Add(3); + h.Add(5); + Assert.AreEqual("5 3 2", String.Format("{0} {1} {2}", h[0], h[1], h[2])); + h.Add(7); + Assert.AreEqual("7 5 3", String.Format("{0} {1} {2}", h[0], h[1], h[2])); + h.Add(11); + h.Add(13); + Assert.AreEqual("13 11 7", String.Format("{0} {1} {2}", h[0], h[1], h[2])); + } + + [TestMethod] + public void TestThrowsExceptions() { + var h = new History(3); + Assert.ThrowsException(() => h[-1]); + Assert.ThrowsException(() => h[3]); + } + } +} diff --git a/SharedTests/Properties/AssemblyInfo.cs b/SharedTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b93fdbf --- /dev/null +++ b/SharedTests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SharedTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SharedTests")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("c86694a5-dd99-4421-aa2c-1230f11c10f8")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SharedTests/SharedTests.csproj b/SharedTests/SharedTests.csproj new file mode 100644 index 0000000..e872bbf --- /dev/null +++ b/SharedTests/SharedTests.csproj @@ -0,0 +1,70 @@ + + + + + + Debug + AnyCPU + {C86694A5-DD99-4421-AA2C-1230F11C10F8} + Library + Properties + SharedTests + SharedTests + v4.7.2 + 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.2.0.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.0.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + + + 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/SharedTests/packages.config b/SharedTests/packages.config new file mode 100644 index 0000000..c7d3707 --- /dev/null +++ b/SharedTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file