In this package
there is a file Examen opdracht
, in which you can enter a temperature and it's converted into 7-segment values. The maximum number of digits
that can be displayed is 7 digits
.
In deze package kun je de grote van de digits kiezen
of om ook al dan niet een kader rond de digits
te plaatsen.
The values that can be used are for numbers 0
too 9
and Symbols C
, °
, .
and spaces
.
The entering of the values is done in main.ts
The sizes that can be used are for normal = 1
and for 2x biger = 2
.
The entering of the Size is done in main.ts
To choose if Frame is used or not can be done by using Frame = 'on'
or Frame = 'off'
.
The entering of the Frame is done in main.ts
To be able to use this package we first need to do the following installations.
First we need to install Typescript. For npm
Users:
npm install typescript --save
het installeren van deze package:
npm install examenopdracht-jonasvandycke
Run the following commands to setup ESLint in your TypeScript project.
npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
Create an .eslintrc
file.
touch .eslintrc
In it, use the following starter config.
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"no-console": 1
}
}
Create an .eslintignore
in order to prevent ESLint from linting stuff we don't want it to.
touch .eslintignore
Then add the things we want to ignore. In the following code sample, we're ignoring the dist/
folder that contains the compiled TypeScript code. If you're compiling your TypeScript code to a different folder, make sure to use that instead of dist
. You should be able to find this in your .tsconfig
.
node_modules
dist
In your project package.json, lets add a lint script in order to lint all TypeScript code.
{
"scripts": {
...
"lint": "eslint . --ext .ts",
}
}
Ready to try it out? Let's run the following command.
npm run lint
For information about ESLint see LINK
Pull in this file to enable Jekyll.
git pull git@github.com:vives-software-engineering-2020/examenopdracht-JonasVanDycke.git bugfix/docs-jekyll
Follow the following steps for fixing the Automation of GitHub Pages.
Step 1) Add a new devdependency called touch
in your package.json
file using the following command:
npm install touch -D
This will install a package that enables us to use the touch command from within JavaScript (and not depend on the operating system).
Step 2) Update your npm run docs
command in the package.json
:
Add the following script:
"nojekyll": "nodetouch docs/.nojekyll",
Update the docs
script to:
"docs": "typedoc && npm run nojekyll",
This will make sure the .nojekyll
file is created after creating the docs.
Install dependencies
npm install --save-dev @types/jest jest ts-jest
In your package.json
add the following scripts to make it easy to use Jest:
"scripts": {
"test": "jest",
"test:watch": "jest --coverage --watchAll",
"coverage": "jest --coverage",
},
This will add a script to run the tests, and a script to check the test coverage.
Create jest.config.js
in the root of your project (where your package.json
file lives)
module.exports = {
transform: {'^.+\\.ts?$': 'ts-jest'},
testEnvironment: 'node',
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
}
This configuration file will add support for TypeScript to Jest using ts-jest.
Next we need to ignore tests when building our project using the TypeScript Compiler.
You can do this in your .tsconfig.json
file. Your configuration should look something like this:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es2015"],
"strict": true,
"declaration": true,
"outDir": "dist",
"sourceMap": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
Note the exclude
settings will ignore tests files in the compiled result.
For more information on creating and running Unit Testing
, see Examples
.
Once the package is installed, you can then use ts-node .\main.ts
to run/test the code.
In the main
you choose the Values
, Size
and Frame
.
If no unit of measurement is given, it will default to celsius
.
In the main
you can put in :
-
temp
(-25.9°C) -
size
(1) -
frame
(off)
console.log(lcd.LCD_Display(temp, size, frame));
Output:
_ _ _ _ _
_ _||_ |_||_||
|_ _| / _| |_
In the main
you can put in :
-
temp
(-25.9°C) -
size
(1) -
frame
(on)
console.log(lcd.LCD_Display(temp, size, frame));
Output:
___________________________
| _ _ _ _ _ |
| _ _||_ |_||_|| |
| |_ _| / _| |_ |
|___________________________|
In the main
you can put in :
-
temp
(-25.9°C) -
size
(2) -
frame
(off)
console.log(lcd.LCD_Display(temp, size, frame));
Output:
___ ___ ___ ___ ___
| | | | | | |
| | | | | | |
___ ___| |___ |___| |___| |
| | | |
| | / | |
|___ ___| / ___| |___
In the main
you can put in :
-
temp
(-25.9°C) -
size
(2) -
frame
(on)
console.log(lcd.LCD_Display(temp, size, frame));
Output:
_______________________________________________
| ___ ___ ___ ___ ___ |
| | | | | | | | |
| | | | | | | | |
| ___ ___| |___ |___| |___| | |
| | | | | |
| | | / | | |
| |___ ___| / ___| |___ |
|_______________________________________________|
**! Importent !** Remember that only the first 7 digits wil return om the terminal.
Consider that we have a class defined in scr/sum.ts
containing the code:
export default function sum(a: number, b: number): number {
return a + b;
}
Then you can create a test that will verify the functionality in a file called tests/sum.test.ts
:
import sum from '../src/sum'
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
The most important parts of this file are:
- A
test()
method containing a description of the test and a function to execute the test. - An
expect()
method that will actually run the code to be tested - A
toBe()
method that will check if the result equals a specific value. If this is true, the test succeeds. If this is false, the test will fail.
To runn the tests use:
npm run test
or you could use:
npm test
This will generate a report that will look like:
PASS ./sum.test.js
✓ adds 1 + 2 to equal 3 (5ms)
Tests can be ran automatically, showing results directly after you save your changes. This results in a very fast feedback loop. Just use the following command:
npm run test:watch
This will run the tests and will keep watching your files for any changes. When a file changes, the test will run again automatically.
For information about the Unit Testing
see:
For information about the Unit Testing
and Jest
see:
For information about the License see LICENSE
Jonas VD - student at University College Vives, Belgium