Giter Site home page Giter Site logo

backendtest's Introduction

This is the Rust implementation

Please checkout the typescript branch instead.

Backend test

Time it took too complete: 1h 27min (between first commit Initial commit 19394231 and Add test for run() 3c94c958 + like 5min to add tests for Direction)

How to run

Use bash/zsh/fish or git bash and cd into the project and run:

cat testinput.txt | cargo run

NOTE: testinput.txt can be edited to test different commands and boards.

To run the test, just run:

cargo test

Assumptions made

The input format is:

width,height,x,y
cmd1,cmd2,cmd3,...,cmdn

cmd can be one of 0, 1, 2, 3 or 4.

If the input is malformatted, the program will panic.

If width, height, x, y isn't a number or if a command is not one of the valid ones, the program will panic.

If the object is out-of-bounds at any point in the execution, the program will halt and not process the remaining commands.

Things to keep in mind

Handle different shapes than a rectangle

This could easily be added by changing Board to a trait and pass a Box<dyn Board> around instead of Board. Then implement, for example Rectagle by implementing the Board trait for Rectagle and write a custom is_legal_position.

Add more commands like rotating the table instead of the object

This could be done by just adding more variants to the Command trait then implement them in run().

Change the binary form of the protocol to JSON

Update the parse_header() and parse_body() functions and parse it like json via serde_json or something similar.

The output would have to be changed in main() as well.

Test coverage:

codecov.io Code Coverage

The logic in main is so simple and there is no resonable way to extract the functionallity that main provide to a more testable function.

backendtest's People

Contributors

mkanilsson avatar

Watchers

 avatar

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.