Skip to content
Snippets Groups Projects
Commit 4b806e1b authored by Morten Hannemose's avatar Morten Hannemose
Browse files

Fixes for week03

parent ff81ad33
No related branches found
No related tags found
No related merge requests found
Showing
with 10 additions and 24 deletions
"""Exercise 3.7: Solar panel."""
def solar_panel(move : bool, swap : bool, hot : bool, empty : bool):
def solar_panel(move : bool, swap : bool, hot : bool, empty : bool) -> str:
"""Print out whether it is a good idea to install solar panels on an object with the given properties.
:param move: does the object move around?
:param swap: does the object allow swapping or recharging battery?
:param hot: is the object hot to the touch when it is running?
:param empty: are there other empty places near the object?
:return: Whether you should put solar panels on the object as a string.
"""
# TODO: Code has been removed from here.
This diff is collapsed.
No preview for this file type
This diff is collapsed.
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -96,38 +96,23 @@ class Week03SolarPanelTests(UTestCase):
def test_maybe(self):
from cp.ex03.solar_panel import solar_panel
with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
solar_panel(True, False, False, False)
out = mock_stdout.getvalue()
self.assertEqual(out.strip().lower(), "maybe")
self.assertEqual(solar_panel(True, False, False, False).strip().lower(), "maybe")
def test_good_luck(self):
from cp.ex03.solar_panel import solar_panel
with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
solar_panel(True, False, True, True)
out = mock_stdout.getvalue()
self.assertEqual(out.strip().lower().splitlines(), ["haha", "good luck"])
self.assertEqual(solar_panel(True, False, True, True).strip().lower()[:4], "haha")
def test_probably_not1(self):
from cp.ex03.solar_panel import solar_panel
with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
solar_panel(True, True, False, False)
out = mock_stdout.getvalue()
self.assertEqual(out.strip().lower(), "probably not")
self.assertEqual(solar_panel(True, True, False, False).strip().lower(), "probably not")
def test_probably_not2(self):
from cp.ex03.solar_panel import solar_panel
with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
solar_panel(False, False, True, True)
out = mock_stdout.getvalue()
self.assertEqual(out.strip().lower(), "probably not")
self.assertEqual(solar_panel(False, False, True, True).strip().lower(), "probably not")
def test_sure(self):
from cp.ex03.solar_panel import solar_panel
with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
solar_panel(False, False, False, False)
out = mock_stdout.getvalue()
self.assertEqual(out.strip().lower(), "sure")
self.assertEqual(solar_panel(False, False, False, False).strip().lower(), "sure")
class Week03TheFunctionToBisect(UTestCase):
......@@ -173,7 +158,7 @@ class Week03Bisect(UTestCase):
class Week03Tests(Report):
title = "Tests for week 03"
# version = 1.0
# version = 1.1
# url = "https://gitlab.compute.dtu.dk/cp/02002students/-/blob/master/cp/tests"
pack_imports = [cp]
individual_imports = []
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment