Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions exercises/concept/meltdown-mitigation/.meta/exemplar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def is_criticality_balanced(temperature, neutrons_emitted):
'''
"""Verify criticality is balanced.
:param temperature: int
:param neutrons_emitted: int
Expand All @@ -9,17 +9,18 @@ def is_criticality_balanced(temperature, neutrons_emitted):
- The temperature less than 800.
- The number of neutrons emitted per second greater than 500.
- The product of temperature and neutrons emitted per second less than 500000.
'''
"""
output = temperature * neutrons_emitted
balanced = False

if (temperature < 800 and neutrons_emitted > 500) and output < 500000:
return True
else:
return False
balanced = True

return balanced


def reactor_efficiency(voltage, current, theoretical_max_power):
'''
"""Assess reactor efficiency zone.
:param voltage: int
:param current: int
Expand All @@ -36,21 +37,25 @@ def reactor_efficiency(voltage, current, theoretical_max_power):
These percentage ranges are calculated as
(generated power/ theoretical max power)*100
where generated power = voltage * current
'''
"""
generated_power = voltage * current
percentage_range = (generated_power/theoretical_max_power)*100
percentage_range = (generated_power / theoretical_max_power) * 100
efficiency_level = 'unknown'

if 80 <= percentage_range <= 100:
return 'green'
efficiency_level = 'green'
elif 60 <= percentage_range <= 79:
return 'orange'
efficiency_level = 'orange'
elif 30 <= percentage_range <= 59:
return 'red'
efficiency_level = 'red'
else:
return 'black'
efficiency_level = 'black'

return efficiency_level


def fail_safe(temperature, neutrons_produced_per_second, threshold):
'''
"""Assess and return safety range.
:param temperature:
:param neutrons_produced_per_second:
Expand All @@ -60,13 +65,16 @@ def fail_safe(temperature, neutrons_produced_per_second, threshold):
- `temperature * neutrons per second` < 40% of `threshold` == 'LOW'
- `temperature * neutrons per second` +/- 10% of `threshold` == 'NORMAL'
- `temperature * neutron per second` is not in the above-stated ranges == 'DANGER'
'''
"""
output = temperature * neutrons_produced_per_second
operational_percentage = int((output/threshold) * 100)
operational_percentage = int((output / threshold) * 100)
safety_range = 'UNKNOWN'

if operational_percentage < 40:
return 'LOW'
safety_range = 'LOW'
elif 90 <= operational_percentage <= 110:
return 'NORMAL'
safety_range = 'NORMAL'
else:
return 'DANGER'
safety_range = 'DANGER'

return safety_range
12 changes: 6 additions & 6 deletions exercises/concept/meltdown-mitigation/conditionals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def is_criticality_balanced(temperature, neutrons_emitted):
'''
"""Verify criticality is balanced.
:param temperature: int
:param neutrons_emitted: int
Expand All @@ -9,13 +9,13 @@ def is_criticality_balanced(temperature, neutrons_emitted):
- The temperature is less than 800.
- The number of neutrons emitted per second is greater than 500.
- The product of temperature and neutrons emitted per second is less than 500000.
'''
"""

pass


def reactor_efficiency(voltage, current, theoretical_max_power):
'''
"""Assess reactor efficiency zone.
:param voltage: int
:param current: int
Expand All @@ -32,13 +32,13 @@ def reactor_efficiency(voltage, current, theoretical_max_power):
These percentage ranges are calculated as
(generated power/ theoretical max power)*100
where generated power = voltage * current
'''
"""

pass


def fail_safe(temperature, neutrons_produced_per_second, threshold):
'''
"""Assess and return safety range.
:param temperature:
:param neutrons_produced_per_second:
Expand All @@ -48,6 +48,6 @@ def fail_safe(temperature, neutrons_produced_per_second, threshold):
- `temperature * neutrons per second` < 40% of threshold == 'LOW'
- `temperature * neutrons per second` +/- 10% of `threshold` == 'NORMAL'
- `temperature * neutron per second` is not in the above-stated ranges == 'DANGER'
'''
"""

pass
31 changes: 19 additions & 12 deletions exercises/concept/meltdown-mitigation/conditionals_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import pytest
from conditionals import (is_criticality_balanced,
reactor_efficiency,
fail_safe
)
fail_safe)


class TestConditionals(unittest.TestCase):
Expand All @@ -14,33 +13,32 @@ class TestConditionals(unittest.TestCase):

@pytest.mark.task(taskno=1)
def test_is_criticality_balanced_set1(self):

self.assertTrue(is_criticality_balanced(
temperature=750, neutrons_emitted=650), msg="Expected True but returned False")


