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

Added week02

parent 2d2e037a
No related branches found
No related tags found
No related merge requests found
Showing
with 320 additions and 6 deletions
......@@ -13,18 +13,22 @@ cache.db
**/unitgrade_data/dont_check_remote.lock
######################## Comment these out upon release. #############################
cp/ex03
cp/ex04
cp/ex05
cp/ex06
cp/ex07
cp/ex08
#cp/ex09
#cp/ex10
cp/ex09
cp/ex10
cp/ex11
cp/ex12
cp/ex13
cp/exam
cp/project1
# cp/project2
#cp/project1
cp/project2
cp/project3
cp/project4
#cp/project5
cp/project5
cp/project6
cp/tests/tests_week01.py
"""This package represents exercise 1."""
"""Exercise 2.1: Printing full name."""
def full_name(first_name:str, last_name:str):
"""Determine and print the full name given first name and last name.
:param first_name: your first name.
:param last_name: your last name.
"""
# TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.")
"""Exercise: Estimate fetal weight using Hadlock formula."""
import math
def hadlock(head_circ:float,abdominal_circ:float,femur_length:float):
"""Estimate fetal weight using Hadlock formula.
:param head_circ: head circumference in cm.
:param abdominal_circ: abdominal circumference in cm.
:param femur_length: femur length in cm.
"""
# TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.")
"""Exercise 2.3: Printing number of characters in name."""
def name_length(name:str):
"""Calculate and print the number of characters in name.
:param name: your name.
"""
# TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.")
"""Exercise 2.2: Round a number to the next nearest thousand."""
import math
def next_thousand(a:int):
"""Round a number to the next nearest thousand and print.
:param a: the number to be rounded.
"""
# TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.")
"""Exercise 2.5: Calculate the normal weight range for a given height."""
import math
def normal_weight(height:float):
"""Calculate and print the range of normal weights for a given height.
:param height: the height.
"""
# TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.")
"""Exercise 2.6: Calculate the lowest survival temperature."""
def survival_temperature(metabolic_heat:int, thermal_conductance:float):
"""Calculate and print the lowest survival temperature.
:param metabolic_heat: the metabolic heat production.
:param thermal_conductance: the thermal conductance.
"""
# TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.")
"""Exercise: Convert length in foot and inch to centimeter."""
import math
def unit_conversion(foot:int, inch:int):
"""Convert length in foot and inch to centimeter.
:param foot: foot portion of the length in imperical unit.
:param inch: inch portion of the length in imperical unit.
"""
# TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.")
"""Exercise 2.4: Wind chill."""
def wind_chill(temperature:int, windspeed:float):
"""Calculate and print the wind chill temperatures.
:param temperature: the actual temperature.
:param windspeed: the wind speed.
"""
# TODO: Code has been removed from here.
raise NotImplementedError("Insert your solution and remove this error.")
This diff is collapsed.
No preview for this file type
"""Lindenmayer system project."""
This diff is collapsed.
import string
from unitgrade import hide
from cp import minput
from unittest.mock import patch
import io
import unittest
from unitgrade import UTestCase, Report
import math
class TestNormalWeight(UTestCase):
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_normal_weight_01(self, mock_stdout):
from cp.ex02.normal_weight import normal_weight
normal_weight(1.47)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Normal weight is between 40 and 54 kg.")
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_normal_weight_02(self, mock_stdout):
from cp.ex02.normal_weight import normal_weight
normal_weight(1.96)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Normal weight is between 72 and 96 kg.")
class TestSurvivalTemperature(UTestCase):
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_survival_temperature_01(self, mock_stdout):
from cp.ex02.survival_temperature import survival_temperature
survival_temperature(186,0.15)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Survival temperature is -5.0 degrees.")
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_survival_temperature_02(self, mock_stdout):
from cp.ex02.survival_temperature import survival_temperature
survival_temperature(356,0.33)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Survival temperature is -7.0 degrees.")
class TestUnitConversion(UTestCase):
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_unit_conversion_01(self, mock_stdout):
from cp.ex02.unit_conversion import unit_conversion
unit_conversion(4, 3)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "4 ft 3 in is equal to 130 cm.")
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_unit_conversion_02(self, mock_stdout):
from cp.ex02.unit_conversion import unit_conversion
unit_conversion(7, 2)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "7 ft 2 in is equal to 218 cm.")
class TestHadlock(UTestCase):
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_hadlock_01(self, mock_stdout):
from cp.ex02.hadlock import hadlock
hadlock(35, 36, 12)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "The estimated fetal weight is 5820.8 g.")
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_hadlock_02(self, mock_stdout):
from cp.ex02.hadlock import hadlock
hadlock(28.6, 29.6, 6.3)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "The estimated fetal weight is 2070.0 g.")
class Project1(Report):
title = "Project 1"
remote_url = "https://cp.pages.compute.dtu.dk/02002public/_static/evaluation/"
abbreviate_questions = True
questions = [
(TestNormalWeight, 25),
(TestSurvivalTemperature, 25),
(TestUnitConversion, 25),
(TestHadlock, 25),
]
import cp
pack_imports = [cp]
if __name__ == "__main__":
from unitgrade import evaluate_report_student
evaluate_report_student(Project1())
File added
File added
File added
File added
import io
import unittest.mock
from unitgrade import Report
import cp
from unitgrade import UTestCase
class Week02FullName(UTestCase):
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_full_name(self, mock_stdout):
from cp.ex02.full_name import full_name
full_name('Donald', 'Duck')
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Donald Duck")
class Week02NextThousand(UTestCase):
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_next_thousand_01(self, mock_stdout):
from cp.ex02.next_thousand import next_thousand
next_thousand(123998)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "124000")
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_next_thousand_02(self, mock_stdout):
from cp.ex02.next_thousand import next_thousand
next_thousand(-123998)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "-123000")
class Week02NameLength(UTestCase):
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_name_length(self, mock_stdout):
from cp.ex02.name_length import name_length
name_length('Anita')
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Your name consists of 5 characters.")
class Week02WindChill(UTestCase):
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_wind_chill_01(self, mock_stdout):
from cp.ex02.wind_chill import wind_chill
wind_chill(8, 12.8)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Temperature: 8 degrees feels like 6 degrees.")
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_wind_chill_02(self, mock_stdout):
from cp.ex02.wind_chill import wind_chill
wind_chill(8, 25.8)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Temperature: 8 degrees feels like 4 degrees.")
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_wind_chill_03(self, mock_stdout):
from cp.ex02.wind_chill import wind_chill
wind_chill(-2, 12.8)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Temperature: -2 degrees feels like -6 degrees.")
class Week02NormalWeight(UTestCase):
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_normal_weight(self, mock_stdout):
from cp.ex02.normal_weight import normal_weight
normal_weight(1.73)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Normal weight is between 56 and 74 kg.")
class Week02SurvivalTemperature(UTestCase):
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_survival_temperature(self, mock_stdout):
from cp.ex02.survival_temperature import survival_temperature
survival_temperature(200, 0.1)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "Survival temperature is -27.5 degrees.")
class Week02UnitConversion(UTestCase):
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_unit_conversion(self, mock_stdout):
from cp.ex02.unit_conversion import unit_conversion
unit_conversion(7, 5)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "7 ft 5 in is equal to 226 cm.")
class Week02Hadlock(UTestCase):
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)
def test_hadlock(self, mock_stdout):
from cp.ex02.hadlock import hadlock
hadlock(31.1, 30.2, 8.3)
out = mock_stdout.getvalue()
self.assertEqual(out.strip(), "The estimated fetal weight is 2990.7 g.")
class Week02Tests(Report): #240 total.
title = "Tests for week 02"
pack_imports = [cp]
individual_imports = []
questions = [
(Week02FullName, 10),
(Week02NextThousand, 10),
(Week02NameLength, 10),
(Week02WindChill, 10),
(Week02NormalWeight, 10),
(Week02SurvivalTemperature, 10),
(Week02UnitConversion, 10),
(Week02Hadlock, 10),
]
if __name__ == '__main__':
from unitgrade import evaluate_report_student
evaluate_report_student(Week02Tests())
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