Skip to content

Commit 9a891c6

Browse files
committed
Merge branch 'coursework/sprint-3' of https://github.com/HoussamLh/Module-Structuring-and-Testing-Data into coursework/sprint-3
2 parents 6d4f165 + 8f3d6cf commit 9a891c6

25 files changed

+273
-93
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
blank_issues_enabled: false
1+
blank_issues_enabled: true
22
contact_links:
33
- name: CYF
44
@@ -8,7 +8,7 @@ contact_links:
88
about: Join CYF here
99
- name: CYF Slack
1010
url: codeyourfuture.slack.com
11-
about: Come to #cyf-syllabus-tech and chat
11+
about: Come to #cyf-curriculum and chat
1212
- name: CYF Tech Ed
1313
url: https://github.com/orgs/CodeYourFuture/teams/mentors
1414
about: CYF mentors on Github

.github/ISSUE_TEMPLATE/pd-assignment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PD Coursework
22
description: Assign a piece of PD coursework
33
title: "[PD] <title>"
4-
labels: [PD, 🏝 Priority Stretch, 🐇 Size Small]
4+
labels: [PD, 🏝 Priority Stretch, 🐇 Size Small, 📅 Sprint 1]
55
body:
66
- type: markdown
77
attributes:

.github/ISSUE_TEMPLATE/tech-ed-assignment.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
name: Tech Ed Coursework
22
description: Assign a piece of technical coursework
3-
title: "[TECH ED] <title>"
4-
labels: [Tech Ed, 🏕 Priority Mandatory, 🐂 Size Medium]
3+
title: "<title>"
4+
labels: [Tech Ed, 🏕 Priority Mandatory, 🐂 Size Medium, 📅 Sprint 1]
55
body:
66
- type: markdown
77
attributes:
88
value: |
9-
Thanks for taking the time to assign this coursework!
9+
Thanks for taking the time to assign this coursework!
1010
11-
To support our trainees with planning and prioritising their own learning journey, we want our coursework assignments to be more informative.
11+
To support our trainees with planning and prioritising their own learning journey, we want our coursework assignments to be more informative.
1212
We don't just want to tell them what to do, we want to tell them stuff like:
1313
- why we are doing it
1414
- what it's "for" (problem-solving, debugging, etc)
1515
- how long they should spend on it, maximum
16-
- how to get help
17-
- how to review it with answers
16+
- how to get help
17+
- how to review it with answers
1818
- how to get it reviewed from mentors and peers
1919
- type: input
2020
attributes:
2121
label: Link to the coursework
2222
validations:
2323
required: true
24+
- type : textarea
25+
attributes:
26+
label: Learning Objectives
27+
description: https://common.codeyourfuture.io/common-theme/shortcodes/objectives/
28+
placeholder: |
29+
<!--{{<objectives}}-->
30+
- [ ] CYF format, task list formatting
31+
<!--{{</objectives}}-->
2432
- type: textarea
2533
attributes:
2634
label: Why are we doing this?
@@ -37,14 +45,14 @@ body:
3745
attributes:
3846
label: How to get help
3947
description: State simply how trainees can get help with this assignment
40-
placeholder: |
48+
value: |
4149
Share your blockers in your class channel
42-
https://syllabus.codeyourfuture.io/guides/asking-questions
50+
https://curriculum.codeyourfuture.io/guides/getting-help/asking-questions/
4351
- type: textarea
4452
attributes:
4553
label: How to submit
4654
description: State in clear steps how a trainee can submit this assignment.
47-
placeholder: |
55+
value: |
4856
Fork the repo to your own GitHub account
4957
Make regular small commits with clear messages
5058
When you are ready, open a Pull Request to the CYF repo
@@ -72,9 +80,9 @@ body:
7280
1. Update labels
7381
- priority -- is this coursework key, mandatory, or stretch? Pick one.
7482
- size -- help trainees plan their time with rough estimation. Pick one
75-
- topics -- add all that seem relevant to you.
76-
2. Add to milestone
77-
- week 1,2,3,4
83+
- topics -- add all that seem relevant to you.
84+
2. Add a Sprint label to add to the backlog view
85+
- sprint 1,2,3,4
7886
7987
Once your ticket is complete, you may like to add it to the example project board attached to this repo.
8088
This is so you understand how trainees will use your work. Nobody has built a board copier yet, so trainees will be doing this step themselves.

