/queue-shapeless-excercise

just a play with some existing default implementations

Primary LanguageScala

Scotiabank Scala Interview Questions

(c) Scotiabank 2017

A selection of interview problems for developer candidates.

There are 2 exercises to complete.

  • Exercise #1 is a data structure question in src/main/scala/test/queue.scala
  • Exercise #2 is a question on automatic typeclass derivation using shapeless in src/main/scala/test/eq.scala

You should complete both questions.

Implementation considerations

  • Both solutions are thoroughly tested:
    • scoverage report result is:
        [info] Statement coverage.: 100.00%
        [info] Branch coverage....: 100.00%
        [info] Coverage reports completed
        [info] 100% Coverage !
      
    • FifoQueue is tested here, with the test output:
      [info] FifoQueueTest:
      [info] Time complexity tests
      [info] - isEmpty should have Q(1) in milliseconds
      [info] - insert should have Q(1) in milliseconds
      [info] - remove should have amortized Q(1) = less than 2 milliseconds
      [info] - insert should not be constant in nanoseconds
      [info] Functional tests
      [info]   isEmpty should
      [info]   - return true for empty Queue
      [info]   - return false for non empty Queue
      [info]   insert should
      [info]   - return a new queue with the element prepended
      [info]   - not mutate the original queue
      [info]   remove should
      [info]   - return a new queue with the first inserted element removed
      [info]   - return removed element
      [info]   - not mutate the original queue
      [info]   toString should
      [info]   - return all values for a non empty queue
      [info]   - return empty string for an empty queue
      
    • Type class derivation is tested here, with the test output:
      [info] EqTest:
      [info] Equivalence test
      [info]   product should
      [info]   - be equal to itself
      [info]   - be equal to another instance with same type and values
      [info]   - be different by values
      [info]   coproduct should
      [info]   - be equal to itself
      [info]   - be equal to another instance with same type and values
      [info]   - be different by values
      [info]   custom type should
      [info]   - be equal to itself
      [info]   - be equal to another instance with same type and values
      [info]   - be different by values
      [info]   - be different by types
      
  • Code is auto formatted using scalariform;
  • Coding style is enforced with scalastyle and wartremover;