basic-calc-task1
v1.0.3
Published
Day 1 Training at syscloiyd
Downloads
3
Readme
Intern Assignment for Quality Control Mechanisms
This project is an assignment for interns to learn the best practices of writing codes by building a simple Calculator in TypeScript
Pre-Requisites
- Node
- Npm
- CLI Tool
Installation
Make sure you have node/npm installed and it's path is added Use the commands below to set up the project
Commands
Migrate to the root directory using command line.
- Install the packages and dependencies using npm
npm install
- Build the typescript files (Compile typescript to js)
npm run build
- Now, generate documentations to know about the functionalities
npm run doc
- You can use the following command to generate unit testing and coverage reports
npm run test
Project Hierarchy
coverage
This directory is auto-generated when "npm run test" is executed. It contains all the coverage reports
of unit test cases.
dist
This directory is auto-generated when "npm run build" is executed. It contains all the js compiled files from typescript
documentation
This directory is auto-genearted when "npm run doc" is executed. It contains the documentations of the usage of calulator functions
node_modules
This directory is auto-generated when "npm install" is executed. It contains the packages and dependencies over which the project is built
src
Here all the source codes are kept which are written in typescipt. Any modifications in code is done here.
Note: Remember to compile everytime any changes are done within this directory
test
This directory contains all the test suites written in js using jest packages. The unit tests are done on the basis of these files only
Documentations
Once you follow the above steps, a new folder named "documentation" will be generated in root folder. Go to documentation->index.html to know about the basic uses of calculator
Usage
This project has 4 functions of a basic calculator:
1. add(a:number, b:number):number
This functions takes two parameters and returns their sum
```js
let sum = add(43, 23)
console.log(sum) //prints 66
```
2. subtract(a:number, b:number):number
This function takes two parameters and returns their subtraction result
```js
let diff = subtract(11, 2)
console.log(diff) //prints 9
```
3. multiply(a:number, b:number):number
This function takes two parameters and returns product
```js
let product = multiply(23, 4)
console.log(product) //prints 92
```
4. divide(a:number, b:number):number
This function take two parameters and returns the quotient when a is divided by b
Note: if b = 0 : Throws "Cannot divide by zero exeception"
```js
let quo = divide(10/2);
console.log(quo) //prints 5
let errQuo = divide(2/0) // throws "Cannot divide by zero" exception
```
Author
Shivam Singh