Tuesday, March 24, 2015

Week10: impressions of this week



In this week’s lecture, we looked back at our a2 and learned the assertion in unittest. In a2, I have learned how to deep copy a list. One of the advantages of deep–copy is that it can avoid the original list's being mutated, which may cause ugly circumstances. For example, we need to find several possible game states based on the original one. Once we get one possible game state with the original one being mutated, we can never find other possibilities using the right game state. In this case, deep-copy helps a lot. There is an easy example:
L1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
L3 = [[item for item in r] for r in L1]
Now we check the id of both L1 and L3. They have different id addresses in spite of the fact that they have the same elements. Sadly, I was unable to figure out the way to deep copy when doing a2. So this approach gives me a new idea about how to think and solve the problem. To practice it, I apply this deep copy in my a2 and this solves many problems that I couldn’t figure out at that time.

Another new thing I learned this week is assertion. We covered this stuff in testing minimax.
It is written in the form of this:
 assert <condition> , <error_string>
---> if not condition: raise AssertionError(error_string)
From slides, assertion can be used to state two things:
•what we know is true (assuming our reasoning is correct) at a crucial point in the code.
•what we assume is true at the start of a function or method
Since I haven’t got enough exercise about unittest before, I feel confused about assertion. So I reviewed the slides and worksheet after class. This helps me to some extent to get a clearer understanding of assertion. But I think knowledge about test still confuses me. I hope I can practice it more in the next week.

No comments:

Post a Comment