Skip to content

Commit

Permalink
[Meltdown Mitigation]: Modified Test Error Messages & Touched Up Docs (
Browse files Browse the repository at this point in the history
…#3515)

* Modified test error messages to better match test runner changes.  Also did touchup for links in docs.
* Updated test error messages to be more verbose.
* Revert "Updated test error messages to be more verbose."
This reverts commit e800f4e.
[no important files changed]
BethanyG authored Nov 7, 2023
1 parent 538e2d9 commit 89db59b
Showing 4 changed files with 27 additions and 21 deletions.
16 changes: 8 additions & 8 deletions exercises/concept/meltdown-mitigation/.docs/hints.md
Original file line number Diff line number Diff line change
@@ -8,17 +8,17 @@

## 1. Check for criticality

- Comparison operators and boolean operations can be combined and used with conditionals.
- Comparison operators ([comparisons][comparisons review]) and boolean operations ([concept:python/bools]()) can be combined and used with conditionals.
- Conditional expressions must evaluate to `True` or `False`.
- `else` can be used for a code block that will execute when all conditional tests return `False`.

```python
>>> item = 'blue'
>>> item_2 = 'green'

>>> if len(item) >=3 and len(item_2) < 5:
>>> if len(item) >= 3 and len(item_2) < 5:
print('Both pass the test!')
elif len(item) >=3 or len(item_2) < 5:
elif len(item) >= 3 or len(item_2) < 5:
print('One passes the test!')
else:
print('None pass the test!')
@@ -29,20 +29,20 @@
## 2. Determine the Power output range

- Comparison operators can be combined and used with conditionals.
- Any number of `elif` statements can be used as "branches".
- Any number of `elif` statements can be used as decision "branches".
- Each "branch" can have a separate `return`

## 3. Fail Safe Mechanism

- Comparison operators can be combined and used with conditionals.
- Any number of `elif` statements can be used as "branches".
- Any number of `elif` statements can be used as decision "branches".
- Each "branch" can have a separate `return`


[python comparisons examples]: https://www.tutorialspoint.com/python/comparison_operators_example.htm
[boolean operations]: https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not
[comparisons review]: https://www.learnpython.dev/02-introduction-to-python/090-boolean-logic/20-comparisons/
[comparisons]: https://docs.python.org/3/library/stdtypes.html#comparisons
[control flow tools]: https://docs.python.org/3/tutorial/controlflow.html
[python booleans]: https://realpython.com/python-boolean/
[python comparisons examples]: https://www.tutorialspoint.com/python/comparison_operators_example.htm
[real python conditionals]: https://realpython.com/python-conditional-statements/
[control flow tools]: https://docs.python.org/3/tutorial/controlflow.html

10 changes: 5 additions & 5 deletions exercises/concept/meltdown-mitigation/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
In Python, [`if`][if statement], `elif` (_a contraction of 'else and if'_) and `else` statements are used to [control the flow][control flow tools] of execution and make decisions in a program.
Unlike many other programming languages, Python versions 3.9 and below do not offer a formal case-switch statement, instead using multiple `elif` statements to serve a similar purpose.

Python 3.10 introduces a variant case-switch statement called `pattern matching`, which will be covered separately in another concept.
Python 3.10 introduces a variant case-switch statement called `structural pattern matching`, which will be covered separately in another concept.

Conditional statements use expressions that must resolve to `True` or `False` -- either by returning a `bool` directly, or by evaluating ["truthy" or "falsy"][truth value testing].
Conditional statements use expressions that must resolve to `True` or `False` -- either by returning a `bool` type directly, or by evaluating as ["truthy" or "falsy"][truth value testing].

```python
x = 10
@@ -74,8 +74,8 @@ else:
'13'
```

[if statement]: https://docs.python.org/3/reference/compound_stmts.html#the-if-statement
[control flow tools]: https://docs.python.org/3/tutorial/controlflow.html#more-control-flow-tools
[truth value testing]: https://docs.python.org/3/library/stdtypes.html#truth-value-testing
[boolean operations]: https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not
[comparisons]: https://docs.python.org/3/library/stdtypes.html#comparisons
[control flow tools]: https://docs.python.org/3/tutorial/controlflow.html#more-control-flow-tools
[if statement]: https://docs.python.org/3/reference/compound_stmts.html#the-if-statement
[truth value testing]: https://docs.python.org/3/library/stdtypes.html#truth-value-testing
4 changes: 2 additions & 2 deletions exercises/concept/meltdown-mitigation/.meta/design.md
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@

## Goal

The goal of this exercise is to teach the student what is a `conditional` and how they are used in Python.
The goal of this exercise is to teach the student about `conditionals` and how they are used in Python.

## Learning objectives

- learn some general things about `control flow` in python
- learn some general things about `control flow` in Python
- create a `conditional` structure to choose something, take a decision
- use an `if...else` structure
- use an `if..elif...else` structure
18 changes: 12 additions & 6 deletions exercises/concept/meltdown-mitigation/conditionals_test.py
Original file line number Diff line number Diff line change
@@ -30,8 +30,10 @@ def test_is_criticality_balanced(self):

# pylint: disable=assignment-from-no-return
actual_result = is_criticality_balanced(temp, neutrons_emitted)
failure_message = (f'Expected {expected} but returned {actual_result} '
f'with T={temp} and neutrons={neutrons_emitted}')
failure_message = (f'Called is_criticality_balanced({temp}, {neutrons_emitted}). '
f' The function returned {actual_result}, '
f'but the test expected {expected} as the return value.')

self.assertEqual(actual_result, expected, failure_message)

@pytest.mark.task(taskno=2)
@@ -52,8 +54,10 @@ def test_reactor_efficiency(self):

# pylint: disable=assignment-from-no-return
actual_result = reactor_efficiency(voltage, current, theoretical_max_power)
failure_message = (f'Expected {expected} but returned {actual_result} '
f'with voltage={voltage}, current={current}, max_pow={theoretical_max_power}')
failure_message =(f'Called reactor_efficiency({voltage}, {current}, {theoretical_max_power}). '
f'The function returned {actual_result}, '
f'but the test expected {expected} as the return value.')

self.assertEqual(actual_result, expected, failure_message)

@pytest.mark.task(taskno=3)
@@ -71,6 +75,8 @@ def test_fail_safe(self):

# pylint: disable=assignment-from-no-return
actual_result = fail_safe(temp, neutrons_per_second, threshold)
failure_message = (f'Expected {expected} but returned {actual_result} with T={temp}, '
f'neutrons={neutrons_per_second}, threshold={threshold}')
failure_message = (f'Called fail_safe({temp}, {neutrons_per_second}, {threshold}). '
f'The function returned {actual_result}, '
f'but the test expected {expected} as the return value.')

self.assertEqual(actual_result, expected, failure_message)

0 comments on commit 89db59b

Please sign in to comment.