WEEK 10 March 16th - March 20th
This week I started working on A3 with my partners. We decided to work on option B as we didn't do quite well on minimax. I will do option A myself later on to get practice for the final exam. We started with the function grow and are still struggling with it. We are very very to close in getting it. We almost got it but when we wrote the function node_count we realized we didn't actually what we wanted to accomplish. I am sure we will be able to get it. This week I need to work more hard so as to complete A3 on time. In lectures this week we looked back on A2 and performed unittest on minimax and learned how to choose test cases. I am still confused how to decide about choosing test cases but I think lab09 would give me that practice. I didn't get time to complete lab09 though I have started. I will post my solutions when I am done. We also performed exercises in class to learn about assertion, what I learned of it was we need to assert something that would be true if our function did its right job.
''' (BTNode, object, object) -> list
Return a Python list of all values in the binary search tree
rooted at node that are between start and end (inclusive).
>>> b = BTNode(8)
>>> b = insert(b, 4)
>>> b = insert(b, 2)
>>> b = insert(b, 6)
>>> b = insert(b, 12)
>>> b = insert(b, 14)
>>> b = insert(b, 10)
>>> list_between(None, 0, 15)
[]
>>> list_between(b, 2, 3)
[2]
>>> L = list_between(b, 3, 11)
>>> L.sort()
>>> L
[4, 6, 8, 10]
'''
lst = []
if node is None:
return []
else:
if node.data > start:
lst += list_between(node.left, start, end)
if node.data < end:
lst += list_between(node.right, start, end)
if start <= node.data <= end:
lst += [node.data]
return lst
In the function above we can assert node = BTNode which I got using the docstring. The syntax for assert statement is as follows
assert <<condition>>, <<error string>>
We have the AssertionError(<<error string>>) if the assertion is not true. I hope to learn more about unittest and implement it when doctest testing is not sufficient. I would like to say a little about doctest and unittest before I end. Doctest are really good for testing but we got more accurate and extensive testing with unittest. There are also conditions where doctest is not possible so unittest are of use in those conditions. Hope next week has more interesting stuff to reflect upon.
No comments:
Post a Comment