<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?action=history&amp;feed=atom&amp;title=Beginning_unit_test</id>
	<title>Beginning unit test - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?action=history&amp;feed=atom&amp;title=Beginning_unit_test"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;action=history"/>
	<updated>2026-07-03T00:25:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=309&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=309&amp;oldid=prev"/>
		<updated>2026-04-14T16:37:28Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:37, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l36&quot;&gt;Line 36:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 36:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Use your &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from exercise 3 in [[Functions, namespace, memory management]]. If you did not do so already, change it to use exceptions instead of &amp;#039;&amp;#039;&amp;#039;sys.exit()&amp;#039;&amp;#039;&amp;#039;, when an error occurs. Now make simple unit tests for the following test cases: a list of positive numbers, a list of negative numbers, a list of integers, a list of mixed floats and integers, a single number in the list, empty list, a list with at least one non-number (string, list, set), a set containing numbers, and a dict where the keys are numbers. Get other ideas if you can. The &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function and all test functions must be in one single file (&amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;), which you can run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; on.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Use your &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from exercise 3 in [[Functions, namespace, memory management]]. If you did not do so already, change it to use exceptions instead of &amp;#039;&amp;#039;&amp;#039;sys.exit()&amp;#039;&amp;#039;&amp;#039;, when an error occurs. Now make simple unit tests for the following test cases: a list of positive numbers, a list of negative numbers, a list of integers, a list of mixed floats and integers, a single number in the list, empty list, a list with at least one non-number (string, list, set), a set containing numbers, and a dict where the keys are numbers. Get other ideas if you can. The &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function and all test functions must be in one single file (&amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;), which you can run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; on.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &#039;&#039;unittest&#039;&#039;. I would put my &#039;&#039;normalize.py&#039;&#039; in &#039;&#039;unittest/src&#039;&#039; and &#039;&#039;normalize_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive for how the search path works. Try to run the test from a different folder, like &quot;pytest test/normalize_test.py&quot; to see how vulnerable just using the path is.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &#039;&#039;unittest&#039;&#039;. I would put my &#039;&#039;normalize.py&#039;&#039; in &#039;&#039;unittest/src&#039;&#039; and &#039;&#039;normalize_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive for how the search path works. Try to run the test from a different folder &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(unittest)&lt;/ins&gt;, like &quot;pytest test/normalize_test.py&quot; to see how vulnerable just using the path is.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class also contains the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; method. Make unit tests for that method in the file &amp;#039;&amp;#039;unittest/test/MyMath_supply_test.py&amp;#039;&amp;#039;. Make the &amp;quot;usual&amp;quot; tests, which are the same as you did in the first exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class also contains the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; method. Make unit tests for that method in the file &amp;#039;&amp;#039;unittest/test/MyMath_supply_test.py&amp;#039;&amp;#039;. Make the &amp;quot;usual&amp;quot; tests, which are the same as you did in the first exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=308&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=308&amp;oldid=prev"/>
		<updated>2026-04-14T16:36:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:36, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l36&quot;&gt;Line 36:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 36:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Use your &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from exercise 3 in [[Functions, namespace, memory management]]. If you did not do so already, change it to use exceptions instead of &amp;#039;&amp;#039;&amp;#039;sys.exit()&amp;#039;&amp;#039;&amp;#039;, when an error occurs. Now make simple unit tests for the following test cases: a list of positive numbers, a list of negative numbers, a list of integers, a list of mixed floats and integers, a single number in the list, empty list, a list with at least one non-number (string, list, set), a set containing numbers, and a dict where the keys are numbers. Get other ideas if you can. The &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function and all test functions must be in one single file (&amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;), which you can run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; on.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Use your &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from exercise 3 in [[Functions, namespace, memory management]]. If you did not do so already, change it to use exceptions instead of &amp;#039;&amp;#039;&amp;#039;sys.exit()&amp;#039;&amp;#039;&amp;#039;, when an error occurs. Now make simple unit tests for the following test cases: a list of positive numbers, a list of negative numbers, a list of integers, a list of mixed floats and integers, a single number in the list, empty list, a list with at least one non-number (string, list, set), a set containing numbers, and a dict where the keys are numbers. Get other ideas if you can. The &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function and all test functions must be in one single file (&amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;), which you can run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; on.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &#039;&#039;unittest&#039;&#039;. I would put my &#039;&#039;normalize.py&#039;&#039; in &#039;&#039;unittest/src&#039;&#039; and &#039;&#039;normalize_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &#039;&#039;unittest&#039;&#039;. I would put my &#039;&#039;normalize.py&#039;&#039; in &#039;&#039;unittest/src&#039;&#039; and &#039;&#039;normalize_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;for how the search path works. Try to run the test from a different folder, like &quot;pytest test/normalize_test.py&quot; to see how vulnerable just using the path is&lt;/ins&gt;.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class also contains the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; method. Make unit tests for that method in the file &amp;#039;&amp;#039;unittest/test/MyMath_supply_test.py&amp;#039;&amp;#039;. Make the &amp;quot;usual&amp;quot; tests, which are the same as you did in the first exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class also contains the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; method. Make unit tests for that method in the file &amp;#039;&amp;#039;unittest/test/MyMath_supply_test.py&amp;#039;&amp;#039;. Make the &amp;quot;usual&amp;quot; tests, which are the same as you did in the first exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=307&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=307&amp;oldid=prev"/>
		<updated>2026-04-14T14:54:42Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:54, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l39&quot;&gt;Line 39:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 39:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class also contains the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; method. Make unit tests for that method in the file &amp;#039;&amp;#039;unittest/test/MyMath_supply_test.py&amp;#039;&amp;#039;. Make the &amp;quot;usual&amp;quot; tests, which are the same as you did in the first exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class also contains the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; method. Make unit tests for that method in the file &amp;#039;&amp;#039;unittest/test/MyMath_supply_test.py&amp;#039;&amp;#039;. Make the &amp;quot;usual&amp;quot; tests, which are the same as you did in the first exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make unit tests for the &#039;&#039;average&#039;&#039; method in &#039;&#039;&#039;MyMath&#039;&#039;&#039;. &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Use &lt;/del&gt;the file &#039;&#039;unittest/test/MyMath_average_test.py&#039;&#039;. Notice how that interacts with the &#039;&#039;supply&#039;&#039; unit tests because &#039;&#039;average&#039;&#039; depends on correct working of &#039;&#039;supply&#039;&#039;. Sometimes you won&#039;t even find the flaw in one method before you test another that depends on it.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make unit tests for the &#039;&#039;average&#039;&#039; method in &#039;&#039;&#039;MyMath&#039;&#039;&#039;. &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Make the tests in &lt;/ins&gt;the file &#039;&#039;unittest/test/MyMath_average_test.py&#039;&#039;. Notice how that interacts with the &#039;&#039;supply&#039;&#039; unit tests because &#039;&#039;average&#039;&#039; depends on correct working of &#039;&#039;supply&#039;&#039;. Sometimes you won&#039;t even find the flaw in one method before you test another that depends on it&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. I am not going to tell you this time what unit tests you should make. You should know by now&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=306&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=306&amp;oldid=prev"/>
		<updated>2026-04-14T14:52:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:52, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l39&quot;&gt;Line 39:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 39:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class also contains the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; method. Make unit tests for that method in the file &amp;#039;&amp;#039;unittest/test/MyMath_supply_test.py&amp;#039;&amp;#039;. Make the &amp;quot;usual&amp;quot; tests, which are the same as you did in the first exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class also contains the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; method. Make unit tests for that method in the file &amp;#039;&amp;#039;unittest/test/MyMath_supply_test.py&amp;#039;&amp;#039;. Make the &amp;quot;usual&amp;quot; tests, which are the same as you did in the first exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make unit tests for the &#039;&#039;average&#039;&#039; method in &#039;&#039;MyMath&#039;&#039;. Use the file &#039;&#039;unittest/test/MyMath_average_test.py&#039;&#039;. Notice how that interacts with the &#039;&#039;supply&#039;&#039; unit tests because &#039;&#039;average&#039;&#039; depends on correct working of &#039;&#039;supply&#039;&#039;. Sometimes you won&#039;t even find the flaw in one method before you test another &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;dependency&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make unit tests for the &#039;&#039;average&#039;&#039; method in &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&lt;/ins&gt;&#039;&#039;MyMath&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&lt;/ins&gt;&#039;&#039;. Use the file &#039;&#039;unittest/test/MyMath_average_test.py&#039;&#039;. Notice how that interacts with the &#039;&#039;supply&#039;&#039; unit tests because &#039;&#039;average&#039;&#039; depends on correct working of &#039;&#039;supply&#039;&#039;. Sometimes you won&#039;t even find the flaw in one method before you test another &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;that depends on it&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=305&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=305&amp;oldid=prev"/>
		<updated>2026-04-14T14:50:46Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:50, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l37&quot;&gt;Line 37:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 37:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &#039;&#039;&#039;MyMath&#039;&#039;&#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &#039;&#039;classes&#039;&#039; in your &#039;&#039;unittest/src&#039;&#039; folder and put the &#039;&#039;MyMath&#039;&#039; class in a file &#039;&#039;MyMath.py&#039;&#039; in &#039;&#039;unittest/src/classes&#039;&#039;. Now make a unit test file &#039;&#039;MyMath_factorial_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &quot;3&quot;, &quot;3.1.&quot;, &quot;ABC&quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &#039;&#039;&#039;MyMath&#039;&#039;&#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &#039;&#039;classes&#039;&#039; in your &#039;&#039;unittest/src&#039;&#039; folder and put the &#039;&#039;MyMath&#039;&#039; class in a file &#039;&#039;MyMath.py&#039;&#039; in &#039;&#039;unittest/src/classes&#039;&#039;. Now make a unit test file &#039;&#039;MyMath_factorial_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &quot;3&quot;, &quot;3.1.&quot;, &quot;ABC&quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &#039;&#039;MyMath&#039;&#039; class also contains the &#039;&#039;supply&#039;&#039; method. Make unit tests for that method in the file &#039;&#039;unittest/test/MyMath_supply_test.py&#039;&#039;. Make the &quot;usual&quot; tests, which are the same as you did in the first exercise.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &#039;&#039;MyMath&#039;&#039; class also contains the &#039;&#039;supply&#039;&#039; method. Make unit tests for that method in the file &#039;&#039;unittest/test/MyMath_supply_test.py&#039;&#039;. Make the &quot;usual&quot; tests, which are the same as you did in the first exercise.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make unit tests for the &amp;#039;&amp;#039;average&amp;#039;&amp;#039; method in &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;. Use the file &amp;#039;&amp;#039;unittest/test/MyMath_average_test.py&amp;#039;&amp;#039;. Notice how that interacts with the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; unit tests because &amp;#039;&amp;#039;average&amp;#039;&amp;#039; depends on correct working of &amp;#039;&amp;#039;supply&amp;#039;&amp;#039;. Sometimes you won&amp;#039;t even find the flaw in one method before you test another dependency.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now make unit tests for the &amp;#039;&amp;#039;average&amp;#039;&amp;#039; method in &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;. Use the file &amp;#039;&amp;#039;unittest/test/MyMath_average_test.py&amp;#039;&amp;#039;. Notice how that interacts with the &amp;#039;&amp;#039;supply&amp;#039;&amp;#039; unit tests because &amp;#039;&amp;#039;average&amp;#039;&amp;#039; depends on correct working of &amp;#039;&amp;#039;supply&amp;#039;&amp;#039;. Sometimes you won&amp;#039;t even find the flaw in one method before you test another dependency.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=304&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=304&amp;oldid=prev"/>
		<updated>2026-04-14T14:50:20Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:50, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l38&quot;&gt;Line 38:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 38:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &amp;#039;&amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039;&amp;#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &amp;#039;&amp;#039;classes&amp;#039;&amp;#039; in your &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; folder and put the &amp;#039;&amp;#039;MyMath&amp;#039;&amp;#039; class in a file &amp;#039;&amp;#039;MyMath.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src/classes&amp;#039;&amp;#039;. Now make a unit test file &amp;#039;&amp;#039;MyMath_factorial_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &amp;quot;3&amp;quot;, &amp;quot;3.1.&amp;quot;, &amp;quot;ABC&amp;quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;# &#039;&#039;MyMath&#039;&#039; class also contains the &#039;&#039;supply&#039;&#039; method. Make unit tests for that method in the file &#039;&#039;unittest/test/MyMath_supply_test.py&#039;&#039;. Make the &quot;usual&quot; tests, which are the same as you did in the first exercise.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;# Now make unit tests for the &#039;&#039;average&#039;&#039; method in &#039;&#039;MyMath&#039;&#039;. Use the file &#039;&#039;unittest/test/MyMath_average_test.py&#039;&#039;. Notice how that interacts with the &#039;&#039;supply&#039;&#039; unit tests because &#039;&#039;average&#039;&#039; depends on correct working of &#039;&#039;supply&#039;&#039;. Sometimes you won&#039;t even find the flaw in one method before you test another dependency.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=303&amp;oldid=prev</id>
		<title>WikiSysop: /* Installation of pytest */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=303&amp;oldid=prev"/>
		<updated>2026-04-14T14:39:24Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Installation of pytest&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:39, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l20&quot;&gt;Line 20:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 20:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  which yptest&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  which yptest&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To install pytest, you need to be root/administrator.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To install pytest, you need to be root/administrator.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; # An install on a basic system&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  pip install -U pytest&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  pip install -U pytest&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  # or maybe (depending on your system)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  # or maybe (depending on your system)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  sudo pip install -U pytest&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  sudo pip install -U pytest&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; # Using ubuntu, which is also WSL in this situation, there is a package&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; apt install python3-pytest&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Subjects covered ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Subjects covered ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=301&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises for extra practice */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=301&amp;oldid=prev"/>
		<updated>2026-04-14T14:35:31Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises for extra practice&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:35, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l37&quot;&gt;Line 37:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 37:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;# Add unit tests for all methods in your &#039;&#039;&#039;fasta&#039;&#039;&#039; class. That will be a bit of work.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=300&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=300&amp;oldid=prev"/>
		<updated>2026-04-14T14:32:23Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:32, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l34&quot;&gt;Line 34:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 34:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &#039;&#039;&#039;MyMath&#039;&#039;&#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &#039;&#039;classes&#039;&#039; in your &#039;&#039;unittest/src&#039;&#039; folder and put the &#039;&#039;MyMath&#039;&#039; class in a file &#039;&#039;MyMath.py&#039;&#039; in &#039;unittest/src/classes&#039;&#039;. Now make a unit test file &#039;&#039;MyMath_factorial_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &quot;3&quot;, &quot;3.1.&quot;, &quot;ABC&quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &#039;&#039;&#039;MyMath&#039;&#039;&#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &#039;&#039;classes&#039;&#039; in your &#039;&#039;unittest/src&#039;&#039; folder and put the &#039;&#039;MyMath&#039;&#039; class in a file &#039;&#039;MyMath.py&#039;&#039; in &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&lt;/ins&gt;&#039;unittest/src/classes&#039;&#039;. Now make a unit test file &#039;&#039;MyMath_factorial_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039; that - surprise - tests your factorial method. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &quot;3&quot;, &quot;3.1.&quot;, &quot;ABC&quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for all methods in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class. That will be a bit of work.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for all methods in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class. That will be a bit of work.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=299&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Beginning_unit_test&amp;diff=299&amp;oldid=prev"/>
		<updated>2026-04-14T14:32:02Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:32, 14 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l34&quot;&gt;Line 34:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 34:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Now remove the &amp;#039;&amp;#039;&amp;#039;normalize&amp;#039;&amp;#039;&amp;#039; function from &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; and put it in its own file &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039;. Import it from the &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; like &amp;#039;&amp;#039;&amp;#039;from normalize import normalize&amp;#039;&amp;#039;&amp;#039;. The first &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of the .py file, the second &amp;#039;&amp;#039;normalize&amp;#039;&amp;#039; is the name of your normalize function. Just run &amp;#039;&amp;#039;pytest&amp;#039;&amp;#039; (no file name) in the folder to check it works. It is more normal to have test and function separated.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Above we removed test code from function code by creating two files. Next, put the files in their own folder in &amp;#039;&amp;#039;unittest&amp;#039;&amp;#039;. I would put my &amp;#039;&amp;#039;normalize.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/src&amp;#039;&amp;#039; and &amp;#039;&amp;#039;normalize_test.py&amp;#039;&amp;#039; in &amp;#039;&amp;#039;unittest/test&amp;#039;&amp;#039;. This way there is a very clear separation between function and test. The problem is making sure the test code loads the function code. Do it wrong a couple of times - it is very instructive.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &#039;&#039;&#039;MyMath&#039;&#039;&#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &#039;&#039;classes&#039; in your &#039;&#039;unittest/src&#039;&#039; folder and put the &#039;&#039;MyMath&#039;&#039; class in a file &#039;&#039;MyMath.py&#039;&#039; in &#039;unittest/src/classes&#039;&#039;. Now make a unit test file &#039;&#039;MyMath_factorial_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039; that - surprise - tests your factorial method.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# You hopefully remember the &#039;&#039;&#039;MyMath&#039;&#039;&#039; class you made in exercise 1 &amp;amp; 2 in [[Beginning classes]]. Make a folder &#039;&#039;classes&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&lt;/ins&gt;&#039; in your &#039;&#039;unittest/src&#039;&#039; folder and put the &#039;&#039;MyMath&#039;&#039; class in a file &#039;&#039;MyMath.py&#039;&#039; in &#039;unittest/src/classes&#039;&#039;. Now make a unit test file &#039;&#039;MyMath_factorial_test.py&#039;&#039; in &#039;&#039;unittest/test&#039;&#039; that - surprise - tests your factorial method&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Test it with at least these input: 12, 2, 1, 0, -1, 3.0, 3.4, &quot;3&quot;, &quot;3.1.&quot;, &quot;ABC&quot;. Parametrize at least the tests that should succeed. Bonus for parametrizing the exceptions&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for all methods in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class. That will be a bit of work.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Add unit tests for all methods in your &amp;#039;&amp;#039;&amp;#039;fasta&amp;#039;&amp;#039;&amp;#039; class. That will be a bit of work.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>