def test_updating_above_duration1_below_duration(self, duration1, duration2):
        global rec

        if duration2==0.0:
            return

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

        assert len([e for e in rec if e[0]==name1])==0
        rec = [ e for e in rec if e[1]!='step' ]
        print rec
        assert rec[0][1]=='update'
        assert abs(rec[0][2]-(next_elapsed-duration1)/duration2)<fe
        assert len(rec)==1
    def test_update_crossing_total_duration_at_1st_step(self, duration1, duration2):
        # elapsed==0, next_elapsed>=duration1 + duration2
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        elapsed = 0.0
        rec = []
        composite = ac.sequence(a1, a2)
        node.do(composite)
        next_elapsed = duration1 + duration2 +fe
        dt = next_elapsed - elapsed
        node._step(dt)
        # expected: for both actions start-update(1)-stop called, in that order
        recx = [ e for e in rec if e[1]!='step' ]
        rec = [ e for e in recx if e[0]==name1]
        print 'rec',rec
        assert len(rec)==3
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'

        rec = [ e for e in recx if e[0]==name2]
        print 'rec',rec
        assert len(rec)==3
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'
    def test_update_crossing_duration1_not_duration_at_1st_step(self, duration1, duration2):
        global rec

        if duration2==0.0:
            return

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

        #expect start, update(1), stop for action 1, start + update(x) for action2
        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'
        assert abs(rec[1][2]-(next_elapsed-duration1)/duration2)<fe
        assert len(rec)==2
Esempio n. 4
0
    def test_update_crossing_duration1_not_duration_at_1st_step(self, duration1, duration2):
        global rec

        if duration2==0.0:
            return

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

        #expect start, update(1), stop for action 1, start + update(x) for action2
        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'
        assert abs(rec[1][2]-(next_elapsed-duration1)/duration2)<fe
        assert len(rec)==2
Esempio n. 5
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
Esempio n. 6
0
    def test_update_crossing_total_duration_at_1st_step(self, duration1, duration2):
        # elapsed==0, next_elapsed>=duration1 + duration2
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        elapsed = 0.0
        rec = []
        composite = ac.sequence(a1, a2)
        node.do(composite)
        next_elapsed = duration1 + duration2 +fe
        dt = next_elapsed - elapsed
        node._step(dt)
        # expected: for both actions start-update(1)-stop called, in that order
        recx = [ e for e in rec if e[1]!='step' ]
        rec = [ e for e in recx if e[0]==name1]
        print('rec', rec)
        assert len(rec)==3
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'

        rec = [ e for e in recx if e[0]==name2]
        print('rec', rec)
        assert len(rec)==3
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'
    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
Esempio n. 8
0
    def test_updating_above_duration1_below_duration(self, duration1, duration2):
        global rec

        if duration2==0.0:
            return

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

        assert len([e for e in rec if e[0]==name1])==0
        rec = [ e for e in rec if e[1]!='step' ]
        print(rec)
        assert rec[0][1]=='update'
        assert abs(rec[0][2]-(next_elapsed-duration1)/duration2)<fe
        assert len(rec)==1
    def test_update_below_duration1(self, duration1, duration2):
        global rec

        if duration1 == 0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)
        node.do(composite)
        elapsed = 0.0
        # check cases 1st step and not 1st step
        for next_elapsed in [duration1 * 0.5, duration1 * 0.75]:
            dt = next_elapsed - elapsed
            rec = []
            node._step(dt)
            rec = [e for e in rec if e[1] != 'step']
            print(rec)
            assert rec[0][1] == 'update' and abs(rec[0][2] -
                                                 next_elapsed / duration1) < fe
            assert len(rec) == 1
            elapsed = next_elapsed
Esempio n. 10
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
Esempio n. 11
0
 def excute(self, i=0):
     if i < self.length:
         _target, _action = self.actionlist[i]  #type:CocosNode, Action
         if _target is None:
             _target = CocosNode()
         _target.do(_action + CallFunc(self.excute, i+1))
     else:
         print('excuted')
    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
