예제 #1
0
    def test_update_crossing_max_at_1st_step(self, duration1, duration2):
        # next_elapsed > max(duration1, duration2)
        global rec

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        rec = []
        node.do(composite)
        elapsed = 0.0
        next_elapsed = max(duration1, duration2) * 1.1  # above max
        dt = next_elapsed - elapsed
        node._step(dt)

        recx = [e for e in rec if e[1] != 'step']
        rec = [e for e in recx if e[0] == name1]
        print('rec', rec)
        assert rec[0][1] == 'start'
        assert rec[1][1] == 'update' and rec[1][2] == 1.0
        assert rec[2][1] == 'stop'
        assert len(rec) == 3

        rec = [e for e in recx if e[0] == name2]
        print('rec:', rec)
        assert rec[0][1] == 'start'
        assert rec[1][1] == 'update' and rec[1][2] == 1.0
        assert rec[2][1] == 'stop'
        assert len(rec) == 3
예제 #2
0
    def test_step_setting_done1_done2(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)
        a_copy = node.do(composite)
        dt = 0.1
        rec = []
        next_done = 3
        node._step(dt)
        print(rec)

        recx = [e for e in rec if e[0] == name1]
        assert recx[0][1] == 'step'
        assert recx[1][1] == 'stop'
        assert len(recx) == 2

        recx = [e for e in rec if e[0] == name2]
        assert recx[0][1] == 'step'
        assert recx[1][1] == 'stop'
        assert len(recx) == 2

        assert a_copy.done()
        rec = []
        node._step(dt)
        assert len(rec) == 0
        assert len(node.actions) == 0
    def test_step_setting_done1_done2(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)
        a_copy = node.do(composite)
        dt = 0.1
        rec = []
        next_done = 3
        node._step(dt)
        print rec

        recx = [e for e in rec if e[0]==name1]
        assert recx[0][1]== 'step'
        assert recx[1][1]=='stop'
        assert len(recx)==2

        recx = [e for e in rec if e[0]==name2]
        assert recx[0][1]=='step'
        assert recx[1][1]=='stop'
        assert len(recx)==2

        assert a_copy.done()
        rec = []
        node._step(dt)
        assert len(rec)==0
        assert len(node.actions)==0
    def test_update_crossing_max_at_1st_step(self, duration1, duration2):
        # next_elapsed > max(duration1, duration2)
        global rec

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        rec = []
        node.do(composite)
        elapsed = 0.0
        next_elapsed = max(duration1, duration2)*1.1 # above max
        dt = next_elapsed - elapsed
        node._step(dt)

        recx = [ e for e in rec if e[1]!='step' ]
        rec = [ e for e in recx if e[0]==name1]
        print 'rec',rec
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'
        assert len(rec)==3

        rec = [ e for e in recx if e[0]==name2]
        print 'rec:', rec
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'
        assert len(rec)==3
예제 #5
0
    def test_update_crossing_min_not_max_not_at_1st_step(
            self, duration1, duration2):
        # 0< min< next_elapsed < max
        global rec

        # only applies if min(duration1, duration2)>=epsilon >0.0 , 1.0/epsilon
        # well defined
        try:
            need_test = (duration1 != duration2)
            a = 1.0 / duration1
            b = 1.0 / duration2
        except ZeroDivisionError:
            need_test = False
        if not need_test:
            # the test dont make sense for the parameters received, skip
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        dt = min(duration1, duration2) / 2.0
        node._step(dt)
        elapsed += dt  # below min

        # between duration1 and duration2
        next_elapsed = (duration1 + duration2) / 2.0
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)

        rec = [e for e in rec if e[1] != 'step']
        # expected:
        # the action with min duration will only call .update(1.0) and
        # .stop(), in that order
        # the action with max duraction will only call .update with apropiate t
        if duration1 < duration2:
            oname1 = name1
            oduration1 = duration1
            oname2 = name2
            oduration2 = duration2
        else:
            oname1 = name2
            oduration1 = duration2
            oname2 = name1
            oduration2 = duration1
        orec1 = [e for e in rec if e[0] == oname1]
        assert orec1[0] == (oname1, 'update', 1.0)
        assert orec1[1] == (oname1, 'stop')
        assert len(orec1) == 2

        orec2 = [e for e in rec if e[0] == oname2]
        assert len(orec2) == 1
        assert orec2[0][1] == 'update'
        assert abs(orec2[0][2] - next_elapsed / oduration2) < fe
    def test_update_crossing_min_not_max_not_at_1st_step(self, duration1, duration2):
        # 0< min< next_elapsed < max
        global rec
                
        # only applies if min(duration1, duration2)>=epsilon >0.0 , 1.0/epsilon
        # well defined 
        try:
            need_test = (duration1!=duration2)
            a = 1.0/duration1
            b = 1.0/duration2
        except ZeroDivisionError:
            need_test = False
        if not need_test:
            # the test dont make sense for the parameters received, skip
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        dt = min(duration1, duration2)/2.0
        node._step(dt)
        elapsed += dt # below min
        
        # between duration1 and duration2
        next_elapsed = (duration1 + duration2)/2.0
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)

        rec = [ e for e in rec if e[1]!='step' ]
        # expected:
        # the action with min duration will only call .update(1.0) and
        # .stop(), in that order
        # the action with max duraction will only call .update with apropiate t
        if duration1 < duration2:
            oname1 = name1
            oduration1 = duration1
            oname2 = name2
            oduration2 = duration2
        else:
            oname1 = name2
            oduration1 = duration2
            oname2 = name1
            oduration2 = duration1
        orec1 = [ e for e in rec if e[0]==oname1 ]
        assert orec1[0]==(oname1, 'update', 1.0)
        assert orec1[1]==(oname1, 'stop')
        assert len(orec1)==2
        
        orec2 = [ e for e in rec if e[0]==oname2 ]
        assert len(orec2)==1
        assert orec2[0][1]=='update'
        assert abs(orec2[0][2] - next_elapsed/oduration2)<fe
    def test_instantiation(self):
        global rec, next_done
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        assert isinstance(a1, ac.Action)
        a2 = UAction(name2)

        rec = []
        composite = ac.spawn(a1, a2)
        assert isinstance(composite, ac.Action)
        assert len(rec)==0
예제 #8
0
    def test_instantiation(self):
        global rec, next_done
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        assert isinstance(a1, ac.Action)
        a2 = UAction(name2)

        rec = []
        composite = ac.spawn(a1, a2)
        assert isinstance(composite, ac.Action)
        assert len(rec) == 0
예제 #9
0
    def test_target_set(self, duration1, duration2):
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.actions[0].target == node
        assert a_copy.actions[1].target == node
    def test_target_set(self, duration1, duration2):
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.actions[0].target==node
        assert a_copy.actions[1].target==node
    def test_start(self, duration1, duration2):
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)

        rec = []
        node.do(composite)
        assert [e for e in rec if e[0]==name1][0]==(name1, 'start') 
        assert [e for e in rec if e[0]==name2][0]==(name2, 'start')
예제 #12
0
    def test_start(self, duration1, duration2):
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)

        rec = []
        node.do(composite)
        assert [e for e in rec if e[0] == name1][0] == (name1, 'start')
        assert [e for e in rec if e[0] == name2][0] == (name2, 'start')
예제 #13
0
    def test_target_set(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.actions[0].target==node
        assert a_copy.actions[1].target==node
    def test_instantiation(self, duration1, duration2):
        global rec
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        assert isinstance(a1, ac.IntervalAction)
        assert a1.duration == duration1
        a2 = UIntervalAction(name2, duration2)

        rec = []
        composite = ac.spawn(a1, a2)
        assert isinstance(composite, ac.IntervalAction)
        assert composite.duration == max(duration1, duration2)
        assert len(rec)==0
예제 #15
0
    def test_target_set(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.actions[0].target == node
        assert a_copy.actions[1].target == node
예제 #16
0
    def test_update_crossing_min_not_max_at_1st_step(self, duration1,
                                                     duration2):
        # min< next_elapsed < max
        global rec
        # expect start, [xxx,]update(1), stop for shortest action

        # only applies if min<max
        need_test = (duration1 < duration2)
        if not need_test:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        rec = []
        node.do(composite)
        elapsed = 0.0
        # between duration1 and duration2
        next_elapsed = (duration1 + duration2) / 2.0
        dt = next_elapsed - elapsed
        node._step(dt)

        print('rec:', rec)
        rec = [e for e in rec if e[1] != 'step']
        if duration1 < duration2:
            oname1 = name1
            oduration1 = duration1
            oname2 = name2
            oduration2 = duration2
        else:
            oname1 = name2
            oduration1 = duration2
            oname2 = name1
            oduration2 = duration1
        orec1 = [e for e in rec if e[0] == oname1]
        print(orec1)
        assert orec1[0] == (oname1, 'start')
        assert orec1[1] == (oname1, 'update', 1.0)
        assert orec1[2] == (oname1, 'stop')
        assert len(orec1) == 3

        orec2 = [e for e in rec if e[0] == oname2]
        print(orec2)
        assert len(orec2) == 2
        assert orec2[0] == (oname2, 'start')
        assert orec2[1][1] == 'update'
        assert abs(orec2[1][2] - next_elapsed / oduration2) < fe
예제 #17
0
    def test_instantiation(self, duration1, duration2):
        global rec
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        assert isinstance(a1, ac.IntervalAction)
        assert a1.duration == duration1
        a2 = UIntervalAction(name2, duration2)

        rec = []
        composite = ac.spawn(a1, a2)
        assert isinstance(composite, ac.IntervalAction)
        assert composite.duration == max(duration1, duration2)
        assert len(rec) == 0
    def test_update_crossing_min_not_max_at_1st_step(self, duration1, duration2):
        # min< next_elapsed < max
        global rec
        # expect start, [xxx,]update(1), stop for shortest action

        # only applies if min<max
        need_test = (duration1 < duration2)
        if not need_test:
            return
        
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        rec = []
        node.do(composite)
        elapsed = 0.0
        # between duration1 and duration2
        next_elapsed = (duration1 + duration2)/2.0
        dt = next_elapsed - elapsed
        node._step(dt)
        
        print 'rec:', rec
        rec = [ e for e in rec if e[1]!='step' ]
        if duration1 < duration2:
            oname1 = name1
            oduration1 = duration1
            oname2 = name2
            oduration2 = duration2
        else:
            oname1 = name2
            oduration1 = duration2
            oname2 = name1
            oduration2 = duration1
        orec1 = [ e for e in rec if e[0]==oname1 ]
        print orec1
        assert orec1[0]==(oname1, 'start')
        assert orec1[1]==(oname1, 'update', 1.0)
        assert orec1[2]==(oname1, 'stop')
        assert len(orec1)==3
        
        orec2 = [ e for e in rec if e[0]==oname2 ]
        print orec2
        assert len(orec2)==2
        assert orec2[0]==(oname2, 'start')
        assert orec2[1][1]=='update'
        assert abs(orec2[1][2] - next_elapsed/oduration2)<fe
예제 #19
0
    def test_receiving_stop_async_before_done1_done2(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)
        a_copy = node.do(composite)

        rec=[]
        a_copy.stop()
        assert rec[0]==(name1, 'stop')
        assert rec[1]==(name2, 'stop')
        assert len(rec)==2
예제 #20
0
    def test_start(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)

        rec = []
        node.do(composite)
        print('start rec:', rec)
        assert rec[0] == (name1, 'start')
        assert rec[0] == (name1, 'start')
        assert len(rec) == 2
예제 #21
0
    def test_receiving_stop_async_before_done1_done2(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)
        a_copy = node.do(composite)

        rec = []
        a_copy.stop()
        assert rec[0] == (name1, 'stop')
        assert rec[1] == (name2, 'stop')
        assert len(rec) == 2
예제 #22
0
    def test_start(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)

        rec = []
        node.do(composite)
        print 'start rec:', rec
        assert rec[0]==(name1, 'start')
        assert rec[0]==(name1, 'start')
        assert len(rec)==2
예제 #23
0
 def test_step_before_any_done(self):
     global rec, next_done
     next_done = 0
     node = CocosNode()
     name1 = '1'
     name2 = '2'
     a1 = UAction(name1)
     a2 = UAction(name2)
     composite = ac.spawn(a1, a2)
     a_copy = node.do(composite)
     dt = 0.1
     rec = []
     node._step(dt)
     assert rec[0] == (name1, 'step', dt)
     assert rec[0] == (name1, 'step', dt)
     assert not a_copy.done()
     assert len(rec) == 2
예제 #24
0
 def test_step_before_any_done(self):
     global rec, next_done
     next_done=0
     node = CocosNode()
     name1 = '1'
     name2 = '2'
     a1 = UAction(name1)
     a2 = UAction(name2)
     composite = ac.spawn(a1, a2)
     a_copy = node.do(composite)
     dt = 0.1
     rec = []
     node._step(dt)
     assert rec[0]==(name1, 'step', dt)
     assert rec[0]==(name1, 'step', dt)
     assert not a_copy.done()
     assert len(rec)==2
    def test_updating_above_min_below_max(self, duration1, duration2):
        # min < elapsed < next_elapsed < max
        global rec


        need_test = (duration1!=duration2)
        if not need_test:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        next_elapsed = (duration1 + duration2)/2.0 # above min, below max
        dt = next_elapsed - elapsed
        node._step(dt)
        elapsed = next_elapsed
        next_elapsed = (elapsed + max(duration1, duration2))/2.0
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)

        # expected:
        # no call from the action with min duration
        # only one call from the action with max duration and will be .update
        if duration1 < duration2:
            oname1 = name1
            oname2 = name2
        else:
            oname1 = name2
            oname2 = name1
        rec_lo = [ e for e in rec if e[0]==oname1]
        print 'rec_lo:', rec_lo
        assert len(rec_lo)==0

        rec = [ e for e in rec if e[0]==oname2]
        rec = [ e for e in rec if e[1]!='step' ]
        print 'rec hi:',rec
        assert len(rec)==1
        assert (rec[0][1]=='update' and
                abs(rec[0][2] - next_elapsed/max(duration1, duration2))<fe)
예제 #26
0
    def test_updating_above_min_below_max(self, duration1, duration2):
        # min < elapsed < next_elapsed < max
        global rec

        need_test = (duration1 != duration2)
        if not need_test:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        next_elapsed = (duration1 + duration2) / 2.0  # above min, below max
        dt = next_elapsed - elapsed
        node._step(dt)
        elapsed = next_elapsed
        next_elapsed = (elapsed + max(duration1, duration2)) / 2.0
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)

        # expected:
        # no call from the action with min duration
        # only one call from the action with max duration and will be .update
        if duration1 < duration2:
            oname1 = name1
            oname2 = name2
        else:
            oname1 = name2
            oname2 = name1
        rec_lo = [e for e in rec if e[0] == oname1]
        print('rec_lo:', rec_lo)
        assert len(rec_lo) == 0

        rec = [e for e in rec if e[0] == oname2]
        rec = [e for e in rec if e[1] != 'step']
        print('rec hi:', rec)
        assert len(rec) == 1
        assert (rec[0][1] == 'update' and
                abs(rec[0][2] - next_elapsed / max(duration1, duration2)) < fe)
    def test_updating_below_min(self, duration1, duration2):
        # next_elapsed < min(duration1, duration2)
        global rec

        # only applies if min(duration1, duration2)>=epsilon >0.0 , 1.0/epsilon
        # well defined 
        need_test = True
        try:
            a = 1.0/duration1
            b = 1.0/duration2
        except ZeroDivisionError:
            need_test = False
        if not need_test:
            # the test dont make sense for the parameters received, skip
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        
        min_duration = min(duration1, duration2)
        for next_elapsed in [ min_duration/3.0, min_duration/2.0]:
            dt = next_elapsed - elapsed
            rec = []
            node._step(dt)
            
            rec = [ e for e in rec if e[1]!='step' ]
            rec1 = [ e for e in rec if e[0]==name1]
            assert len(rec1)==1
            assert (rec1[0][1]=='update' and
                    abs(rec1[0][2]-next_elapsed/duration1)<fe
                    )
            rec2 = [ e for e in rec if e[0]==name2]
            assert len(rec2)==1
            assert(rec2[0][1]=='update' and
                   abs(rec2[0][2]-next_elapsed/duration2)<fe
                   )
            elapsed = next_elapsed
    def update_crossing_max_from_below_min(self, duration1, duration2):
        # elapsed < min <= max < next_elapsed
        global rec

        need_test = True
        try:
            a = 1.0/duration1
            b = 1.0/duration2
        except ZeroDivisionError:
            need_test = False
        if not need_test:
            # the test dont make sense for the parameters received, skip
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        next_elapsed = min(duration1, duration2)/2.0 # above 0, below min
        dt = next_elapsed - elapsed
        node._step(dt)
        next_elapsed = max(duration1, duration2)*1.1 # above max
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)

        # expected: for each action .update(1.0) and stop() called, in that order
        # nothing more
        # ? maybe step
        recx = [ e for e in rec if e[1]!='step' ]
        rec = [ e for e in recx if e[0]==name1]
        assert len(rec)==2
        assert rec[0][1]=='update' and rec[0][2]==1.0
        assert rec[1][1]=='stop'

        rec = [ e for e in recx if e[0]==name2]
        assert len(rec)==2
        assert rec[0][1]=='update' and rec[0][2]==1.0
        assert rec[1][1]=='stop'
