vinitapenmatsa / Triangle-Challenge

Rest API to determine the type of triangle.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Triangle Challenge

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

Instructions

  1. Git clone the repository.
  2. mvn clean install - to generate target resources.
  3. 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.
  4. 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 )
  5. Test API Results.
  6. Included Jacoco dependency for test coverage reports.
  7. Also Included a Bash script to test REST end points, if needed to run as a bash script. ( change port number accordigly )

Implementation Details

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.

  1. Rest API authentication
  2. Degenerate Triangles

Test Results

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.

image

About

Rest API to determine the type of triangle.


Languages

Language:Java 93.6%Language:Shell 6.4%