C# PointByCoordinates

C# PointByCoordinates

In this section were going to finish the PointByCoordinates class and create Unit Tests for it.

Let’ start of with some changes to the Abstract Classes, Base Classes, and Interfaces.

Within the IPointBase3D Interface, I added a TranslatePointAlongVector method, to aid in calculating the points location relative to an AxisSystem.

C#

Within the PointBase3D Class, I created the method for the TranslatePointAlongVector, and also changed the SetCoordinates method to be a Virtual method so it can be overridden higher up the code stack. Also I added two operator methods, an Add and Subtract to make adding and subtracting points from each other easier. Finally the Equal method was fully defined so we can validate if two points are equal or not.

C#

Within the IVectorBase3D Interface and additional property was added for the Inverse Vector.

C#

And in the Implementation VectorBase3D Class, the Inverse Vector Property was defined and two constructors created, one default constructor and one which take I,J,K parameters.

C#

A lot has changed within the PointByCoordinates Class, all of the methods and property’s have been defined to allow the correct creation of a Point By Coordinates, with either a Reference Axis System or a Reference Point (but not both).

C#

Unit Testing

No Good Class is without a Unit Test to aid with Development and Production testing, there are Ten unit tests, which tests all of the end user interactions. Form the creation of a simple PointByCoordinate, to updating the initial XYZ values, Adding Reference Points and Reference AxisSystem’s and removing them.

This will help ensure we don’t break anything while making changes later on.

To do this first we need to add additional Solution Folders, Projects and Classes, not forgetting a couple of NuGet Packages.

Unit Testing Solution Changes

To build the Unit tests we need to add addition NuGet Packages, like FluentAssertions which will make building the unit testing easier.

Unit testing NuGet Packages

Finally we can add a new Class and build our Unit Test for PointByCoordinates.

Note :- on some of the cases I had to use System.Math.Round to simplify the resulting value so that the Should().Be(Value) could be kept simple, and ensure an exact match each time.

C#