예제 #29
0
    def test_receiving_stop_async_after_done2_before_done1(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)
        a_copy = node.do(composite)
        dt = 0.1
        next_done = 2
        node._step(dt)

        rec = []
        print(rec)
        a_copy.stop()
        assert rec[0] == (name1, 'stop')
        assert len(rec) == 1
예제 #30
0
    def update_crossing_max_from_below_min(self, duration1, duration2):
        # elapsed < min <= max < next_elapsed
        global rec

        need_test = True
        try:
            a = 1.0 / duration1
            b = 1.0 / duration2
        except ZeroDivisionError:
            need_test = False
        if not need_test:
            # the test dont make sense for the parameters received, skip
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        next_elapsed = min(duration1, duration2) / 2.0  # above 0, below min
        dt = next_elapsed - elapsed
        node._step(dt)
        next_elapsed = max(duration1, duration2) * 1.1  # above max
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)

        # expected: for each action .update(1.0) and stop() called, in that order
        # nothing more
        # ? maybe step
        recx = [e for e in rec if e[1] != 'step']
        rec = [e for e in recx if e[0] == name1]
        assert len(rec) == 2
        assert rec[0][1] == 'update' and rec[0][2] == 1.0
        assert rec[1][1] == 'stop'

        rec = [e for e in recx if e[0] == name2]
        assert len(rec) == 2
        assert rec[0][1] == 'update' and rec[0][2] == 1.0
        assert rec[1][1] == 'stop'
예제 #31
0
    def test_receiving_stop_async_after_done2_before_done1(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.spawn(a1, a2)
        a_copy = node.do(composite)
        dt = 0.1
        next_done = 2
        node._step(dt)

        rec=[]
        print rec
        a_copy.stop()
        assert rec[0]==(name1, 'stop')
        assert len(rec)==1
    def test_update_crossing_max_from_above_min(self, duration1, duration2):
        # min < elapsed < max < next_elapsed
        global rec
        
        need_test = (duration1!=duration2)
        if not need_test:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        next_elapsed = (duration1 + duration2)/2.0 # above min, below max
        dt = next_elapsed - elapsed
        node._step(dt)
        elapsed = next_elapsed
        next_elapsed = max(duration1, duration2)*1.1 # above max
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)
        # expected: no call from action with min duration, two calls from the
        # action with max duration: .update(1) and .stop() in that order
        if duration1 < duration2:
            oname1 = name1
            oname2 = name2
        else:
            oname1 = name2
            oname2 = name1
        rec_lo = [ e for e in rec if e[0]==oname1]
        print 'rec_lo:', rec_lo
        assert len(rec_lo)==0

        rec = [ e for e in rec if e[0]==oname2]
        rec = [ e for e in rec if e[1]!='step' ]
        print 'rec hi:', rec
        assert rec[0][1]=='update' and rec[0][2]==1.0
        assert rec[1][1]=='stop'
        assert len(rec)==2
예제 #33
0
    def test_update_crossing_max_from_above_min(self, duration1, duration2):
        # min < elapsed < max < next_elapsed
        global rec

        need_test = (duration1 != duration2)
        if not need_test:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0
        next_elapsed = (duration1 + duration2) / 2.0  # above min, below max
        dt = next_elapsed - elapsed
        node._step(dt)
        elapsed = next_elapsed
        next_elapsed = max(duration1, duration2) * 1.1  # above max
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)
        # expected: no call from action with min duration, two calls from the
        # action with max duration: .update(1) and .stop() in that order
        if duration1 < duration2:
            oname1 = name1
            oname2 = name2
        else:
            oname1 = name2
            oname2 = name1
        rec_lo = [e for e in rec if e[0] == oname1]
        print('rec_lo:', rec_lo)
        assert len(rec_lo) == 0

        rec = [e for e in rec if e[0] == oname2]
        rec = [e for e in rec if e[1] != 'step']
        print('rec hi:', rec)
        assert rec[0][1] == 'update' and rec[0][2] == 1.0
        assert rec[1][1] == 'stop'
        assert len(rec) == 2
예제 #34
0
    def test_updating_below_min(self, duration1, duration2):
        # next_elapsed < min(duration1, duration2)
        global rec

        # only applies if min(duration1, duration2)>=epsilon >0.0 , 1.0/epsilon
        # well defined
        need_test = True
        try:
            a = 1.0 / duration1
            b = 1.0 / duration2
        except ZeroDivisionError:
            need_test = False
        if not need_test:
            # the test dont make sense for the parameters received, skip
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.spawn(a1, a2)
        node.do(composite)
        elapsed = 0.0

        min_duration = min(duration1, duration2)
        for next_elapsed in [min_duration / 3.0, min_duration / 2.0]:
            dt = next_elapsed - elapsed
            rec = []
            node._step(dt)

            rec = [e for e in rec if e[1] != 'step']
            rec1 = [e for e in rec if e[0] == name1]
            assert len(rec1) == 1
            assert (rec1[0][1] == 'update'
                    and abs(rec1[0][2] - next_elapsed / duration1) < fe)
            rec2 = [e for e in rec if e[0] == name2]
            assert len(rec2) == 1
            assert (rec2[0][1] == 'update'
                    and abs(rec2[0][2] - next_elapsed / duration2) < fe)
            elapsed = next_elapsed