Skip to content
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

CYF-ITP - South Africa | Simphiwe Mabuya | Structuring-and-Testing-Data | Sprint-3 #215

Open
wants to merge 110 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 99 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
7c6d5f1
I commented out the text to solve the error
Simphiwe-Mabuya Nov 4, 2024
0528968
Created a getAngleType function
Simphiwe-Mabuya Nov 16, 2024
5ce8556
Created a getCardValue function and assertions to test my function
Simphiwe-Mabuya Nov 16, 2024
47d669d
Edited my code so it can return the value 10
Simphiwe-Mabuya Nov 19, 2024
979c099
Implemented a function named isProperFraction()
Simphiwe-Mabuya Nov 19, 2024
372d56b
Implemented an isValidTriangle() function
Simphiwe-Mabuya Nov 19, 2024
e3732f1
Revert "I commented out the text to solve the error"
Simphiwe-Mabuya Nov 20, 2024
6fb54c4
Passed a different value to my getCardValue() function as a test
Simphiwe-Mabuya Nov 21, 2024
e3cb721
Created get-angle-type test
Simphiwe-Mabuya Nov 25, 2024
532476e
Created a JSON file Installed jest
Simphiwe-Mabuya Nov 25, 2024
621182e
Created an export in get-angle-type.js
Simphiwe-Mabuya Nov 25, 2024
e0ad3e5
Created a rotate-char function
Simphiwe-Mabuya Nov 25, 2024
b47fbce
Edited function condition
Simphiwe-Mabuya Nov 25, 2024
16245b5
Edited my get-angle-test file
Simphiwe-Mabuya Nov 25, 2024
a96957d
Deleted file and folder
Simphiwe-Mabuya Nov 25, 2024
c2f25db
Deleted files and folder get-angle-type folder
Simphiwe-Mabuya Nov 25, 2024
cfe0f8a
Installed jest / node modules
Simphiwe-Mabuya Nov 25, 2024
fdaf12c
Edited description text on package.json
Simphiwe-Mabuya Nov 25, 2024
f148ac7
Created a get-angle-type test.js file
Simphiwe-Mabuya Nov 25, 2024
6b0cebf
Edited the file and added tests
Simphiwe-Mabuya Nov 25, 2024
c307773
Updated get-angle-type code
Simphiwe-Mabuya Nov 25, 2024
5d98686
Updated get-angle-type test file
Simphiwe-Mabuya Nov 25, 2024
1bc80f3
Edited package.json file
Simphiwe-Mabuya Nov 25, 2024
23439a6
Updated the package.json file
Simphiwe-Mabuya Nov 25, 2024
422e58e
Edited the file again
Simphiwe-Mabuya Nov 26, 2024
f8b9c01
Updated function
Simphiwe-Mabuya Nov 26, 2024
25826d8
Updated test file
Simphiwe-Mabuya Nov 26, 2024
f3e7455
Update json file
Simphiwe-Mabuya Nov 26, 2024
683091e
Edited file by adding js at the end on get-angle-type
Simphiwe-Mabuya Nov 26, 2024
6d6d37e
Edited the test file again
Simphiwe-Mabuya Nov 26, 2024
3909973
Deleted get-angle-type test, deleted node modules and the json files …
Simphiwe-Mabuya Nov 26, 2024
4516ba2
Re-installed jest again
Simphiwe-Mabuya Nov 26, 2024
1ca1ee2
Created a get-angle-test file and got the test to pass
Simphiwe-Mabuya Nov 26, 2024
2915c06
Added an export line for my getCardValue function
Simphiwe-Mabuya Nov 26, 2024
abb24c9
Edited getValueCard function to remove the last character
Simphiwe-Mabuya Nov 26, 2024
9af6ad9
Created a get-card-value test file and got it to pass the test
Simphiwe-Mabuya Nov 26, 2024
54917c6
Created an export line for isProperFraction
Simphiwe-Mabuya Nov 26, 2024
ff36a57
Created an is-proper-fraction test file, imported the isProperFractio…
Simphiwe-Mabuya Nov 26, 2024
73fd961
Updated and an export line for isValidTriangle
Simphiwe-Mabuya Nov 26, 2024
7b7bfd8
Created an is-valid-triangle test file and got is to pass the jest test
Simphiwe-Mabuya Nov 26, 2024
d0cc829
Deleted rotate-char.js then renamed it
Simphiwe-Mabuya Nov 27, 2024
5dc6147
Renamed rotate-char to rotate-characters.js
Simphiwe-Mabuya Nov 27, 2024
205fa03
Also renamed the rotate-character test file
Simphiwe-Mabuya Nov 27, 2024
ca5bb89
Created a creditCardValidator function and checked if it works
Simphiwe-Mabuya Nov 27, 2024
22b53a0
Added a module exports line for my creditCardValidator function
Simphiwe-Mabuya Nov 27, 2024
a4f4e0f
Created a credit-card-validator test file
Simphiwe-Mabuya Nov 27, 2024
522a45a
Created a few tests for to check my function works well
Simphiwe-Mabuya Nov 27, 2024
d8a5a24
Passed an uneven number at the end to check if my function works ok
Simphiwe-Mabuya Nov 27, 2024
7500639
Deleted the file
Simphiwe-Mabuya Nov 27, 2024
c3602a5
Deleted the file
Simphiwe-Mabuya Nov 27, 2024
76986c6
Created a new file and renamed it
Simphiwe-Mabuya Nov 27, 2024
e6c41c7
Renamed the file
Simphiwe-Mabuya Nov 27, 2024
9b06ff8
Tested the if the function still works
Simphiwe-Mabuya Nov 27, 2024
5a5034a
Fixed my require line for my test to work
Simphiwe-Mabuya Nov 27, 2024
d1ea95f
Edited /fixed my export line
Simphiwe-Mabuya Nov 27, 2024
14cfc68
Created a countChar test file
Simphiwe-Mabuya Nov 27, 2024
6f51e96
Created a working countChar function
Simphiwe-Mabuya Nov 27, 2024
9bf2414
Deleted count.test and renamed it count-char so to identify it for te…
Simphiwe-Mabuya Nov 27, 2024
aab17eb
Created and updated getOrdinalNumber function
Simphiwe-Mabuya Nov 27, 2024
3d06955
Created get-ordinal-number test file and added more test cases
Simphiwe-Mabuya Nov 27, 2024
ecd5495
Created a isPrime file and a code to check for a prime number
Simphiwe-Mabuya Nov 29, 2024
5d467a5
Created an is-prime test file and all the tests passed
Simphiwe-Mabuya Nov 29, 2024
3cc080b
Edited / fixed my isPrime file because the test was failing
Simphiwe-Mabuya Nov 29, 2024
3eabd5f
Created a password validator function file and got to work properly
Simphiwe-Mabuya Nov 29, 2024
8b1b59c
Created a password validator function and got to work properly
Simphiwe-Mabuya Nov 29, 2024
0e4fbdd
Edited my function so it returns a boolean
Simphiwe-Mabuya Nov 29, 2024
ffbcb50
Fixed my failing test by declaring passwords because it wasn't defined
Simphiwe-Mabuya Nov 29, 2024
8c26e78
Added an export line for my function
Simphiwe-Mabuya Nov 29, 2024
f588eac
Edited my function to test different results
Simphiwe-Mabuya Dec 2, 2024
9d30d13
Created a Repeat string function file and got it to work
Simphiwe-Mabuya Dec 2, 2024
32c27fb
Created my Repeat function in my repeat.test file and deleted it
Simphiwe-Mabuya Dec 2, 2024
19784cf
Renamed my repeat.test file to srt-repeat
Simphiwe-Mabuya Dec 2, 2024
85e30b0
Added an exports line into my function and tested it if it will throw…
Simphiwe-Mabuya Dec 2, 2024
e27cfc2
Added my import/require line into my str-repeat test file
Simphiwe-Mabuya Dec 2, 2024
23bdcf1
Did my fist test case, fixed and made sure it passed
Simphiwe-Mabuya Dec 2, 2024
a3fc63f
Did second test for count of 1 and it worked
Simphiwe-Mabuya Dec 2, 2024
be389fa
Checked if count of of 1 works and it does
Simphiwe-Mabuya Dec 2, 2024
811ed1f
Fixed my function to return and empty string
Simphiwe-Mabuya Dec 2, 2024
59e491e
Fixed my test so it can pass handling count of 0
Simphiwe-Mabuya Dec 2, 2024
b5ebdf2
Fixed my function so it handle negative count
Simphiwe-Mabuya Dec 2, 2024
458b348
Edited my error message
Simphiwe-Mabuya Dec 2, 2024
bd23236
Added a test to check negative integer and it works
Simphiwe-Mabuya Dec 2, 2024
68bd517
Answered all the questions according to my understanding of what the …
Simphiwe-Mabuya Dec 2, 2024
7666abf
Refactored my test to make it cleaner / neat
Simphiwe-Mabuya Dec 3, 2024
cc24ffc
Deleted assertions, fixed function to handle numerical values and inv…
Simphiwe-Mabuya Dec 3, 2024
5c60e2d
Fixed code to handle negative denominator values
Simphiwe-Mabuya Dec 3, 2024
df4c0df
Refactored my code and made sure it checks for negative denominator v…
Simphiwe-Mabuya Dec 3, 2024
a2e8f9d
Refactored my code after looking up the De Morgan's Law
Simphiwe-Mabuya Dec 3, 2024
cbd8962
Fixed my code to check for a value with a leading 0 or a decimal point
Simphiwe-Mabuya Dec 3, 2024
86e9340
Edited my code again to handle Invalid ranks and Face cards correctly
Simphiwe-Mabuya Dec 3, 2024
7e9c514
Fixed my test to check for valid and invalid card ranks
Simphiwe-Mabuya Dec 3, 2024
8f833aa
Refactored the code so it looks clean
Simphiwe-Mabuya Dec 3, 2024
ee7550e
Refactored rotate-character test to look clean
Simphiwe-Mabuya Dec 3, 2024
5374b14
Refactored card-validator test and fixed it to check various cases
Simphiwe-Mabuya Dec 3, 2024
5e10a18
Refactored code and tested for large prime and non-prime numbers
Simphiwe-Mabuya Dec 3, 2024
ff75cad
Updated the code by editing line 2, line 6 and adding line 10 thus re…
Simphiwe-Mabuya Dec 3, 2024
de23baa
Refactored password-validator test and updated it to check for differ…
Simphiwe-Mabuya Dec 3, 2024
d543032
Refactored code so to clean
Simphiwe-Mabuya Dec 3, 2024
51dc361
Rectified my answers after researching, from ChatGpt, about what the …
Simphiwe-Mabuya Dec 3, 2024
049a414
Updated code so it can handle invalid values like 2.1 etc
Simphiwe-Mabuya Dec 4, 2024
8f51e6a
Updated my test file to check invalid cases like 10 etc
Simphiwe-Mabuya Dec 4, 2024
dc778fe
Updated my test file to check for other possible invalid cases
Simphiwe-Mabuya Dec 4, 2024
ff277ba
Added more tests to check when card number is less or greater than 16
Simphiwe-Mabuya Dec 4, 2024
ed7dee1
Updated my code to return a boolean: true or false, instead of "is pr…
Simphiwe-Mabuya Dec 4, 2024
3acefb7
Also updated my test file to return a boolean instead of "is prime" o…
Simphiwe-Mabuya Dec 4, 2024
a033d20
Updated my test file to also check for when password is only missing …
Simphiwe-Mabuya Dec 4, 2024
a3932a4
Updated my function to return false instead of "Password already used…
Simphiwe-Mabuya Dec 4, 2024
b6bdcbc
Updated test file to expect a false return instead of "Password alrea…
Simphiwe-Mabuya Dec 4, 2024
ca55423
Updated my function so it could return false instead of true if passw…
Simphiwe-Mabuya Dec 4, 2024
8aaa530
Updated my test file to check for when password is missing at least o…
Simphiwe-Mabuya Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Sprint-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
// When the function getAngleType is called with this angle,
// Then it should:

