Monday, February 23, 2015

Week 6 Summary of Object-Oriented Programming concepts

For last week, a new method Tree had been lead into our world of knowledge. Also the tracking recursive functions help us a lot in coding. Mr. Heap said we have learnt all the knowledge we need in assignment 2, there is a bit regret that our team just missed 3 docstring in the last 3 functions which made TA took away 2.5 points in our total marks. However it`s good enough for me and our team will try our best in assignment 2 to get a full mark.

Summary of Object-Oriented Programming concepts

After the learning of chapter 1, as the name indicates that the object-Oriented Programming working around the objects but not the functional action. 
I`ve found some interesting graph on this website:
(www.ldodds.com/lectures/intro2java/OOP_Terms.doc)

Saturday, February 7, 2015

Week 5

Week 5
This week I did not learn so much because of the first term test was hold on Wednesday night. I took the early course which taught by Mrs. Diane but not Mr. Heap because I had to take MAT137 test that night. Mrs. Diane told us about the unit test, which we`ve learned in CSC108. She show us an example of insert_after (L, n1, n2) and run it in unit test. The function was like this:
def insert_after(L, n1, n2):
    """
    (list, int, int) -> NoneType
    
    After each occurrence of n1 in L, insert n2.
    
    >>> L = [5, 1, 2, 1, 6]
    >>> insert_after(L, 1, 99)
    >>> L
    [5, 1, 99, 2, 1, 99, 6]
    """
    
    i = 0
    while i < len(L):
        if L[i] == n1:
            L.insert(i+1, n2)
            i += 1
        i += 1

if __name__ == "__main__":
    import doctest
    doctest.testmod()

The unit test is this:
import unittest
from insert import insert_after

# Note: this test suite does not contain a complete set of test cases.
# Challenge: Extend it to the point that either you are convinced the
# function works as advertised in the docstring, or you have demonstrated
# that it doesn't.

class TestInsertAfter(unittest.TestCase):

    def test_insert_after_at_front(self):
        """ Test insert_after with one occurrence of n1 in L, at the front."""

        input_list = [0, 1, 2, 3]
        return_value = insert_after(input_list, 0, 99)
        expected = [0, 99, 1, 2, 3]
        self.assertEqual(input_list, expected)    
        self.assertEqual(return_value, None)
        
    def test_insert_after_at_back(self):
        """ Test insert_after with one occurrence of n1 in L, at the back."""

        input_list = [0, 1, 2, 3]
        return_value = insert_after(input_list, 3, 99)
        expected = [0, 1, 2, 3, 99]
        self.assertEqual(input_list, expected)    
        self.assertEqual(return_value, None)
        
    def test_insert_after_middle(self):
        """ Test insert_after with one occurrence of n1 in L, not on 
        either end."""

        input_list = [0, 1, 2, 3]
        return_value = insert_after(input_list, 1, 99)
        expected = [0, 1, 99, 2, 3]
        self.assertEqual(input_list, expected)    
        self.assertEqual(return_value, None)
        
if __name__ == '__main__':
    unittest.main(exit=False)

Unit test is not hard enough but it was always the necessary one in function testing. Wish I can get a good mark in test.