.github/pull_request_template.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
33
You must title your PR like this:
44
5-
REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
5+
Region | Cohort | FirstName LastName | Sprint | Assignment Title
66
77
For example,
88
9-
London | May-2025 | Carol Owen | Sprint-1
9+
London | 25-ITP-May | Carol Owen | Sprint 1 | Alarm Clock
1010
11-
Complete the task list below this message.
12-
If your PR is rejected, check the task list.
11+
Fill in the template below - remove any sections that don't apply.
12+
13+
Complete the self checklist - replace each empty box in the checklist [ ] with a [x].
14+
15+
Add the label "Needs Review" and you will get review.
16+
17+
Respond to volunteer reviews until the volunteer marks it as "Complete".
1318
1419
-->
1520

1621
## Learners, PR Template
1722

1823
Self checklist
1924

20-
- [ ] I have committed my files one by one, on purpose, and for a reason
21-
- [ ] I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
25+
- [ ] I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
26+
- [ ] My changes meet the requirements of the task
2227
- [ ] I have tested my changes
23-
- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/)
24-
- [ ] My changes meet the [requirements](./README.md) of this task
28+
- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/reviewing/style-guide/)
2529

2630
## Changelist
2731

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Validate PR Metadata
2+
on:
3+
pull_request_target:
4+
types:
5+
- labeled
6+
- unlabeled
7+
- opened
8+
- edited
9+
- reopened
10+
11+
jobs:
12+
validate_pr_metadata:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: CodeYourFuture/actions/validate-pr-metadata@main
17+
with:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Implement solutions and rewrite tests with Jest
2+
3+
## 1 Implement solutions
4+
5+
In the `implement` directory you've got a number of functions you'll need to implement.
6+
For each function, you also have a number of different cases you'll need to check for your function.
7+
8+
Write your assertions and build up your program case by case. Don't rush to a solution. The point of these assignments is to learn how to write assertions and build up a program step by step.
9+
10+
Here is a recommended order:
11+
12+
1. `1-get-angle-type.js`
13+
2. `2-is-proper-fraction.js`
14+
3. `3-get-card-value.js`
15+
16+
## 2 Rewrite tests with Jest
17+
18+
`console.log` is most often used as a debugging tool. We use to inspect the state of our program during runtime.
19+
20+
We can use `console.assert` to write assertions: however, it is not very easy to use when writing large test suites. In the first section, Implement, we used a custom "helper function" to make our assertions more readable.
21+
22+
Jest is a whole library of helper functions we can use to make our assertions more readable and easier to write.
23+
24+
Your new task is to write the same tests as you wrote in the `implement` directory, but using Jest instead of `console.assert`.
25+
26+
You shouldn't have to change the contents of `implement` to write these tests.
27+
28+
There are files for your Jest tests in the `rewrite-tests-with-jest` directory. They will automatically use the functions you already implemented.
29+
30+
You can run all the tests in this repo by running `npm test` in your terminal. However, VSCode has a built-in test runner that you can use to run the tests, and this should make it much easier to focus on building up your test cases one at a time.
31+
32+
https://code.visualstudio.com/docs/editor/testing
33+
34+
1. Go to rewrite-tests-with-jest/1-get-angle-type.test.js
35+
2. Click the green play button to run the test. It's on the left of the test function in the gutter.
36+
3. Read the output in the TEST_RESULTS tab at the bottom of the screen.
37+
4. Explore all the tests in this repo by opening the TEST EXPLORER tab. The logo is a beaker.
38+
39+
![VSCode Test Runner](../../run-this-test.png)
40+
41+
![Test Results](../../test-results-output.png)
42+
43+
> [!TIP]
44+
> You can always run a single test file by running `npm test path/to/test-file.test.js`.

Sprint-3/1-key-implement/1-get-angle-type.js renamed to Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,25 @@
88
// Then, write the next test! :) Go through this process until all the cases are implemented
99

1010
function getAngleType(angle) {
11+
<<<<<<< HEAD:Sprint-3/1-key-implement/1-get-angle-type.js
1112
if (angle === 90) return "Right angle";
1213
if (angle < 90) return "Acute angle";
1314
if (angle > 90 && angle < 180) return "Obtuse angle";
1415
if (angle === 180) return "Straight angle";
1516
if (angle > 180 && angle < 360) return "Reflex angle";
17+
=======
18+
if (angle === 90) {
19+
return "Right angle";
20+
}
21+
// Run the tests, work out what Case 2 is testing, and implement the required code here.
22+
// Then keep going for the other cases, one at a time.
23+
>>>>>>> 8f3d6cf2d1733da02a010f1a16c46b8b5ab4c491:Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js
1624
}
1725

