mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-04 22:00:59 -04:00
fix(curriculum): update email simulator tests (#63803)
This commit is contained in:
@@ -15,24 +15,14 @@ Here is an example:
|
||||
|
||||
```py
|
||||
x = 10
|
||||
y = 'Even' if x % 2 == 0 else 'Odd' # y will be even
|
||||
y = 'Even' if x % 2 == 0 else 'Odd' # y will be Even
|
||||
```
|
||||
|
||||
Within the method, before, use conditional expression to assign the string `Read` to a variable `status` if the email is read and `Unread` if it is not.
|
||||
|
||||
# --hints--
|
||||
|
||||
The `__str__` method should create a `status` variable that uses a conditional expression.
|
||||
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
assert(runPython(`_Node(_code).find_class("Email").find_function("__str__").has_stmt("status = 'Read' if self.read else 'Unread'")`));
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
The `__str__` method should return the email information with the status included.
|
||||
You should have a `status` variable within the `__str__` method.
|
||||
|
||||
```js
|
||||
({
|
||||
@@ -42,6 +32,37 @@ The `__str__` method should return the email information with the status include
|
||||
})
|
||||
```
|
||||
|
||||
You should assign a conditional expression to the `status` variable.
|
||||
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
runPython(`
|
||||
import ast
|
||||
assert isinstance(_Node(_code).find_class("Email").find_function("__str__").find_variable("status").tree.value, ast.IfExp)`);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Your conditional expression should evaluate to the string `Read` if the email is read and `Unread` if it is not.
|
||||
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
runPython(`
|
||||
if_exps = [
|
||||
"'Read' if self.read else 'Unread'",
|
||||
"'Read' if self.read == True else 'Unread'",
|
||||
"'Unread' if not self.read else 'Read'",
|
||||
"'Unread' if self.read == False else 'Read'"
|
||||
]
|
||||
foo = _Node(_code).find_class("Email").find_function("__str__")
|
||||
assert any(foo.has_stmt(f"status = {if_exp}") for if_exp in if_exps)
|
||||
`);
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
Reference in New Issue
Block a user