Skip to content

Commit ace5ce7

Browse files
Merge pull request LaunchCodeEducation#12 from LaunchCodeEducation/unit-testing
Adding starter code files for Unit Testing chapter
2 parents 67f2c53 + 4ee1b34 commit ace5ce7

File tree

15 files changed

+166
-0
lines changed

15 files changed

+166
-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": "palindrome.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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function reverse(str) {
2+
return str.split('').reverse().join('');
3+
}
4+
5+
function isPalindrome(str) {
6+
return reverse(str) === str;
7+
}
8+
9+
module.exports = isPalindrome;
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)