Esempio n. 13
0
def test_Loop_InstantAction():
    rec = []
    def f(x):
       rec.append(x)
    node = CocosNode()
    template_action = cocos.actions.instant_actions.CallFunc(f, 1)
    n = 5
    action = template_action * n
    node.do(action)
    assert rec == [1] * n
Esempio n. 14
0
def test_Loop_InstantAction():
    rec = []

    def f(x):
        rec.append(x)

    node = CocosNode()
    template_action = cocos.actions.instant_actions.CallFunc(f, 1)
    n = 5
    action = template_action * n
    node.do(action)
    assert rec == [1] * n
    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')
Esempio n. 16
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')
Esempio n. 17
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
    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
Esempio n. 19
0
    def test_update_1_called(self):
        global rec
        duration = 2.0
        original_action = UIntervalAction('original', duration)
        modified_action = ac.AccelDeccel(original_action)

        node = CocosNode()
        node.do(modified_action)
        dt = duration * 1.0
        rec = []
        node._step(dt)
        print('rec:', rec)
        update_record = rec[-1]
        assert update_record[1] == 'update'
        assert update_record[2] == 1.0
Esempio n. 20
0
    def test_update_1_called(self):
        global rec
        duration = 2.0
        original_action = UIntervalAction('original', duration)
        modified_action = ac.AccelDeccel(original_action)

        node = CocosNode()
        node.do(modified_action)
        dt = duration * 1.0
        rec = []
        node._step(dt)
        print 'rec:', rec
        update_record = rec[-1]
        assert update_record[1] == 'update'
        assert update_record[2] == 1.0
Esempio n. 21
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
    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
Esempio n. 23
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
Esempio n. 25
0
    def test_remove_action(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        action1 = UAction(name1)
        name2 = '2'
        action2 = UAction(name2)
        a1_copy = node.do(action1)
        a2_copy = node.do(action2)
        assert len(node.actions) == 2
        rec = []
        node.remove_action(a1_copy)

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

        rec = []
        dt = 0.1
        node._step(
            dt)  # needed to complete delete, will traceback if remove failed
        assert len(node.actions) == 1
        assert a2_copy in node.actions
        recx = [e for e in rec if e[0] == name1]
        assert len(recx) == 0
    def test_test_receiving_stop_async_after_duration1_before_duration2(
            self, duration1, duration2):
        #0<duration2
        global rec

        if duration2 == 0.0:
            return

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

        rec = []
        a_copy.stop()
        assert rec[0] == (name2, 'stop')
        assert len(rec) == 1
    def test_remove_action(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        action1 = UAction(name1)
        name2 = '2'
        action2 = UAction(name2)
        a1_copy = node.do(action1)
        a2_copy = node.do(action2)
        assert len(node.actions)==2
        rec = []
        node.remove_action(a1_copy)

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

        rec =[]
        dt = 0.1
        node._step(dt)# needed to complete delete, will traceback if remove failed
        assert len(node.actions)==1
        assert a2_copy in node.actions
        recx = [ e for e in rec if e[0]==name1]
        assert len(recx)==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)
Esempio n. 29
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 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'
Esempio n. 31
0
 def test_remove_action(self):
     node = CocosNode()
     self.assertTrue(len(node.actions)==0)
     action = ac.Action()
     a_copy = node.do(action)
     self.assertTrue(len(node.actions)==1)
     node.remove_action(a_copy)
     dt = 0.1
     node._step(dt)# needed to complete delete, will traceback if remove failed
     self.assertTrue(len(node.actions)==0)
Esempio n. 32
0
 def test_node_stop_calls_remove_and_not_anything_in_action(self):
     global rec, next_done
     next_done = 0
     node = CocosNode()
     name1 = '1'
     action1 = UAction(name1)
     name2 = '2'
     action2 = UAction(name2)
     a1_copy = node.do(action1)
     a2_copy = node.do(action2)
 def test_node_stop_calls_remove_and_not_anything_in_action(self):
     global rec, next_done
     next_done = 0
     node = CocosNode()
     name1 = '1'
     action1 = UAction(name1)
     name2 = '2'
     action2 = UAction(name2)
     a1_copy = node.do(action1)
     a2_copy = node.do(action2)
    def test_target_set(self):
        global rec, next_done
        node = CocosNode()
        name1 = '1'
        a1 = UAction(name1)
        composite = ac.Repeat(a1)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.action.target==node
    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
Esempio n. 36
0
    def test_target_set(self):
        global rec, next_done
        node = CocosNode()
        name1 = '1'
        a1 = UAction(name1)
        composite = ac.Repeat(a1)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.action.target == node
Esempio n. 37
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'
Esempio n. 38
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
    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
    def test_start(self, duration1, duration2):
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)

        rec = []
        node.do(composite)
        print 'start rec:', rec
        num = 0
        assert rec[num]==(name1, 'start')
        if duration1==0.0:
            assert rec[num + 1]==(name1, 'update', 1.0)
            assert rec[num + 2]==(name1, 'stop')
            assert rec[num + 3]==(name2, 'start')
            num = num + 3
        assert len(rec)==num+1
