File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Kangaroo :
2
+
3
+ def __init__ (self , name , pouch_contents = None ):
4
+ # __init__ runs, it checks the value of contents and,
5
+ # if necessary, creates a new empty list. That way,
6
+ # every Kangaroo that gets the default value gets a
7
+ # reference to a different list.
8
+
9
+ self .name = name
10
+
11
+ if pouch_contents is None :
12
+ pouch_contents = []
13
+ self .pouch_contents = pouch_contents
14
+
15
+ def put_in_pouch (self , obj ):
16
+ self .pouch_contents .append (obj )
17
+
18
+ def __str__ (self ):
19
+ t = [self .name + ' has pouch contents:' ]
20
+ for thing in self .pouch_contents :
21
+ s = ' ' + object .__str__ (thing )
22
+ t .append (s )
23
+ return '\n ' .join (t )
Original file line number Diff line number Diff line change
1
+ import unittest
2
+ from src .kangaroo import Kangaroo
3
+
4
+
5
+ class TestKangaroo (unittest .TestCase ):
6
+ def test_initialization (self ):
7
+ kangaroo = Kangaroo ("kangaroo" )
8
+ self .assertEqual (kangaroo .pouch_contents , [])
9
+
10
+ def test_kangaroo_str (self ):
11
+ kangaroo = Kangaroo ("kangaroo" )
12
+ kangaroo .put_in_pouch ("hello" )
13
+ kangaroo .put_in_pouch ("world" )
6DB1
14
+ print (kangaroo )
15
+
16
+ def test_put_in_pouch (self ):
17
+ kanga = Kangaroo ("kanga" )
18
+ roo = Kangaroo ("roo" )
19
+ kanga .put_in_pouch (roo )
20
+ print (kanga )
21
+
22
+
23
+ if __name__ == '__main__' :
24
+ unittest .main ()
You can’t perform that action at this time.
0 commit comments