From dc950b5fdb08081461143c4395ad6b34b656cdce Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Thu, 11 Feb 2016 22:55:13 -0800 Subject: [PATCH] +Unit test project + Added some unit tests on spheres/sphere script output. --- .../OSCADSharp.UnitTests.csproj | 89 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ .../OSCADSharp.UnitTests/SphereTests.cs | 57 ++++++++++++ OSCADSharp/OSCADSharp.sln | 6 ++ 4 files changed, 188 insertions(+) create mode 100644 OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj create mode 100644 OSCADSharp/OSCADSharp.UnitTests/Properties/AssemblyInfo.cs create mode 100644 OSCADSharp/OSCADSharp.UnitTests/SphereTests.cs diff --git a/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj b/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj new file mode 100644 index 0000000..66b6edd --- /dev/null +++ b/OSCADSharp/OSCADSharp.UnitTests/OSCADSharp.UnitTests.csproj @@ -0,0 +1,89 @@ + + + + Debug + AnyCPU + {73F78C4B-06E4-4ABF-B331-65ECF090E24E} + Library + Properties + OSCADSharp.UnitTests + OSCADSharp.UnitTests + v4.5.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.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 + + + + + + + + + + + + + + + + + + + + + + + {e420ce17-2f13-4abc-87d7-c9744df39d3d} + OSCADSharp + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file diff --git a/OSCADSharp/OSCADSharp.UnitTests/Properties/AssemblyInfo.cs b/OSCADSharp/OSCADSharp.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..90827a2 --- /dev/null +++ b/OSCADSharp/OSCADSharp.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OSCADSharp.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OSCADSharp.UnitTests")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("73f78c4b-06e4-4abf-b331-65ecf090e24e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OSCADSharp/OSCADSharp.UnitTests/SphereTests.cs b/OSCADSharp/OSCADSharp.UnitTests/SphereTests.cs new file mode 100644 index 0000000..6337958 --- /dev/null +++ b/OSCADSharp/OSCADSharp.UnitTests/SphereTests.cs @@ -0,0 +1,57 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OSCADSharp.Solids; + +namespace OSCADSharp.UnitTests +{ + [TestClass] + public class SphereTests + { + private Sphere sphere; + + [TestInitialize] + public void Setup() + { + this.sphere = new Sphere(10); + } + + [TestMethod] + public void Sphere_RadiusIsHalfofDiameter() + { + Assert.AreEqual(5, this.sphere.Radius); + } + + [TestMethod] + public void Sphere_ResolutionAffectsFNvalue_scriptWithFNof30RR() + { + this.sphere.Resolution = 30; + + string script = this.sphere.ToString(); + + Assert.IsTrue(script.Contains("$fn = 30")); + } + + [TestMethod] + public void Sphere_FAandFSAreAffectedByAngleANdFragmentSize_scriptWithMatchingAngleAndFragmentSize() + { + this.sphere.MinimumAngle = 2; + this.sphere.MinimumFragmentSize = 4; + + string script = this.sphere.ToString(); + + Assert.IsTrue(script.Contains("$fa = 2")); + Assert.IsTrue(script.Contains("$fs = 4")); + } + + [TestMethod] + public void Sphere_ParameterlessSphereHasMethodCallAndEndsWithSemicolon_scriptWithSphereMethodCall() + { + var basicSphere = new Sphere(); + + string script = basicSphere.ToString(); + + Assert.IsTrue(script.StartsWith("sphere(")); + Assert.IsTrue(script.EndsWith(");")); + } + } +} diff --git a/OSCADSharp/OSCADSharp.sln b/OSCADSharp/OSCADSharp.sln index 9eb3226..fa0c806 100644 --- a/OSCADSharp/OSCADSharp.sln +++ b/OSCADSharp/OSCADSharp.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSCADSharp", "OSCADSharp\OS EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSCADSharp.ConsoleTests", "OSCADSharp.ConsoleTests\OSCADSharp.ConsoleTests.csproj", "{E1010464-A816-4F86-AE22-8465C27723C4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSCADSharp.UnitTests", "OSCADSharp.UnitTests\OSCADSharp.UnitTests.csproj", "{73F78C4B-06E4-4ABF-B331-65ECF090E24E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {E1010464-A816-4F86-AE22-8465C27723C4}.Debug|Any CPU.Build.0 = Debug|Any CPU {E1010464-A816-4F86-AE22-8465C27723C4}.Release|Any CPU.ActiveCfg = Release|Any CPU {E1010464-A816-4F86-AE22-8465C27723C4}.Release|Any CPU.Build.0 = Release|Any CPU + {73F78C4B-06E4-4ABF-B331-65ECF090E24E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {73F78C4B-06E4-4ABF-B331-65ECF090E24E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {73F78C4B-06E4-4ABF-B331-65ECF090E24E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {73F78C4B-06E4-4ABF-B331-65ECF090E24E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE