File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 1717A Clicker is an object for recording changes of state in other objects. The main
1818functions are 'click' and '__cmp__', which changes the counter of a Clicker and
1919compares its counter to that of other Clickers, respectively. The idea is to
20- click a clicker whenever the state that it monitor changes. That clicker can
20+ click a clicker whenever the state that it monitors changes. That clicker can
2121then be compared to other clickers that are used to monitor other objects.
2222
2323Clickers of the same type share a global counter that records the total number
@@ -66,6 +66,7 @@ def __init__(self):
6666 def addObserver (self , other ):
6767 """Add a Clicker that observes this one."""
6868 self ._observers .add (other )
69+ self .update ()
6970 return
7071
7172 def addSubject (self , other ):
@@ -107,7 +108,11 @@ def click(self):
107108 return
108109
109110 def update (self ):
110- """Update the observers."""
111+ """Update the local state and that of the observers.
112+
113+ This sets the local state to the global state and updates all
114+ observers.
115+ """
111116 self ._state = self .__class__ ._numclicks
112117 for clicker in self ._observers :
113118 clicker .update ()
Original file line number Diff line number Diff line change @@ -42,13 +42,13 @@ def testClicker(self):
4242 self .assertFalse ( c1 >= c2 )
4343 self .assertFalse ( c2 <= c1 )
4444
45- # Observe these two. Note that this does not change the state of the
46- # observer or the subjects .
45+ # Observe these two. Note that this sets the state of the subject and
46+ # all observers equal to the global state .
4747 observer .addSubject (c1 )
4848 observer .addSubject (c2 )
49- self .assertTrue ( observer < c1 )
50- self .assertTrue ( observer < c2 )
51- self .assertTrue ( c2 > c1 )
49+ self .assertTrue ( observer == c1 )
50+ self .assertTrue ( observer == c2 )
51+ self .assertTrue ( c2 == c1 )
5252
5353 # Check relations
5454 self .assertTrue ( c1 .hasObserver (observer ) )
You can’t perform that action at this time.
0 commit comments