Skip to content

Commit

Permalink
Merge branch 'master' into CON-3265-fix-rust-quest-03
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodesu authored Dec 26, 2024
2 parents 9ae0340 + 26623fc commit 97f0509
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Welcome to the [Public](https://github.com/01-edu/public) Repository of the [01 Edu System](https://github.com/01-edu) 👋

![01 Edu System](https://github.com/01-edu/public/assets/14015057/35560fed-34e6-42c8-a71b-71b0534b7ad7)
![01-Edu](https://github.com/user-attachments/assets/addd2e35-d07c-4201-98b7-521443ad38e6)

### 🍎 Our Courses

Expand Down
25 changes: 17 additions & 8 deletions dom/class-it_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ tests.push(async ({ page, eq }) => {
})

tests.push(async ({ page, eq }) => {
// check that the targetted elements have the correct class names
await eq.$('p#eye-left', { className: 'eye' })
await eq.$('p#eye-right', { className: 'eye' })
await eq.$('div#arm-left', { className: 'arm body-member' })
await eq.$('div#arm-right', { className: 'arm body-member' })
await eq.$('div#leg-left', { className: 'leg body-member' })
await eq.$('div#leg-right', { className: 'leg body-member' })
})
// Helper function to check if an element has the expected classes
async function hasClasses(selector, expectedClasses) {
const element = await page.$(selector);
const className = await element.evaluate(el => el.className);
const classList = className.split(' ').sort();
const expectedClassList = expectedClasses.split(' ').sort();
return JSON.stringify(classList) === JSON.stringify(expectedClassList);
}

// Check that the target elements have the correct classes
eq(await hasClasses('p#eye-left', 'eye'), true);
eq(await hasClasses('p#eye-right', 'eye'), true);
eq(await hasClasses('div#arm-left', 'arm body-member'), true);
eq(await hasClasses('div#arm-right', 'arm body-member'), true);
eq(await hasClasses('div#leg-left', 'leg body-member'), true);
eq(await hasClasses('div#leg-right', 'leg body-member'), true);
});
5 changes: 5 additions & 0 deletions js/tests/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ if test "$CODE_EDITOR_RUN_ONLY" = true; then
exit
fi

if test "$EXERCISE" = "elementary"; then
node --disallow-code-generation-from-strings /app/test.mjs "/jail/student" "${EXERCISE}"
exit
fi

node /app/test.mjs "/jail/student" "${EXERCISE}"
54 changes: 27 additions & 27 deletions js/tests/happiness-manager_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,52 +100,52 @@ tests.push(async ({ eq, ctx }) => {
})

tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'beer' }
// should create a list with 6-packs-beers and potatoes
// test when vips answer { drink: 'iced-tea' }
// should create a list with iced-tea-bottles and potatoes
const answers = [
{ answer: 'no', drink: 'beer' },
...ctx.createAnswers(1, { answer: 'yes', drink: 'beer' }),
...ctx.createAnswers(1, { answer: 'yes', drink: 'iced-tea' }),
]
await ctx.setAnswersIn({ dir: 'guests', answers })

const { data } = await ctx.run('guests', 'happy-beer-list.json')
return eq(data, { potatoes: 1, '6-packs-beers': 1 })
const { data } = await ctx.run('guests', 'happy-iced-tea-list.json')
return eq(data, { potatoes: 1, 'iced-tea-bottles': 1 })
})

tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'beer' }
// should create a list with 6-packs-beers and potatoes
// test when vips answer { drink: 'iced-tea' }
// should create a list with iced-tea-bottles and potatoes
const answers = [
{ answer: 'no', drink: 'beer' },
...ctx.createAnswers(6, { answer: 'yes', drink: 'beer' }),
{ answer: 'no', drink: 'iced-tea' },
...ctx.createAnswers(6, { answer: 'yes', drink: 'iced-tea' }),
]
await ctx.setAnswersIn({ dir: 'guests', answers })

const { data } = await ctx.run('guests', 'happy-beer-pack-list.json')
return eq(data, { potatoes: 6, '6-packs-beers': 1 })
const { data } = await ctx.run('guests', 'happy-iced-tea-bottles-list.json')
return eq(data, { potatoes: 6, 'iced-tea-bottles': 1 })
})

tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'wine' }
// should create a list with wine-bottles and potatoes
// test when vips answer { drink: 'sparkling-water' }
// should create a list with sparkling-water-bottles and potatoes
const answers = [
...ctx.createAnswers(3, { answer: 'no', drink: 'wine' }),
...ctx.createAnswers(5, { answer: 'yes', drink: 'wine' }),
...ctx.createAnswers(3, { answer: 'no', drink: 'sparkling-water' }),
...ctx.createAnswers(5, { answer: 'yes', drink: 'sparkling-water' }),
]
await ctx.setAnswersIn({ dir: 'guests', answers })

const { data } = await ctx.run('guests', 'happy-wine-list.json')
return eq(data, { potatoes: 5, 'wine-bottles': 2 })
const { data } = await ctx.run('guests', 'happy-sparkling-water-list.json')
return eq(data, { potatoes: 5, 'sparkling-water-bottles': 2 })
})

tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'wine' }
// should create a list with wine-bottles and potatoes
const answers = ctx.createAnswers(8, { answer: 'yes', drink: 'wine' })
// test when vips answer { drink: 'sparkling-water' }
// should create a list with sparkling-water-bottles and potatoes
const answers = ctx.createAnswers(8, { answer: 'yes', drink: 'sparkling-water' })
await ctx.setAnswersIn({ dir: 'guests', answers })

const { data } = await ctx.run('guests', 'happy-wine-bottle-list.json')
return eq(data, { potatoes: 8, 'wine-bottles': 2 })
const { data } = await ctx.run('guests', 'happy-sparkling-water-bottles-list.json')
return eq(data, { potatoes: 8, 'sparkling-water-bottles': 2 })
})

tests.push(async ({ eq, ctx }) => {
Expand Down Expand Up @@ -365,12 +365,12 @@ tests.push(async ({ eq, ctx }) => {
}),
...ctx.createAnswers(6, { answer: 'yes', food: 'vegan', drink: 'water' }),
...ctx.createAnswers(2, { answer: 'yes', food: 'veggie', drink: 'water' }),
...ctx.createAnswers(3, { answer: 'yes', food: 'veggie', drink: 'beer' }),
...ctx.createAnswers(11, { answer: 'yes', food: 'fish', drink: 'wine' }),
...ctx.createAnswers(3, { answer: 'yes', food: 'veggie', drink: 'iced-tea' }),
...ctx.createAnswers(11, { answer: 'yes', food: 'fish', drink: 'sparkling-water' }),
...ctx.createAnswers(4, {
answer: 'yes',
food: 'everything',
drink: 'beer',
drink: 'iced-tea',
}),
]
await ctx.setAnswersIn({ dir: 'guests', answers })
Expand All @@ -388,8 +388,8 @@ tests.push(async ({ eq, ctx }) => {
sardines: 11,
burgers: 2,
kebabs: 4,
'6-packs-beers': 2,
'wine-bottles': 3,
'iced-tea-bottles': 2,
'sparkling-water-bottles': 3,
'water-bottles': 2,
'soft-bottles': 1,
})
Expand Down
10 changes: 5 additions & 5 deletions js/tests/level-up.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
"code": "equal(shaker.length, 3)"
},
{
"description": "shaker can make a cocktail.",
"code": "equal(shaker(1, 'strawberry', true), '1 strawberry cocktail')"
"description": "shaker can make a skinny milkshake.",
"code": "equal(shaker(1, 'strawberry', true), '1 skinny strawberry milkshake')"
},
{
"description": "shaker can make a milkshake.",
"code": "equal(shaker(1, 'strawberry', false), '1 strawberry milkshake')"
},
{
"description": "shaker can make multiple cocktails.",
"code": "equal(shaker(7, 'banana', true), '7 banana cocktails')"
"description": "shaker can make multiple skinny milkshakes.",
"code": "equal(shaker(7, 'banana', true), '7 skinny banana milkshakes')"
},
{
"description": "shaker can make multiple milkshakes.",
"code": "equal(shaker(22, 'banana', false), '22 banana milkshakes')"
},
{
"description": "shaker is shakin it right.",
"code": "equal(shaker(1, 'vanilla', true), '1 vanilla cocktail')\nequal(shaker(1, 'mango', true), '1 mango cocktail')\nequal(shaker(2, 'banana', true), '2 banana cocktails')\nequal(shaker(2, 'chocolate', false), '2 chocolate milkshakes')\nequal(shaker(2, 'vanilla', false), '2 vanilla milkshakes')\nequal(shaker(2, 'strawberry', false), '2 strawberry milkshakes')"
"code": "equal(shaker(1, 'vanilla', true), '1 skinny vanilla milkshake')\nequal(shaker(1, 'mango', true), '1 skinny mango milkshake')\nequal(shaker(2, 'banana', true), '2 skinny banana milkshakes')\nequal(shaker(2, 'chocolate', false), '2 chocolate milkshakes')\nequal(shaker(2, 'vanilla', false), '2 vanilla milkshakes')\nequal(shaker(2, 'strawberry', false), '2 strawberry milkshakes')"
}
]
2 changes: 1 addition & 1 deletion sh/debian/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function deployPlatform() {
git clone git@github.com-01-edu-all:01-edu/all.git /root/"$serverFQDN"
cd /root/"$serverFQDN"
# Generate platform environment file automatically
./generate_env.sh --gen
./gene_env.sh --gen
./redeploy.sh --hard
}

Expand Down
24 changes: 14 additions & 10 deletions subjects/blockchain/local-node-info/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
## Local Node Info

To start, we will create a simple page that displays basic information from our local node.
To get started, we will create a simple web page that displays basic information from our local node.

### Instructions

Create a web page, `localNodeInfo.html` that loads an ethereum library, connects to a local node at `http://localhost:8545` and displays basic information :
Create a web page called `localNodeInfo.html` that does the following:

- In an element with (`id`=`chainId`), the number ID of the current network
- In an element with `blockNumber` as `id` the number of blocks in the chain
1. Loads an Ethereum library, such as `ethers.js` or `web3.js`.
2. Connects to a local Ethereum node at `http://localhost:8545`.
3. Displays the following information on the page:

![image](networkInfo.png)
- The ID of the current network in an element with `chainId` as `id`.
- The number of blocks in the chain in an element with `blockNumber` as `id`.

![image](network-infos.png)

### Hint

You can use any library such as `ethers.js` or `web3.js` to connect to your local node.
🚫 Please be aware that the test environment restricts internet access for security reasons. Therefore, you need to download the library and import it locally.

Automated tests check for elements with specific IDs, the design is up to you.
🎨 Automated tests only check for the content of elements with specific IDs; the rest of the design is up to you.

Minimal structure:
🎁 Here is a minimal example structure for the HTML file:

```HTML
<!DOCTYPE html>
<body>
<span id="chainId"></span>
<span id="blockNumber"></span>

<script src="XXX"></script>
<script src="./XXX"></script>
<script type="module">
// Your code
</script>
Expand All @@ -36,4 +40,4 @@ Minimal structure:
### Notions

- [ethers Provider transaction-methods](https://docs.ethers.io/v5/api/providers/provider/#Provider--network-methods)
- [web3](https://web3js.readthedocs.io/en/v1.3.4/web3-eth.html)
- [web3 providers](https://docs.web3js.org/guides/web3_providers_guide/)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed subjects/blockchain/local-node-info/networkInfo.png
Binary file not shown.
2 changes: 1 addition & 1 deletion subjects/copy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ And its output:
```console
$ cargo run
(0, 1.0, -inf)
("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351")
([1, 2, 4, 5], [0.0, 0.6931471805599453, 1.3862943611198906, 1.6094379124341003])
("1 2 4 5 6", "2.718281828459045 7.38905609893065 54.598150033144236 148.4131591025766 403.4287934927351")
$
```

Expand Down
1 change: 1 addition & 0 deletions subjects/cybersecurity/hole-in-bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Files that must be inside your repository:
- All tools you use, and any scripts you write.

> It's forbidden to use external scripts, in the audit you will be asked different questions about the concepts and the practices of this project, prepare yourself!
> It's is forbidden to use `strings` command.
1 change: 1 addition & 0 deletions subjects/elementary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Create 3 functions which each take `(a, b)` as arguments:
```js
Math.imul = undefined
eval = undefined
```
26 changes: 13 additions & 13 deletions subjects/happiness-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,46 @@
As you're smart, you asked every guest of the party to precise in their answer
the kind of drink they would enjoy and the kind of food they would die for.

Create a `happiness-manager.mjs` script that sort, who wants to drink what and
Create a `happiness-manager.mjs` script that sorts, who wants to drink what and
who wants to eat what and integrate that in your barbecue's shopping list!

> note that you must only consider **vips** guests, those that answerd `'yes'`
> note that you must only consider as **VIP** guests, those that answered `'yes'`
The script must:

- Take a directory as first argument (the `guest` directory)
- Take a file `.json` as second argument:
- If the file already exists, it will add the informations to it. If some elements already exist in the original file, it will be replaced by new values.
- If the file already exists, it will add the information to it. If some elements already exist in the original file, it will be replaced by new values.
- If it doesn't, the script must handle the creation of the file.
- Handle case when no one answered yes to the invitation:
- `No one is coming.` has to appear in console.
- Handle the case when no one answered yes to the invitation:
- `No one is coming.` has to appear in the console.
- No file is updated/created.
- Handle cases when answers contains no "food" information, or no "drink"
- Handle cases when answers contain no "food" information, or no "drink"
information
- Handle cases when no one has chosen a category (for example: no one chose to
drink softs). This category should not appear in the final list.

You have to handle the info like this:

- Drinks:
- Beers: 1 pack / 6 vips (rounded up). Expected key: `6-packs-beers`.
- Water, wine, softs: 1 bottle / 4 vips in each category (rounded up).
Expected keys: `wine-bottles`, `water-bottles`, `soft-bottles`.
- Iced tea: 1 pack / 6 VIPs (rounded up). Expected key: `iced-tea-bottles`.
- Water, sparkling water, softs: 1 bottle / 4 VIPs in each category (rounded up).
Expected keys: `sparkling-water-bottles`, `water-bottles`, `soft-bottles`.
- Food:
- Veggies and vegans: 1 eggplant, 1 courgette, 3 mushrooms and 1 hummus / 3
vips in these categories put together. Expected keys: `eggplants`,
VIPs in these categories put together. Expected keys: `eggplants`,
`mushrooms`, `hummus`, `courgettes`.
- Carnivores: 1 burger per person. Expected key: `burgers`.
- Fish lovers: 1 sardine per person. Expected key: `sardines`.
- Omnivores: 1 chicken+shrimps+pepper kebab / person. Expected key: `kebabs`.
- Bonus: you'll add 1 potatoe per person (all categories put together).
- Bonus: you'll add 1 potato per person (all categories put together).
Expected key: `potatoes`.

The infos have to be formated like this in the `.json` file:
The info has to be formated like this in the `.json` file:

```js
{
"key": 1 // according to actual number associated to the elem
"key": 1 // according to actual number associated to the element
}
```

Expand Down
32 changes: 16 additions & 16 deletions subjects/level-up/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ is an example:

```js
let happy = (mood) => {
if (mood === 'happy') {
return true
if (mood === "happy") {
return true;
}
return false
}
return false;
};

let result1 = happy('happy')
let result2 = happy('sad')
let result1 = happy("happy");
let result2 = happy("sad");

console.log(result1) // true
console.log(result2) // false
console.log(result1); // true
console.log(result2); // false
```

Here we used the `if` statement, and two `return` keywords to alternate between
Expand All @@ -27,25 +27,25 @@ the string `happy` or not. The possibilities are becoming limitless...
### Instructions

As Rick's robot, you are continuing your training to add yourself new ... skills
(I could have said funtions). You want now to become a robot bartender.
(I could have said functions). You want now to become a robot barista.

Define the function `shaker` which will take as arguments:

- `quantity`, which will be variable of type `Number`
- `fruit`, which will be a `String`
- `alcohol`, which will be a `Boolean`
- `diet`, which will be a `Boolean`

`shaker` must return a `String`. Look at the examples below to understand how
`shaker` must mix its ingredients:

```js
console.log(shaker(1, 'strawberry', true))
//'1 strawberry cocktail'
console.log(shaker(2, 'chocolate', false))
console.log(shaker(1, "strawberry", true));
//'1 skinny strawberry milkshake'
console.log(shaker(2, "chocolate", false));
//'2 chocolate milkshakes'
console.log(shaker(2, 'strawberry', true))
//'2 strawberry cocktails'
console.log(shaker(1, 'chocolate', false))
console.log(shaker(2, "strawberry", true));
//'2 skinny strawberry milkshakes'
console.log(shaker(1, "chocolate", false));
//'1 chocolate milkshake'
```

Expand Down
Loading

0 comments on commit 97f0509

Please sign in to comment.