Skip to content

Commit 0912c89

Browse files
Adding starter code files for unit testing chapter
1 parent 52b5d60 commit 0912c89

File tree

16 files changed

+185
-0
lines changed

16 files changed

+185
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function hello(name) {
2+
if (name === undefined)
3+
name = "World";
4+
5+
return "Hello, " + name + "!";
6+
}
7+
8+
module.exports = hello;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "unit-testing",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "hello.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"readline-sync": "^1.4.10"
13+
},
14+
"devDependencies": {
15+
"jest": "^29.6.4"
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const hello = require('../hello.js');
2+
3+
describe("hello world test", function(){
4+
5+
test("should return a custom message when name is specified", function(){
6+
expect(hello("Jest")).toBe("Hello, Jest!");
7+
});
8+
9+
it("should return a general greeting when name is not specified", function(){
10+
expect(hello()).toBe("Hello, World!");
11+
});
12+
13+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "unit-testing",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "reverse.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"readline-sync": "^1.4.10"
13+
},
14+
"devDependencies": {
15+
"jest": "^29.6.4"
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function reverse(str) {
2+
let lettersArray = str.split('');
3+
let reversedLettersArray = lettersArray.reverse();
4+
return reversedLettersArray.join('');
5+
}
6+
7+
module.exports = reverse;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const reverse = require('../reverse.js');
2+
3+
describe("reverse", function(){
4+
5+
test("should not change a single character", function(){
6+
expect(reverse("a")).toBe("a");
7+
});
8+
9+
test("should handle the empty string", function(){
10+
expect(reverse("")).toBe("");
11+
});
12+
13+
test("should reverse a short string", function(){
14+
expect(reverse("dog")).toBe("god");
15+
});
16+
17+
test("should reverse a long string", function(){
18+
expect(reverse("LaunchCode")).toBe("edoChcnuaL");
19+
});
20+
21+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "unit-testing",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "processor.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"readline-sync": "^1.4.10"
13+
},
14+
"devDependencies": {
15+
"jest": "^29.6.4"
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe("transmission processor", function() {
2+
3+
// TODO: put tests here
4+
5+
});

unit-testing/exercises/RPS.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function whoWon(player1,player2){
2+
3+
if (player1 === player2){
4+
return 'TIE!';
5+
}
6+
7+
if (player1 === 'rock' && player2 === 'paper'){
8+
return 'Player 2 wins!';
9+
}
10+
11+
if (player1 === 'paper' && player2 === 'scissors'){
12+
return 'Player 2 wins!';
13+
}
14+
15+
if (player1 === 'scissors' && player2 === 'rock '){
16+
return 'Player 2 wins!';
17+
}
18+
19+
return 'Player 1 wins!';
20+
}

unit-testing/exercises/checkFive.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function checkFive(num){
2+
let result = '';
3+
if (num < 5){
4+
result = num + " is less than 5.";
5+
} else if (num === 5){
6+
result = num + " is equal to 5.";
7+
} else {
8+
result = num + " is greater than 5.";
9+
}
10+
return result;
11+
}

unit-testing/exercises/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "unit-testing",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "checkFive.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"readline-sync": "^1.4.10"
13+
},
14+
"devDependencies": {
15+
"jest": "^29.6.4"
16+
}
17+
}

unit-testing/exercises/tests/RPS.test.js

Whitespace-only changes.

unit-testing/exercises/tests/checkFive.test.js

Whitespace-only changes.

unit-testing/studio/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
let launchcode = {
3+
4+
}
5+
6+
module.exports = launchcode;
7+

unit-testing/studio/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "unit-testing",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"readline-sync": "^1.4.10"
13+
},
14+
"devDependencies": {
15+
"jest": "^29.6.4"
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// launchcode.test.js code:
2+
const launchcode = require('../index.js');
3+
4+
describe("Testing launchcode", function(){
5+
6+
// Write your unit tests here!
7+
8+
});

0 commit comments

Comments
 (0)