Skip to content

tareksamni/primes

Repository files navigation

Primes table generator

CircleCI Maintainability Test Coverage

This is a ruby implementation of Coding Challenge which could be found here. The code in this repo is mainly divided into small/simple classes and each class own its responsibilities, errors, constants, state and behaviour as follows:

  • Primes::Generator is responsible for generating N primes.

  • Calculators::Multiplication is responsible for calculating a 2D array (matrix) of multiplications of a given set of primes. It's easy to integrate other calculators into the system and switch between them.

  • Formatters::CLI is responsible for printing any given 2D array as a table to the STDOUT. It's easy to integrate other formatter into the system and switch between them.

For ex. you can code a json formatter that saves a json format of the table instead of printing it to the STDOUT.

This project is following TDD so specs could be found here.

Example run

EXAMPLE

Setup & Run

This project is using:

  • ruby 2.5.1
  • bundler gem to install all required gems that are listed in Gemfile.
  • rspec gem as the tests framework. Config can be found in .rspec.
  • rubocop gem as a main coding style guide. Config can be found in .rubocop.yml.
  • Docker to run the application without any dependencies using docker engine.
  • Codeclimate is used in this project to provide some transparency about the code quality and test coverage.

Using Docker (Build from source)

Install Docker Engine on your machine to be able to follow these steps.

run docker --version to make sure that docker is installed and running successfully. You should get a message like Docker version 18.06.1-ce, build e68fc7a. Now you follow these steps:

  • Build docker image from source
docker build . -t primes:$(git rev-parse HEAD)
  • Run the application on a docker container
docker run primes:$(git rev-parse HEAD) # default 10
#or
docker run primes:$(git rev-parse HEAD) ./run 15
  • Run tests on a docker container
docker run primes:$(git rev-parse HEAD) rspec

Using Docker (Pull from docker hub)

Install Docker Engine on your machine to be able to follow these steps.

run docker --version to make sure that docker is installed and running successfully. You should get a message like Docker version 18.06.1-ce, build e68fc7a. Now you follow these steps:

  • Run the application on a docker container
# Make sure that the tag is already exisiting on:
# https://hub.docker.com/r/tareksamni/primes/tags/
docker run tareksamni/primes:$(git rev-parse HEAD) # default 10
# or
docker run tareksamni/primes:$(git rev-parse HEAD) ./run 15
  • Run tests on a docker container
docker run tareksamni/primes:$(git rev-parse HEAD) rspec

Without Docker

You need to install the dependencies first, follow these steps to install all required dependencies using RVM:

  • Install RVM
curl -sSL https://get.rvm.io | bash -s stable
  • Install/Use ruby 2.5.1 and create a gemset for this project
rvm use ruby-2.5.1@primes --create
  • Install bundler gem
gem install bundler
  • Install gems listed in Gemfile
bundle install
  • Run application
./run # default 10
# or
./run 15
  • Run tests
rspec

About

A ruby coding/Interview challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published