Giter Club home page Giter Club logo

js-tdd-exercises's Introduction

README

Before you start

First step is to fork this repo to your account, then clone it locally.

After you do that, add a remote to point to CodeYourFuture repo, that will allow you to update you forked copy when we update the repo with more exercises.

This is the command to run git remote add cyf [email protected]:CodeYourFuture/js-tdd-exercises.git

How to run the tests

To run the tests from the console, run the command: npm test To keep the tests running (auto updating when you save files), run the command: npm test -- --watch then press a to run all the tests and keep watching the files for changes. To quit the tests, type q.

To run a specifc test, do: npm test -- filname for example npm test -- find-alive (that will run only the files that matches find-alive, i.e. findAlive.test.js)

01-Exercises

The exercises are divided into two groups:

  1. A group where we provide the tests, we expect you to write a function that passes those tests. (find-*.js)
  2. A group where we provide an implementation where we provide a function and we want you to write tests for the function (and potentially change the function if you find a bug)

Further instructions will be found as comments in the individual files.

When writing tests, always think about Edge cases - unexpected input for example (what if we pass null or undefined as an argument, or pass a string instead of a number). Always write tests for these edge cases. (Read about Defensive Programming in Code Complete for more information)

You unit tests descriptions should be meaningful and easy to read. This is like documentation for what the function does.

DO NOT Change the tests (you can add more tests though) - let us know if you think one of the tests is wrong.

Your goal is to turn Red to Green

Do Not hardcode answers!

Roman calculator

Using TDD, write a function that converts an Arabic number (the numbers used here) to Roman Numerals.

Always write tests first

Part One: Old Roman Numerals

Arabic Number Roman Numeral
1 I
5 V
10 X
50 L
100 C
500 D
1000 M

Table 1. Arabic number and their old Roman numeral equivalents.

In the early days of Roman numerals, the Romans built their numerals from the individual characters in Table 1 (e.g., I, V, X, etc.) written largest value to smallest from left to right. To determine the value of any numeral, they used straight addition. I is equivalent to 1. II is equivalent to 1 + 1, or 2. VIIII is equivalent to 5 + 1 + 1 + 1 + 1, or 9.

More examples

Arabic Number Roman Numeral
1 I
3 III
7 VII
15 XV
18 XVIII
22 XXII

We are going to begin writing a function convertToOldRoman. When passed an integer between 1 and 3000, this function will return a string containing the proper old Roman Numeral. In other words, convertToOldRoman(4) should return the string 'IIII'. Don't worry about checking whether or not the number passed to the method is between 1 and 3000.

Hint: It might be useful to use the integer division / and modulus % methods.

Part Two: Modern Roman Numerals

Arabic Number Roman Numeral
4 IV
9 IX
14 XIV
44 XLIV
99 XCIX
400 CD
944 CMXLIV

Table 2. Modern Roman numeral examples.

Eventually, the Romans changed systems. Now, putting a smaller numeral before a larger one meant you had to subtract the smaller one. So, instead of 4 being represented by 1 + 1 + 1 + 1, it was now 5 - 1, or IV. 4 was not the only value affected (see Table 2 for more examples).

We're going to write a second method so that will return modern Roman Numerals. We'll most likely use some similar logic as in the first function.

convertToOldRoman(4)
 => "IIII"
 
convertToNewRoman(4)
 => "IV"

JEST

Refer to our syllabus (JS-Core lesson 3) to refresh your knowledge on the testing framework JEST - also refer to its documentation: https://facebook.github.io/jest/docs/api.html

js-tdd-exercises's People

Contributors

kabaros 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.