26+
// The line below allows us to load the getAngleType function into tests in other files.
27+
// This will be useful in the "rewrite tests with jest" step.
28+
module.exports = getAngleType;
29+
1830
// we're going to use this helper function to make our assertions easier to read
1931
// if the actual output matches the target output, the test will pass
2032
function assertEquals(actualOutput, targetOutput) {

Sprint-3/1-key-implement/2-is-proper-fraction.js renamed to Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11+
<<<<<<< HEAD:Sprint-3/1-key-implement/2-is-proper-fraction.js
1112
// Use absolute value of numerator to handle negatives
1213
if (numerator < denominator) return true;
1314
return false; // for all other cases
15+
=======
16+
if (numerator < denominator) {
17+
return true;
18+
}
19+
>>>>>>> 8f3d6cf2d1733da02a010f1a16c46b8b5ab4c491:Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
1420
}
1521

22+
// The line below allows us to load the isProperFraction function into tests in other files.
23+
// This will be useful in the "rewrite tests with jest" step.
24+
module.exports = isProperFraction;
25+
1626
// here's our helper again
1727
function assertEquals(actualOutput, targetOutput) {
1828
console.assert(
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck
2+
3+
// You will need to implement a function getCardValue
4+
// the function takes a single parameter, a string representing a playing card
5+
// the function should return the numerical value of the card
6+
// the first test and first case is written for you
7+
// complete the rest of the tests and cases
8+
// write one test at a time, and make it pass, build your solution up methodically
9+
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
10+
function getCardValue(card) {
11+
<<<<<<< HEAD:Sprint-3/1-key-implement/3-get-card-value.js
12+
const rank = card.slice(0, -1); // remove the emoji
13+
if (rank === "A") return 11;
14+
if (["K", "Q", "J", "10"].includes(rank)) return 10;
15+
const number = Number(rank);
16+
if (number >= 2 && number <= 9) return number;
17+
throw new Error("Invalid card rank");
18+
=======
19+
if (rank === "A") {
20+
return 11;
21+
}
22+
>>>>>>> 8f3d6cf2d1733da02a010f1a16c46b8b5ab4c491:Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
23+
}
24+
25+
// The line below allows us to load the getCardValue function into tests in other files.
26+
// This will be useful in the "rewrite tests with jest" step.
27+
module.exports = getCardValue;
28+
29+
// You need to write assertions for your function to check it works in different cases
30+
// we're going to use this helper function to make our assertions easier to read
31+
// if the actual output matches the target output, the test will pass
32+
function assertEquals(actualOutput, targetOutput) {
33+
console.assert(
34+
actualOutput === targetOutput,
35+
`Expected ${actualOutput} to equal ${targetOutput}`
36+
);
37+
}
38+
// Acceptance criteria:
39+
40+
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A),
41+
// When the function getCardValue is called with this card string as input,
42+
// Then it should return the numerical card value
43+
const aceofSpades = getCardValue("A♠");
44+
assertEquals(aceofSpades, 11);
45+
46+
// Handle Number Cards (2-10):
47+
// Given a card with a rank between "2" and "9",
48+
// When the function is called with such a card,
49+
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
50+
const fiveofHearts = getCardValue("5♥");
51+
assertEquals(fiveofHearts, 5);
52+
53+
54+
// Handle Face Cards (J, Q, K):
55+
// Given a card with a rank of "10," "J," "Q," or "K",
56+
// When the function is called with such a card,
57+
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
58+
const jackofClubs = getCardValue("J♣");
59+
assertEquals(jackofClubs, 10);
60+
61+
const queenofDiamonds = getCardValue("Q♦");
62+
assertEquals(queenofDiamonds, 10);
63+
64+
const kingofHearts = getCardValue("K♥");
65+
assertEquals(kingofHearts, 10);
66+
67+
// Handle Ace (A):
68+
// Given a card with a rank of "A",
69+
// When the function is called with an Ace,
70+
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
71+
72+
const aceofSpades = getCardValue("A♠");
73+
assertEquals(aceofSpades, 11);
74+
75+
// Handle Invalid Cards:
76+
// Given a card with an invalid rank (neither a number nor a recognized face card),
77+
// When the function is called with such a card,
78+
// Then it should throw an error indicating "Invalid card rank."
79+
80+
81+
// getCardValue("Z♠"); // should throw "Invalid card rank"
82+
83+

Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js renamed to Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const getAngleType = require("./1-get-angle-type");
1+
// This statement loads the getAngleType function you wrote in the implement directory.
2+
// We will use the same function, but write tests for it using Jest in this file.
3+
const getAngleType = require("../implement/1-get-angle-type");
24

35
test("should identify right angle (90°)", () => {
46
expect(getAngleType(90)).toEqual("Right angle");

0 commit comments

Comments
 (0)