function getAngleType(degrees) {
if (degrees === 90) return "Right angle";
if (degrees < 90) return "Acute angle";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you expect getAngleType(-5) to return?

if (degrees > 90 && degrees < 180) return "Obtuse angle";
if (degrees === 180) return "Straight angle";
if (degrees > 180 && degrees < 360) return "Reflex angle";
return "Invalid angle";
}

module.exports = getAngleType;

console.log(getAngleType(359));



// Identify Right Angles:
// When the angle is exactly 90 degrees,
// Then the function should return "Right angle"
Expand Down
30 changes: 30 additions & 0 deletions Sprint-3/implement/get-angle-type.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

const getAngleType = require("./get-angle-type");


test("Checks for Right Angle for when the angle is 90 degrees", () => {
expect(getAngleType(90)).toEqual("Right angle");
});


test("Checks for Acute angle, when the angle < 90 degrees", () => {
expect(getAngleType(45)).toEqual("Acute angle");
});


test("Checks for Obtuse angle, when the angle > 90 and angle < 180 degrees", () => {
expect(getAngleType(145)).toEqual("Obtuse angle");
});


test("Checks for Straight angle, when the angle is exactly 180 degrees", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});


test("Expect 'Reflect angle' when 180 < angle < 360", () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just making a suggestion so that you can try to keep the test description concise in the future.

Copy link
Author

@Simphiwe-Mabuya Simphiwe-Mabuya Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip CJ ..I thought it was best I used it.

expect(getAngleType(192)).toEqual("Reflex angle");
});



