mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 21:48:34 +00:00
+ Added some tests for Cube
+ Adjusted some of the Sphere tests + Overrides for .Equals and .GetHashCode on Cube and Sphere
This commit is contained in:
parent
7efd7f161d
commit
7d59afbdd9
57
OSCADSharp/OSCADSharp.UnitTests/CubeTests.cs
Normal file
57
OSCADSharp/OSCADSharp.UnitTests/CubeTests.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OSCADSharp.Solids;
|
||||
|
||||
namespace OSCADSharp.UnitTests
|
||||
{
|
||||
[TestClass]
|
||||
public class CubeTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void Cube_LengthWidthHeightAffectSizeVector()
|
||||
{
|
||||
const double length = 10;
|
||||
const double width = 7;
|
||||
const double height = 9;
|
||||
|
||||
var cube = new Cube(length, width, height);
|
||||
|
||||
Assert.AreEqual(length, cube.Size.X);
|
||||
Assert.AreEqual(width, cube.Size.Y);
|
||||
Assert.AreEqual(height, cube.Size.Z);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Cube_SizeAppearsInOutput()
|
||||
{
|
||||
var cube = new Cube(new Vector3(1.5, 5.5, 8.7));
|
||||
|
||||
string script = cube.ToString();
|
||||
|
||||
Assert.IsTrue(script.Contains(String.Format("size = [{0}, {1}, {2}]", 1.5, 5.5, 8.7)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Cube_CloneYieldsEqualObject()
|
||||
{
|
||||
var cube = new Cube(new Vector3(1.5, 5.5, 8.7));
|
||||
|
||||
var clone = cube.Clone();
|
||||
|
||||
Assert.IsTrue(clone.Equals(cube));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Cube_ParameterlessCubeHasMethodCallInIt()
|
||||
{
|
||||
var cube = new Cube();
|
||||
|
||||
string script = cube.ToString();
|
||||
|
||||
Assert.IsTrue(script.StartsWith("cube("));
|
||||
Assert.IsTrue(script.EndsWith(");"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,11 +45,14 @@
|
||||
</When>
|
||||
<Otherwise>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="CubeTests.cs" />
|
||||
<Compile Include="SphereTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -22,7 +22,7 @@ namespace OSCADSharp.UnitTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Sphere_ResolutionAffectsFNvalue_scriptWithFNof30RR()
|
||||
public void Sphere_ResolutionAffectsFNvalue()
|
||||
{
|
||||
this.sphere.Resolution = 30;
|
||||
|
||||
@ -32,7 +32,7 @@ namespace OSCADSharp.UnitTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Sphere_FAandFSAreAffectedByAngleANdFragmentSize_scriptWithMatchingAngleAndFragmentSize()
|
||||
public void Sphere_FAandFSAreAffectedByAngleANdFragmentSize()
|
||||
{
|
||||
this.sphere.MinimumAngle = 2;
|
||||
this.sphere.MinimumFragmentSize = 4;
|
||||
@ -44,7 +44,7 @@ namespace OSCADSharp.UnitTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Sphere_ParameterlessSphereHasMethodCallAndEndsWithSemicolon_scriptWithSphereMethodCall()
|
||||
public void Sphere_ParameterlessSphereHasMethodCallAndEndsWithSemicolon()
|
||||
{
|
||||
var basicSphere = new Sphere();
|
||||
|
||||
@ -55,7 +55,7 @@ namespace OSCADSharp.UnitTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Sphere_CloneCoversEveryAttribute_copyWithAllAttributes()
|
||||
public void Sphere_CloneYieldsEqualObject()
|
||||
{
|
||||
var sphere = new Sphere()
|
||||
{
|
||||
|
||||
@ -23,6 +23,9 @@ namespace OSCADSharp.Scripting
|
||||
this.innerCode = innerCode;
|
||||
}
|
||||
|
||||
//TODO: Assess perf and find a better performing way to apply indentation
|
||||
// this approach will likely be a big performance drain with deeply nested structures.
|
||||
// -MLS 2/12/2016
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@ -43,6 +43,22 @@ namespace OSCADSharp.Solids
|
||||
this.Size = size ?? new Vector3(1, 1, 1);
|
||||
this.Center = center;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Cube object with Length/Width/Height
|
||||
/// </summary>
|
||||
/// <param name="length">Size on the X axis</param>
|
||||
/// <param name="width">Size on the Y axis</param>
|
||||
/// <param name="height">Size on the Z axis</param>
|
||||
/// <param name="center">Indicates whether the cube should be centered on the origin</param>
|
||||
public Cube(double length, double width, double height, bool center = false)
|
||||
{
|
||||
this.Size.X = length;
|
||||
this.Size.Y = width;
|
||||
this.Size.Z = height;
|
||||
|
||||
this.Center = center;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
@ -60,6 +76,24 @@ namespace OSCADSharp.Solids
|
||||
Center = this.Center
|
||||
};
|
||||
}
|
||||
|
||||
public override bool Equals(object other)
|
||||
{
|
||||
if (other.GetType() == typeof(Cube))
|
||||
{
|
||||
Cube otherSphere = other as Cube;
|
||||
return this.GetHashCode() == other.GetHashCode();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.ToString().GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,20 +83,25 @@ namespace OSCADSharp.Solids
|
||||
|
||||
public override bool Equals(object other)
|
||||
{
|
||||
// This logic is because we want to prevent the weird scenario
|
||||
// where perhaps this sphere is being compared to a string that's an
|
||||
// exact match to this sphere's string output. Since the hashcode is
|
||||
// borrowed from the string output
|
||||
if(other.GetType() == typeof(Sphere))
|
||||
{
|
||||
Sphere otherSphere = other as Sphere;
|
||||
return this.Diameter == otherSphere.Diameter &&
|
||||
this.Radius == otherSphere.Radius &&
|
||||
this.MinimumAngle == otherSphere.MinimumAngle &&
|
||||
this.MinimumFragmentSize == otherSphere.MinimumFragmentSize &&
|
||||
this.Resolution == otherSphere.Resolution;
|
||||
return this.GetHashCode() == other.GetHashCode();
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.Equals(other);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.ToString().GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user