Coder Social home page Coder Social logo

latch2112 / anagramchallenge Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 768 KB

anagrams server coding challenge

License: GNU General Public License v3.0

Dockerfile 7.06% Java 92.94%
java http-server docker anagrams docker-compose postman-collection newman

anagramchallenge's Introduction

anagramChallenge

Anagram Coding Challenge

Definitions​:

Anagram: a word, phrase, or name formed by rearranging the letters of another, such as cinema,​ formed from ​iceman​.

Problem​:

Please complete any or all of these problems in a public GitHub repository, and provide a link to the repository. Any documentation on running the solution will be appreciated.

  1. Create a function which takes two ​String​ arguments, and returns a ​Boolean corresponding to whether or not the two ​String​ arguments are ​anagrams​ of each other.

  2. Provide some unit tests for the function implemented in step 1.

  3. Create a HTTP server which implements the following:

    a) Endpoint ​/anagrams/{string1}/{string2}

    • Returns a ​400​ - ​Bad Request​ if either s​tring1​ or ​string2​ are not valid

    • Returns a ​200 - OK​ with the following ​JSON​ payload: { ​areAnagrams​: true|false } where ​areAnagrams​ is true or false, depending on whether ​string1​ and ​string2 are ​anagrams​ of each other.

    b) Endpoint ​/anagrams/{string1}

    • Returns a ​400 - Bad Request​ if s​ tring1​ is not valid

    • Returns a ​200 - OK​ with the following ​JSON p​ayload: { anagrams: [ ... ] } where anagrams is an array of all possible anagrams of ​string1

  4. Provide some unit/integration tests for the server implemented in step 3.

  5. Containerize your project in a Docker container and include the Dockerfile and docker-compose files with you project

Solution:

  • Java-Spark; a tiny framework to make for a smaller container size;

  • Multi-stage Docker Build to reduce final container size

  • Junit 5 unit tests

  • Integration tests using Postman Collection (with JavaScript's Chai framework) and newman

  • For the problem 3b, I've decided to used one of the english dictionary available in all distribution on linux. For the simplicity of the solution, I have provided the one from the Mac OS X distribution. From the README:

WEB ---- (introduction provided by jaw@riacs) -------------------------

Welcome to web2 (Webster's Second International) all 234,936 words worth.
The 1934 copyright has lapsed, according to the supplier.

Only same length anagrams is returned for simplicity.

Build and run the solution with docker:

docker-compose up --build anagramServer

Test:

Integration tests:

docker run --network host -t postman/newman run "https://www.getpostman.com/collections/7f56d87ab98e182e9f9a"

Manual:

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost/anagrams/cinema/iceman

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.