31 changes: 31 additions & 0 deletions Sprint-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

// You will need to implement a function getCardValue

function getCardValue(cardRank){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getCardValue("10000♣") would still break your implementation. (sorry)

The card value should always have ONE suite character as the LAST character. So
getCardValue("10") should return 'Invalid card rank'.

Since there are exactly 13 valid ranks but countless possible invalid ranks,
it would be easier to consider what value constitutes a valid rank
instead of considering what values are invalid.
After you have checked all valid cases, everything else would be invalid.


if(cardRank === "10"){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can remove the suite character from cardRank first, this is a good way to guarantee the return value is correct.

return 10;
}

if(/^0\d/.test(cardRank) || /\.\d/.test(cardRank)){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can skip checking for possible invalid cases.

return "Invalid card rank";
}

cardRank = cardRank.slice(0, 2) === "10" ? "10" : cardRank.slice(0, 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should be replaced by a statement that removes the suite character from the string, and should be perform at the beginning of the function.


if(cardRank ==="A"){
return 11;
}else if(cardRank === "J" || cardRank === "K" || cardRank === "Q"){
return 10;
}

const numericalValue = parseInt(cardRank, 10);
if(numericalValue >= 2 && numericalValue <= 10){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have already checked for "10" at line 7. So the remaining values to be checked are "2", "3", ..., "9". What do these strings have in common? What condition can you add so that ranks like "2.1" would not pass the check.

return numericalValue;
}else {
return 'Invalid card rank'
}
}
module.exports = getCardValue;


//testGetCardValue();
console.log(getCardValue("2.1♣"));

// You need to write assertions for your function to check it works in different cases

// Acceptance criteria:
Expand Down
26 changes: 26 additions & 0 deletions Sprint-3/implement/get-card-value.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const getCardValue = require("./get-card-value");


test("Checks if cardRank is 'A♠' then returns 11 ", () => {
expect(getCardValue("A♠")).toEqual(11);
});

test("Checks if cardRank is 'J♦' then returns 10 ", () => {
expect(getCardValue("J♦")).toEqual(10);
});

test("Checks if cardRank is 'K♥' then returns 10 ", () => {
expect(getCardValue("K♥")).toEqual(10);
});

test("Checks if cardRank is 'Q♣' then returns 10 ", () => {
expect(getCardValue("Q♣")).toEqual(10);
});

test("Checks if cardRank is '8' then returns 8 ", () => {
expect(getCardValue("8")).toEqual(8);
});

test("Checks if cardRank is '2.1' then returns 'Invalid card rank", () => {
expect(getCardValue("2.1♣")).toEqual("Invalid card rank");
});
16 changes: 16 additions & 0 deletions Sprint-3/implement/is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
// Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j
// Written here like this: 1/2 == Numerator/Denominator

function isProperFraction(num,den){

if(den === 0){
throw new Error('Denominator must be a positive or negative number');
}
den = Math.abs(den);

return Math.abs(num) < den;

}

module.exports = isProperFraction;


console.log(isProperFraction(-4,-7))

// Acceptance criteria:

// Proper Fraction check:
Expand Down
23 changes: 23 additions & 0 deletions Sprint-3/implement/is-proper-fraction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const isProperFraction = require("./is-proper-fraction");


test("Checks if the fraction is a Proper fraction (2/3) or (-4/-7) then return true", () => {
expect(isProperFraction(1, 2)).toEqual(true);
expect(isProperFraction(-4,-7)).toEqual(true);
});

test("Checks if the fraction is a Negative fraction (-4/7) then return true", () => {
expect(isProperFraction(-4, 7)).toEqual(true);
});

test("Checks if the fraction is an Improper fraction (5/3) then return false", () => {
expect(isProperFraction(5, 3)).toEqual(false);
});

test("Checks if the Numerator === Denominator (3/3) then return false", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});