@pytest.mark.task(taskno=1)
def test_is_criticality_balanced_set2(self):

self.assertTrue(is_criticality_balanced(
temperature=799, neutrons_emitted=501), msg="Expected True but returned False")


@pytest.mark.task(taskno=1)
def test_is_criticality_balanced_set3(self):

self.assertTrue(
is_criticality_balanced(temperature=500, neutrons_emitted=600), msg="Expected True but returned False"
)


@pytest.mark.task(taskno=1)
def test_is_criticality_balanced_set4(self):

self.assertFalse(
is_criticality_balanced(temperature=800, neutrons_emitted=500), msg="Expected False but returned True"
)

# End of first functions testing
# End of first functions testing

# Test case for reactor_ efficiency()
# Test case for reactor_ efficiency()
# Checking the second condition using assertEqual
# The values for arguments is not final and should be considered as placeholders
# More test-cases required for full testing
Expand All @@ -49,13 +47,13 @@ def test_is_criticality_balanced_set4(self):

@pytest.mark.task(taskno=2)
def test_reactor_efficiency_set1(self):

test_return = reactor_efficiency(
voltage=100, current=50, theoretical_max_power=5000)
self.assertEqual(
test_return, 'green', msg=f"Expected green but returned {test_return}"
)


@pytest.mark.task(taskno=2)
def test_reactor_efficiency_set2(self):
test_return = reactor_efficiency(
Expand All @@ -64,6 +62,7 @@ def test_reactor_efficiency_set2(self):
test_return, 'orange', msg=f"Expected orange but returned {test_return}"
)


@pytest.mark.task(taskno=2)
def test_reactor_efficiency_set3(self):
test_return = reactor_efficiency(
Expand All @@ -72,6 +71,7 @@ def test_reactor_efficiency_set3(self):
test_return, 'red', msg=f"Expected red but returned {test_return}"
)


@pytest.mark.task(taskno=2)
def test_reactor_efficiency_set4(self):
test_return = reactor_efficiency(
Expand All @@ -80,10 +80,9 @@ def test_reactor_efficiency_set4(self):
test_return, 'black', msg=f"Expected black but returned {test_return}"
)

# End of second function testing

# End of second function testing

# Test case for fail_safe()
# Test case for fail_safe()
# Checking the third condition using assertEqual
# The values for arguments is not final and should be considered as placeholders
# More test-cases required for full testing
Expand All @@ -98,6 +97,7 @@ def test_fail_safe_set1(self):
test_return, 'LOW', msg=f"Expected LOW but returned {test_return}"
)


@pytest.mark.task(taskno=3)
def test_fail_safe_set2(self):
test_return = fail_safe(
Expand All @@ -106,6 +106,7 @@ def test_fail_safe_set2(self):
test_return, 'LOW', msg=f"Expected LOW but returned {test_return}"
)


@pytest.mark.task(taskno=3)
def test_fail_safe_set3(self):
test_return = fail_safe(
Expand All @@ -114,6 +115,7 @@ def test_fail_safe_set3(self):
test_return, 'LOW', msg=f"Expected LOW but returned {test_return}"
)


@pytest.mark.task(taskno=3)
def test_fail_safe_set4(self):
test_return = fail_safe(
Expand All @@ -122,6 +124,7 @@ def test_fail_safe_set4(self):
test_return, 'NORMAL', msg=f"Expected NORMAL but returned {test_return}"
)


@pytest.mark.task(taskno=3)
def test_fail_safe_set5(self):
test_return = fail_safe(
Expand All @@ -130,6 +133,7 @@ def test_fail_safe_set5(self):
test_return, 'NORMAL', msg=f"Expected NORMAL but returned {test_return}"
)


@pytest.mark.task(taskno=3)
def test_fail_safe_set6(self):
test_return = fail_safe(
Expand All @@ -138,6 +142,7 @@ def test_fail_safe_set6(self):
test_return, 'NORMAL', msg=f"Expected NORMAL but returned {test_return}"
)


@pytest.mark.task(taskno=3)
def test_fail_safe_set7(self):
test_return = fail_safe(
Expand All @@ -146,6 +151,7 @@ def test_fail_safe_set7(self):
test_return, 'DANGER', msg=f"Expected DANGER but returned {test_return}"
)


@pytest.mark.task(taskno=3)
def test_fail_safe_set8(self):
test_return = fail_safe(
Expand All @@ -154,6 +160,7 @@ def test_fail_safe_set8(self):
test_return, 'DANGER', msg=f"Expected DANGER but returned {test_return}"
)


@pytest.mark.task(taskno=3)
def test_fail_safe_set9(self):
test_return = fail_safe(
Expand Down