Esempio n. 41
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.sequence(a1, a2)

        rec = []
        node.do(composite)
        print('start rec:', rec)
        num = 0
        assert rec[num]==(name1, 'start')
        if duration1==0.0:
            assert rec[num + 1]==(name1, 'update', 1.0)
            assert rec[num + 2]==(name1, 'stop')
            assert rec[num + 3]==(name2, 'start')
            num = num + 3
        assert len(rec)==num+1
Esempio n. 42
0
 def test_remove_action(self):
     node = CocosNode()
     self.assertTrue(len(node.actions) == 0)
     action = ac.Action()
     a_copy = node.do(action)
     self.assertTrue(len(node.actions) == 1)
     node.remove_action(a_copy)
     dt = 0.1
     node._step(
         dt)  # needed to complete delete, will traceback if remove failed
     self.assertTrue(len(node.actions) == 0)
Esempio n. 43
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
Esempio n. 44
0
    def test_target_set(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        times = 2
        a1 = UAction(name1)
        composite = ac.loop(a1, times)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.current_action.target == node
    def test_target_set(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        times = 2
        a1 = UAction(name1)
        composite = ac.loop(a1, times)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.current_action.target==node
    def test_target_set(self):
        global rec
        node = CocosNode()
        name1 = '1'
        duration1 = 3.0
        times = 2
        a1 = UIntervalAction(name1, duration1)
        composite = ac.loop(a1, times)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.current_action.target == node
    def test_target_set_next_time(self):
        global rec, next_done
        node = CocosNode()
        name1 = '1'
        a1 = UAction(name1)
        composite = ac.Repeat(a1)

        a_copy = node.do(composite)
        dt = 0.1
        next_done=1
        node._step(dt)
        assert a_copy.action.target==node
    def test_target_set(self):
        global rec
        node = CocosNode()
        name1 = '1'
        duration1 = 3.0
        times = 2
        a1 = UIntervalAction(name1, duration1)
        composite = ac.loop(a1, times)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.current_action.target==node
Esempio n. 49
0
    def test_target_set_next_time(self):
        global rec, next_done
        node = CocosNode()
        name1 = '1'
        a1 = UAction(name1)
        composite = ac.Repeat(a1)

        a_copy = node.do(composite)
        dt = 0.1
        next_done = 1
        node._step(dt)
        assert a_copy.action.target == node
    def test_life_cycle(self):
        global rec, next_done
        next_done=0
        name1 = '1'
        times = 2
        a1 = UAction(name1)
        node = CocosNode()
        composite = ac.loop(a1, times)
        
        #1st start
        rec = []
        a_copy = node.do(composite)
        assert rec[0]==(name1, 'start')
        assert len(rec)==1
        assert not a_copy.done()

        #step in first repetition
        dt = 0.1
        next_done=0
        rec = []
        node._step(dt)
        assert rec[0]==(name1, 'step', dt) 
        assert len(rec)==1
        assert not a_copy.done()

        #termination first repetion, start second repetition
        next_done = 1
        rec = []
        node._step(dt)
        assert rec[0]==(name1, 'step', dt) 
        assert rec[1]==(name1, 'stop')
        assert rec[2]==(name1, 'start')
        assert len(rec)==3
        assert not a_copy.done()

        #step in second repetition
        next_done=0
        rec = []
        node._step(dt)
        assert rec[0]==(name1, 'step', dt) 
        assert len(rec)==1
        assert not a_copy.done()

        #terminatation last repetition
        next_done = 1
        rec = []
        node._step(dt)
        assert rec[0]==(name1, 'step', dt) 
        assert rec[1]==(name1, 'stop')
        assert len(rec)==2

        assert a_copy.done()
Esempio n. 51
0
    def test_life_cycle(self):
        global rec, next_done
        next_done = 0
        name1 = '1'
        times = 2
        a1 = UAction(name1)
        node = CocosNode()
        composite = ac.loop(a1, times)

        #1st start
        rec = []
        a_copy = node.do(composite)
        assert rec[0] == (name1, 'start')
        assert len(rec) == 1
        assert not a_copy.done()

        #step in first repetition
        dt = 0.1
        next_done = 0
        rec = []
        node._step(dt)
        assert rec[0] == (name1, 'step', dt)
        assert len(rec) == 1
        assert not a_copy.done()

        #termination first repetion, start second repetition
        next_done = 1
        rec = []
        node._step(dt)
        assert rec[0] == (name1, 'step', dt)
        assert rec[1] == (name1, 'stop')
        assert rec[2] == (name1, 'start')
        assert len(rec) == 3
        assert not a_copy.done()

        #step in second repetition
        next_done = 0
        rec = []
        node._step(dt)
        assert rec[0] == (name1, 'step', dt)
        assert len(rec) == 1
        assert not a_copy.done()

        #terminatation last repetition
        next_done = 1
        rec = []
        node._step(dt)
        assert rec[0] == (name1, 'step', dt)
        assert rec[1] == (name1, 'stop')
        assert len(rec) == 2

        assert a_copy.done()
    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
Esempio n. 53
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_do_inmediate_effects1(self):
     # do called without an explicit target
     global rec, next_done
     next_done = 0
     node = CocosNode()
     name1 = '1'
     action = UAction(name1)
     rec = []
     a_copy = node.do(action)
     assert a_copy.target == node
     assert a_copy in node.actions
     assert len(node.actions)==1
     assert rec[0]==(name1, 'start')
     assert len(rec)==1
Esempio n. 55
0
 def test_do_inmediate_effects1(self):
     # do called without an explicit target
     global rec, next_done
     next_done = 0
     node = CocosNode()
     name1 = '1'
     action = UAction(name1)
     rec = []
     a_copy = node.do(action)
     assert a_copy.target == node
     assert a_copy in node.actions
     assert len(node.actions) == 1
     assert rec[0] == (name1, 'start')
     assert len(rec) == 1
Esempio n. 56
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.sequence(a1, a2)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.one.target == node
        assert a_copy.two.target == node
    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.sequence(a1, a2)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.one.target==node
        assert a_copy.two.target==node
 def test_do_inmediate_effects2(self):
     # do called with an explicit target
     global rec, next_done
     next_done = 0
     node = CocosNode()
     name1 = "1"
     action = UAction(name1)
     my_target = "zptx"
     rec = []
     a_copy = node.do(action, target=my_target)
     assert a_copy.target == my_target
     assert a_copy in node.actions
     assert len(node.actions) == 1
     assert rec[0] == (name1, "start")
     assert len(rec) == 1
    def test_update_below_duration1(self, duration1, duration2):
        global rec

        if duration1==0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)
        node.do(composite)
        elapsed = 0.0
        # check cases 1st step and not 1st step
        for next_elapsed in [ duration1*0.5, duration1*0.75]:
            dt = next_elapsed - elapsed
            rec = []
            node._step(dt)
            rec = [ e for e in rec if e[1]!='step' ]
            print rec
            assert rec[0][1]=='update' and abs(rec[0][2]-next_elapsed/duration1)<fe
            assert len(rec)==1
            elapsed = next_elapsed
    def test_receiving_stop_async_before_done1(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)
        rec = []
        a_copy.stop()

        assert rec[0]==(name1, 'stop')
        len(rec)==0