test("Throws an error when the denominator is zero", () => {
expect(() => isProperFraction(3, 0)).toThrow("Denominator must be a positive or negative number");
});
13 changes: 13 additions & 0 deletions Sprint-3/implement/is-valid-triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
// It's also true that b + c > a
// It's also true that a + c > b

function isValidTriangle(a,b,c){

if ( (a + b > c) && (a + c > b) && (b + c > a)){
return true;
}else {
return false;
}
}

module.exports = isValidTriangle;

console.log(isValidTriangle(3,2,4));

// In our function isValidTriangle which takes as parameters the lengths of three sides, we need to invalidate any triangle where the sum of any two sides is less than or equal to the length of the third side.
// and we need to validate any triangle where the sum of any two sides is greater than the length of the third side.

Expand Down
13 changes: 13 additions & 0 deletions Sprint-3/implement/is-valid-triangle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const isValidTriangle = require("./is-valid-triangle");

test("Checks for Valid Triangle where the sum is (a + b > c)", () => {
expect(isValidTriangle(3, 5, 4)).toEqual(true);
});

test("Checks for Invalid Triangle when any of the sides are less than or equal to zero ", () => {
expect(isValidTriangle(0, 2, 4)).toEqual(false);
});

test("Checks for Invalid Triangle, where the sum is (b + c <= a)", () => {
expect(isValidTriangle(2, 2, 4)).toEqual(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@
// This function is commonly used for text encryption and decryption,
// where shifting characters by a certain value can obscure their meaning or reveal hidden messages.

function rotateCharacter(character, shift) {
let startCode;

// Checks if the character is a letter
if (character >= 'A' && character <= 'Z') {
// Uppercase letter
startCode = 'A'.charCodeAt(0);
} else if (character >= 'a' && character <= 'z') {
// Lowercase letter
startCode = 'a'.charCodeAt(0);
} else {
// Not a letter, return it unchanged
return character;
}

// Gets the character's position in the alphabet
const charPosition = character.charCodeAt(0) - startCode;

// Rotates the position within the alphabet (wrap around using %)
const newPosition = (charPosition + shift) % 26;

// Handles negative shift values to wrap correctly
const wrappedPosition = newPosition < 0 ? newPosition + 26 : newPosition;

// Converts the new position back to a character
const rotatedChar = String.fromCharCode(startCode + wrappedPosition);

return rotatedChar;
}

module.exports = rotateCharacter;

// Acceptance criteria:

// Given a character and a shift value,
Expand Down
19 changes: 19 additions & 0 deletions Sprint-3/implement/rotate-character.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const rotateCharacter = require("./rotate-character");

test("Checks for Rotate Lowercase Letters", () => {
expect(rotateCharacter("a", 3)).toEqual("d");
});

test("Checks for Rotate Uppercase Letters", () => {
expect(rotateCharacter("F", 1)).toEqual("G");
});

test("Checks for where Non-Letter Characters are left Unchanged", () => {
expect(rotateCharacter(7, 5)).toEqual(7);
});

test("Checks if a Characters shift with Wraparound", () => {
expect(rotateCharacter("Y", 2)).toEqual("A");
});


Loading