generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOUTH AFRICA CPT-ITP | LUKE MANYAMAZI | MODULE STRUCTURING AND TESTING | WEEK 3 #212
Open
Luke-Manyamazi
wants to merge
15
commits into
CodeYourFuture:main
Choose a base branch
from
Luke-Manyamazi:feature/sprint3-exercises
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0c3900e
added function code for getting angle type
Luke-Manyamazi e19337e
added the code function to get card value
Luke-Manyamazi 8b5817c
added assertion tests
Luke-Manyamazi 7c896c5
added the code to check if given fraction is a proper fraction
Luke-Manyamazi 5df0dc8
added code function to validate triangle
Luke-Manyamazi 79adfd5
added vode to shift characters
Luke-Manyamazi 2a48bd0
created a new js file and added the code to check credit card number
Luke-Manyamazi ee1141e
added the function code to count a character in a given string
Luke-Manyamazi bd07f40
added a case-sensitive test
Luke-Manyamazi f44ab9c
added code fro checking if a number is prime
Luke-Manyamazi 9f71b35
added a test for char "e"
Luke-Manyamazi 6dab22f
added code to validate a password
Luke-Manyamazi 19bea18
added code for the repeat function
Luke-Manyamazi a578fc7
created a get angle type test file
Luke-Manyamazi 9ae910e
added assertions to my functions
Luke-Manyamazi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const getAngleType = require("./get-angle-type"); // Import the function | ||
|
||
describe("getAngleType function", () => { | ||
// Test for a right angle | ||
test('should return "Right angle" for 90 degrees', () => { | ||
expect(getAngleType(90)).toBe("Right angle"); | ||
}); | ||
|
||
// Test for acute angles (between 0 and 90) | ||
test('should return "Acute angle" for angles between 0 and 90', () => { | ||
expect(getAngleType(45)).toBe("Acute angle"); | ||
expect(getAngleType(1)).toBe("Acute angle"); | ||
}); | ||
|
||
// Test for obtuse angles (between 90 and 180) | ||
test('should return "Obtuse angle" for angles between 90 and 180', () => { | ||
expect(getAngleType(120)).toBe("Obtuse angle"); | ||
expect(getAngleType(179)).toBe("Obtuse angle"); | ||
}); | ||
|
||
// Test for a straight line | ||
test('should return "Straight line" for 180 degrees', () => { | ||
expect(getAngleType(180)).toBe("Straight line"); | ||
}); | ||
|
||
// Test for reflex angles (between 180 and 360) | ||
test('should return "Reflex angle" for angles between 180 and 360', () => { | ||
expect(getAngleType(270)).toBe("Reflex angle"); | ||
expect(getAngleType(200)).toBe("Reflex angle"); | ||
}); | ||
|
||
// Test for angles outside the valid range (0-360 degrees) | ||
test('should return "Invalid angle" for angles less than 0 or greater than 360', () => { | ||
expect(getAngleType(-10)).toBe("Invalid angle"); | ||
expect(getAngleType(400)).toBe("Invalid angle"); | ||
}); | ||
|
||
// Test for angle of 0 degrees (should be invalid) | ||
test('should return "Invalid angle" for 0 degrees', () => { | ||
expect(getAngleType(0)).toBe("Invalid angle"); | ||
}); | ||
|
||
// Test for angle of 360 degrees (should be invalid as well) | ||
test('should return "Invalid angle" for 360 degrees', () => { | ||
expect(getAngleType(360)).toBe("Invalid angle"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "my-project", | ||
"version": "1.0.0", | ||
"description": "A project that uses Jest for testing", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"jest": "^28.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
// Given a positive integer num, | ||
// When the isPrime function is called with num as input, | ||
// Then it should check if the num is prime | ||
|
||
function isPrime(num) { | ||
if (num < 2) { | ||
return `${num} is not a prime number`; | ||
} | ||
|
||
for (let i = 2; i * i <= num; i++) { | ||
if (num % i === 0) { | ||
return `${num} is not a prime number`; | ||
} | ||
} | ||
|
||
return `${num} is a prime number`; | ||
} | ||
|
||
console.assert( | ||
isPrime(1) === "1 is not a prime number", | ||
"Test failed: 1 should not be a prime number" | ||
); | ||
console.assert( | ||
isPrime(2) === "2 is a prime number", | ||
"Test failed: 2 should be a prime number" | ||
); | ||
console.assert( | ||
isPrime(3) === "3 is a prime number", | ||
"Test failed: 3 should be a prime number" | ||
); | ||
console.assert( | ||
isPrime(4) === "4 is not a prime number", | ||
"Test failed: 4 should not be a prime number" | ||
); | ||
console.assert( | ||
isPrime(17) === "17 is a prime number", | ||
"Test failed: 17 should be a prime number" | ||
); | ||
console.assert( | ||
isPrime(18) === "18 is not a prime number", | ||
"Test failed: 18 should not be a prime number" | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are switching or 'looping' through the possible values of which variable? (Hint - not of true, though I see your idea, you used true inside of switch() so that you always go into this switch construction. But this is not the usual way to use switch).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave it a second though, I think your approach is valid, though my first though for solving this task would be if-else conditions.