Skip to content

Commit 6949c96

Browse files
authored
fix(curriculum): update email simulator tests (freeCodeCamp#63803)
1 parent 29420e8 commit 6949c96

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

curriculum/challenges/english/blocks/workshop-email-simulator/685cdfd1932d8ac6ad986813.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,50 @@ Here is an example:
1515

1616
```py
1717
x = 10
18-
y = 'Even' if x % 2 == 0 else 'Odd' # y will be even
18+
y = 'Even' if x % 2 == 0 else 'Odd' # y will be Even
1919
```
2020

2121
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.
2222

2323
# --hints--
2424

25-
The `__str__` method should create a `status` variable that uses a conditional expression.
25+
You should have a `status` variable within the `__str__` method.
2626

2727
```js
2828
({
2929
test: () => {
30-
assert(runPython(`_Node(_code).find_class("Email").find_function("__str__").has_stmt("status = 'Read' if self.read else 'Unread'")`));
30+
assert(runPython(`_Node(_code).find_class("Email").find_function("__str__").has_variable("status")`));
3131
}
3232
})
3333
```
3434

35-
The `__str__` method should return the email information with the status included.
35+
You should assign a conditional expression to the `status` variable.
3636

3737
```js
3838
({
3939
test: () => {
40-
assert(runPython(`_Node(_code).find_class("Email").find_function("__str__").has_variable("status")`));
40+
runPython(`
41+
import ast
42+
assert isinstance(_Node(_code).find_class("Email").find_function("__str__").find_variable("status").tree.value, ast.IfExp)`);
43+
}
44+
})
45+
```
46+
47+
Your conditional expression should evaluate to the string `Read` if the email is read and `Unread` if it is not.
48+
49+
```js
50+
({
51+
test: () => {
52+
runPython(`
53+
if_exps = [
54+
"'Read' if self.read else 'Unread'",
55+
"'Read' if self.read == True else 'Unread'",
56+
"'Unread' if not self.read else 'Read'",
57+
"'Unread' if self.read == False else 'Read'"
58+
]
59+
foo = _Node(_code).find_class("Email").find_function("__str__")
60+
assert any(foo.has_stmt(f"status = {if_exp}") for if_exp in if_exps)
61+
`);
4162
}
4263
})
4364
```

0 commit comments

Comments
 (0)