We only covered one topic this week: unit testing. Being a mathematics specialist, I am more interested in the science part of of computer science (like data structure and algorithms), not developing, so I did not pay much attention to unit testing. Despite this fact, as a student who used to take class in programming (in particular csc108), and who is currently using python to implements his projects in other sciences, I am aware of the significance of testing.
It is fairly common that a piece of wrong code passes doc test. In this case, unit testing can be very useful in determining the correctness of the code as well as identifying the bug, especially when we have good test cases. And by good test cases I mean the ones where wrong codes are very unlikely to pass the tests. In practice, we use the method assert to implement unit testing. Method assert takes on two arguments: a boolean value which is usually used to tell us wether the function being tested gives us what we want, and a string that gives us an description of the error when the boolean value is False. Assert can also be useful in many other cases. For example, we can put assert in critical points in a function body to see if the function is correct up to this point, and if the code is wrong, it is easier to identify the bug because we now have more information about it from assert method.
Realizing that the length of this slog is relatively short and that we have a prescribed topic for slog week 11, I also include some of my thoughts about the material taught in week 11: algorithm complexity and big-oh notation.
In class, we compare the performance of various sorting algorithms over a list of integers of given sizes. In particular, we analyzed the run time of these algorithm as a function of the size of the list being sorted (denote as n). For example, merge sort first divide the list in a binary manner, which takes approximately log(n) times, and for each level of division, the sorting process takes exactly n run times. As a result, merge sort takes approximately nlog(n) run times to sort a list of integer with size n. We did not actually give a definition of big-oh notation. In mathematics, big-oh describes the behaviour of a function when its argument tends to a particular value. In computer science, this value is usually infinity, meaning that big-oh describes the approximate run time of an algorithm when the input size is very large!
No comments:
Post a Comment