Take home challenge to determine the type of a triangle. (EQUILATERAL / ISOSCELES / SCALENE ) https://vinitapenmatsa.github.io/Triangle-Challenge/
Instructions
Implementation Details
Tests Results / Code Coverage
- Git clone the repository.
- mvn clean install - to generate target resources.
- mvn spring-boot:run (default port 8000 - optionally specify your own port with : -Dserver.port=YOUR_PORT_NUMBER ).
Note : you can also run this as a java application using : java -jar target/Triangle-Challenge-0.0.1-SNAPSHOT.jar. - Once Application is up and running , you can access the API end points using swagger UI on your localhost and port number. Example : http://localhost:8000/swagger-ui.html ( change port number if required )
- Test API Results.
- Included Jacoco dependency for test coverage reports.
- Also Included a Bash script to test REST end points, if needed to run as a bash script. ( change port number accordigly )
I have used Java + Spring boot to implement the solution simply because spring boot is easy to setup and offers a wide variety of features for building services and web applications.
Application Exposes The Following API
- getTriangleType :
takes an array of doubles and returns
- EQUILATRAL / ISOCELES / SCALENE based on sides.
- INVALID TRIANGLE if the given triangle does not satify properties of a triangle
- Shape Not Supported if size of sides array > 3.
Class Hierarchy - SHAPE (Interface) ------------> POLYGON ( Abstract class ) -----------> TRIANGLE ( Concrete Class)
If needed the solution can be easily extended to other shapes by:
-
Implementing the shape interface for shapes other than a polygon Eg: circle , ellipse etc.
-
Extending the Polygon Abstract class for any other n-sided polygon Eg: square , hexagon etc.
- Certain common functions have been included in polygon abstract class Eg : getNumberOfSides , isEquilateral etc. More polygon functions like isCyclic , isRectilinear can be added if required.
-
ShapeFactory can be modified to support other shapes.
-
PolygonFactory can be modified to support other polygons.
For the sake of keeping it simple , the following concepts have been considered out of scope.
- Rest API authentication
- Degenerate Triangles
Application includes jaCoCo dependency. After running mvm clean install , test coverage reports can be seen using /target/site/jacoco/index.html. Also including a screenshot of local test coverage results.