- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 240
Birmingham | 25-ITP-Sept | Khor Biel | Sprint 3 | coursework/sprint-3-practice-tdd #801
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
base: main
Are you sure you want to change the base?
Birmingham | 25-ITP-Sept | Khor Biel | Sprint 3 | coursework/sprint-3-practice-tdd #801
Conversation
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.
Why not include a brief description of the changes made in this PR in the PR description?
        
          
                Sprint-3/2-practice-tdd/count.js
              
                Outdated
          
        
      | typeof stringOfCharacters !== "string" || | ||
| typeof findCharacter !== "string" | ||
| ) { | ||
| return 0; | 
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.
How should the caller distinguish the result of countChar(1234, 5) from the result of countChar("1234", "5")?
| if (typeof num !== "number" || isNaN(num)) { | ||
| return ""; | ||
| } | 
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.
3.1416 and Infinity could pass this test.
| // Case 2: Identify the ordinal number for 2 | ||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|  | 
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.
To ensure thorough testing, we need broad scenarios that cover all possible cases.
Listing individual values, however, can quickly lead to an unmanageable number of test cases.
Instead of writing tests for individual numbers, consider grouping all possible input values into meaningful categories.
Then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain.
For example, we can prepare a test for numbers 2, 22, 132, etc. as
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
    expect( getOrdinalNumber(2) ).toEqual("2nd");
    expect( getOrdinalNumber(22) ).toEqual("22nd");
    expect( getOrdinalNumber(132) ).toEqual("132nd");
});
| test("should return 'th' for numbers ending with 0, 4–9", () => { | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(14)).toEqual("14th"); | ||
| expect(getOrdinalNumber(19)).toEqual("19th"); | ||
| }); | 
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.
This test is good.
| test("should return '11th', '12th', '13th' for special cases", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| }); | 
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.
When the person implementing the function see this test message, they may ask "what exactly are 'special cases'?".
| Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). | 
    
      
        1 similar comment
      
    
  
    | Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). | 
| Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). | 
    
      
        1 similar comment
      
    
  
    | Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). | 
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.
        
          
                Sprint-3/2-practice-tdd/count.js
              
                Outdated
          
        
      | // Ensure valid inputs | ||
| if ( | ||
| typeof stringOfCharacters !== "string" || | ||
| typeof findCharacter !== "string" | ||
| ) { | ||
| return 0; | ||
| } | ||
|  | 
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.
Why remove the check instead of strengthening it?
        
          
                Sprint-3/2-practice-tdd/count.js
              
                Outdated
          
        
      | let count = 0; | ||
| for (let char of stringOfCharacters) { | ||
| if (char === findCharacter) { | ||
| count++; | ||
| let total = 0; | ||
| for (let i=0; i < stringOfCharacters.length; i++){ | ||
| if (findCharacter == stringOfCharacters[i]){ | ||
| total++; | ||
| } | ||
| } | ||
|  | 
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.
Why replace the for-of loop with a for loop? The former is more compact.
| // Ensure the input is a valid number | ||
| if (typeof num !== "number" || isNaN(num)) { | ||
| return ""; | ||
| } | ||
|  | 
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.
Why remove the check instead of strengthening it?
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.
@cjyuan I was just trying to simplify the code
| const lastTwoDigits = num % 100; | ||
| const lastDigit = num % 10; | ||
|  | ||
| let result; | ||
|  | ||
| // Handle special cases: 11th, 12th, 13th | ||
| if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { | ||
| return `${num}th`; | ||
| if (num % 100 == 11 || num % 100 == 12 || num % 100 == 13){ | ||
| result = num.toString() + "th"; | 
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.
Why replace the previous approach
 const lastTwoDigits = num % 100;
  if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
    return `${num}th`;
    
    ...
with the current approach
let result;
  if (num % 100 == 11 || num % 100 == 12 || num % 100 == 13){
    result = num.toString() + "th";
    ...
  return result;
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 was just trying to simplify the code
| Your PR couldn't be matched to an assignment in this module. Please check its title is in the correct format, and that you only have one PR per assignment. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). | 
| Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). | 
| @cjyuan, just give me a few minutes. I'm in the market, I'll edit my code as soon as I get home. | 
| The functions work. Some of the code I commented remain unchanged, so I am not sure if you have addressed all my comments. Can you address all my previous comments? | 

Self checklist