def test_caracter(self): 'Teste de caracter para status ATIVO e DESTRUIDO' ator = Actor() self.assertEqual('A', ator.character()) outro_ator_na_mesma_posicao = Actor() ator.clash(outro_ator_na_mesma_posicao) self.assertEqual(' ', ator.character())
def test_character(self): 'Testing char for ACTIVE and DESTROYED status' ator = Actor() self.assertEqual('A', ator.character()) actor_on_same_position = Actor() ator.clash(actor_on_same_position) self.assertEqual(' ', ator.character())
def tests(): parser_tests() a = Actor(global_env, Script([Method('method1', [], 'Hurary'), Method('method2:', ['x'], 'x')])) n = Number(3) env = Env(None, {'a': a, 'n': n}) test_expr(env, 'a', a) should_raise(env, 'b', 'Unbound') should_raise(env, 'a method1', 'Unbound') should_raise(env, 'a foo', 'No matching method') test_expr(env, 'a method2: a', a) test_expr(env, 'n * n', Number(9)) test_expr(env, 'a. n', n) test_expr(env, '', void_actor) test_expr(env, '42', Number(42)) test_expr(env, '(a method2: 3) * 2', Number(6)) s1 = Script([Method('run:', ['x'], 'make Foo')]) s2 = Script([Method('multiply_by:', ['y'], 'x * y')]) s1.get_method('run:').set_inner('Foo', s2) a1 = Actor(global_env, s1) env1 = Env(None, {'a1': a1}) test_expr(env1, '(a1 run: 4) multiply_by: 5', Number(20)) assert Method('f', [], 'ab. ab').mark_up_body(global_env) == 'ab. ab' assert Method('foo:', ['x'], 'x').get_signature() == 'foo: x' s = String('Hello, world!') env2 = Env(None, {'s': s}) test_expr(env2, 's', String('Hello, ' + 'world!')) test_expr(env2, 's length', Number(13)) test_expr(env2, 's from: 1 to: 5', String('Hello')) test_expr(env2, "'Hello, world!'", s) test_expr(env2, 'let x = 2 * 3. x * x', Number(36))
def teste_ator_posicao(self): 'Teste que verifica que o ator comum não deve se mover independente do tempo do jogo' ator = Actor() x, y = ator.calculate_position(0) self.assertEqual(0, x) self.assertEqual(0, y) ator = Actor(0.3, 0.5) x, y = ator.calculate_position(10) self.assertEqual(0.3, x) self.assertEqual(0.5, y)
def test_actor_position(self): "Test that an ordinary actor doen't move." ator = Actor() x, y = ator.calculate_position(0) self.assertEqual(0, x) self.assertEqual(0, y) ator = Actor(0.3, 0.5) x, y = ator.calculate_position(10) self.assertEqual(0.3, x) self.assertEqual(0.5, y)
def test_move_ten_steps(): sujeto = Actor('A') a = actions.Move(sujeto, 0, 10, Vector(100, 10)) a.start(0) a.step(0) assert sujeto.pos == Vector(10, 1) a.step(1) assert sujeto.pos == Vector(20, 2) a.step(2) assert sujeto.pos == Vector(30, 3) a.step(3) assert sujeto.pos == Vector(40, 4) a.step(4) assert sujeto.pos == Vector(50, 5) a.step(5) assert sujeto.pos == Vector(60, 6) a.step(6) assert sujeto.pos == Vector(70, 7) a.step(7) assert sujeto.pos == Vector(80, 8) a.step(8) assert sujeto.pos == Vector(90, 9) a.step(9) assert sujeto.pos == Vector(100, 10) a.end(10)
def teste_valores_passados_por_parametro(self): 'Testa se valores passados no inicializador são armazenados no objeto' ator = Actor(1, 2) self.assertEqual(1, ator.x) self.assertEqual(2, ator.y) self.assertEqual(ACTIVE, ator.status) self.assertEqual('A', ator.character())
def eval(self, env): from actors import Actor, void_actor # XXX circular dependency nested_env = env.sprout() env.define(self.name, void_actor) # XXX need some other marker result = Actor(nested_env, self.script) env.define(self.name, result) return result
def test_stored_values(self): 'Tests if initial values are stored in Actor' ator = Actor(1, 2) self.assertEqual(1, ator.x) self.assertEqual(2, ator.y) self.assertEqual(ACTIVE, ator.status) self.assertEqual('A', ator.character())
def teste_valores_padrao(self): 'Testa valores iniciais padrão de um Actor' ator = Actor() self.assertEqual(0, ator.x) self.assertEqual(0, ator.y) self.assertEqual(ACTIVE, ator.status) self.assertEqual('A', ator.character())
def test_default_values(self): 'Test inital values of Actor' ator = Actor() self.assertEqual(0, ator.x) self.assertEqual(0, ator.y) self.assertEqual(ACTIVE, ator.status) self.assertEqual('A', ator.character())
def embody(symbol): from actors import Actor, Being kind = Habitor(symbol) if kind in (Habitor.Elf, Habitor.Goblin): return Actor(Habitor(symbol)) else: return Being(Habitor(symbol))
def agregar(self, k=0, modif=False): if modif is False: k = input("\nIngrese el codigo de Actor: ") nombre = input("Ingrese el nombre: ") personajes = {} actor = Actor(nombre, personajes) self.repoA.repoActors[k] = actor self.listar()
def test_get_relative_frame(): task = actions.Action(Actor('A'), 5, 10) assert task.get_relative_frame(5) == 1 assert task.get_relative_frame(6) == 2 assert task.get_relative_frame(7) == 3 assert task.get_relative_frame(8) == 4 assert task.get_relative_frame(9) == 5 assert task.get_relative_frame(10) == 6
def test_last_frame(): task = actions.Action(Actor('A'), 5, 10) with pytest.raises(ValueError): task.is_last(4) assert not task.is_last(5) assert not task.is_last(6) assert not task.is_last(7) assert not task.is_last(8) assert not task.is_last(9) assert task.is_last(10) with pytest.raises(ValueError): task.is_last(11)
def make_account(): from actors import Expression # XXX circular module dependency root_env = global_env.sprout() sender_script = \ Script([Method('send:', ['message'], 'inbox <- ([message] + inbox get)')]) mailbox_script = \ Script([Method('first', [], 'inbox get at: 1'), Method('removefirst', [], 'inbox <- (inbox get from: 2)'), Method('sender', [], 'sender')]) makemailbox_run = \ Method('run', [], Expression('let inbox = makebox holding: []. make sender. make mailbox', {'sender': sender_script, 'mailbox': mailbox_script})) root_env.define('makemailbox', Actor(root_env, Script([makemailbox_run]))) root_env.define('maildirectory', maildir_actor) root_actor = \ Actor(root_env, Script([Text('Welcome to your new account. You should bookmark this page if you ever intend to return, because going back and clicking "Go!" again would create another new account with a different URI.\n\nIn Hmph, everything is an object, and every object has a page with a generated URI. For example, the number 2 is an object. Below, we send it the message "+ 3" and it adds 3 to itself, yielding 5:'), Example('2 + 3'), Example('(3*3) + (4*4)'), Text('The syntax is related to Smalltalk, but not the same. To make a new type of object, decide on what to call it in the local scope, such as Foo, and enter "make Foo":'), Example('make Foo'), Text('You can also give a local name to any other object using "let name = expression". For example:'), Example('let box = makebox holding: true'), Example('box get'), Example('box <- false. box get'), Example("['hello']"), Text("""There's a public directory of message boxes for other users, in maildirectory:"""), Example('maildirectory'), Text('You can create your own mailbox:'), Example('let mailbox = makemailbox run'), Text("""To add it to the directory, enter "maildirectory at: 'alice' put: mailbox sender" into the "Add example" field below, changing alice to some single-word identifier of your choice. (This will fail and return false if that identifier is already taken.) Then inspect "mailbox" to see how to get your messages. A message can be any object, not just plain text."""), Text("""Have fun exploring! Don't put much work into it, at least yet, because this account *will* get zapped during code upgrades; I'm not ready to commit to continuity yet. There will be actual documentation real soon now. Please send feedback to Darius Bacon <*****@*****.**>. Thanks!""") ])) return get_editor(root_actor)
def test_move_not_in_origin(): sujeto = Actor('A', pos=Vector(50, 50)) a = actions.Move(sujeto, 0, 5, Vector(50, 0)) a.start(0) a.step(0) assert sujeto.pos == Vector(50, 40) a.step(1) assert sujeto.pos == Vector(50, 30) a.step(2) assert sujeto.pos == Vector(50, 20) a.step(3) assert sujeto.pos == Vector(50, 10) a.step(4) assert sujeto.pos == Vector(50, 0) a.end(5)
def test_move_five_steps(): sujeto = Actor('A') a = actions.Move(sujeto, 0, 5, Vector(50, 0)) a.start(0) a.step(0) assert sujeto.pos == Vector(10, 0) a.step(1) assert sujeto.pos == Vector(20, 0) a.step(2) assert sujeto.pos == Vector(30, 0) a.step(3) assert sujeto.pos == Vector(40, 0) a.step(4) assert sujeto.pos == Vector(50, 0) a.end(5)
def test_fall_not_in_origin(): sujeto = Actor('A', pos=(100, 0)) a = actions.Fall(sujeto, 0, 5, Vector(200, 0)) a.start(0) a.step(0) assert sujeto.pos == Vector(104, 0) a.step(1) assert sujeto.pos == Vector(116, 0) a.step(2) assert sujeto.pos == Vector(136, 0) a.step(3) assert sujeto.pos == Vector(164, 0) a.step(4) assert sujeto.pos == Vector(200, 0) a.end(5)
def test(): sujeto = Actor('A') a = actions.Fall(sujeto, 0, 5, Vector(100, 0)) a.start(0) a.step(0) assert sujeto.pos == Vector(4, 0) a.step(1) assert sujeto.pos == Vector(16, 0) a.step(2) assert sujeto.pos == Vector(36, 0) a.step(3) assert sujeto.pos == Vector(64, 0) a.step(4) assert sujeto.pos == Vector(100, 0) a.end(5)
def test_colorize(self): sujeto = Actor('A', color='#0080FF') sch = Scheduler() sch.add_action(actions.Colorize(sujeto, 0, 4, '#FF9000')) frame = sch.next() # Frame 0 to 1, first step self.assertEqual(frame, 1) self.assertEqual(str(sujeto.color), '#4084bf') frame = sch.next() # Frame 1 to 2, second step self.assertEqual(frame, 2) self.assertEqual(str(sujeto.color), '#80887f') frame = sch.next() # Frame 2 to 3, third step self.assertEqual(frame, 3) self.assertEqual(str(sujeto.color), '#bf8c40') frame = sch.next() # Frame 3 to 4, fourth step self.assertEqual(frame, 4) self.assertEqual(str(sujeto.color), '#ff9000')
def create_title(): uid = request.args.get('uid') title_type = request.args.get('title_type') if uid.isnumeric(): if title_type == "movie" or title_type == "tv": prefix = title_type[0:2] else: return {} elif uid[2:].isnumeric(): prefix = uid[0:2] uid = uid[2:] if prefix == "mo": title_type = "movie" elif prefix == "tv": title_type = "tv" else: return {} title = find_title(prefix + uid) if title and 'children_known' in title: return title title_data = get_titles_data([{'uid': uid, "title_type": title_type}]) t = Title(title_data[0]['uid'], title_data[0]['title'], title_data[0]['released'], title_data[0]['title_type']) actors_added = t.add_cast(title_data[0]['cast']) actors = get_actors_data(actors_added) for actor in actors: a = Actor(actor['uid'], actor['name']) a.add_titles(actor['titles']) return redirect(url_for('find_title', uid=title_data[0]['uid']))
def test_calls(): sch = Scheduler() class TestAction(actions.Action): def start(self, frame): self.started_at_frame = frame self.called_on_frames = [] def step(self, frame): self.called_on_frames.append(frame) def end(self, frame): self.ended_at_frame = frame a = Actor('A') task = TestAction(a, 3, 6) sch.add_action(task) for f in range(15): sch.next() assert task.started_at_frame == 3 assert task.ended_at_frame == 6 assert task.called_on_frames == [3, 4, 5]
def create_actor(): uid = request.args.get('uid') uid = uid if uid.isnumeric() else uid[2:] if not uid.isnumeric(): return {} actor = find_actor("na" + uid) if actor and 'children_known' in actor: return actor actor_data = get_actors_data([{'uid': uid}]) a = Actor(actor_data[0]['uid'], actor_data[0]['name']) titles_added = a.add_titles(actor_data[0]['titles']) casts = get_titles_data(titles_added) for cast in casts: t = Title(cast['uid'], cast['title'], cast['released'], cast['title_type']) t.add_cast(cast['cast']) return redirect(url_for('find_actor', uid=actor_data[0]['uid']))
def test_start(): sch = Scheduler() bob = Actor('Bob') sch.add_action(actions.Move(bob, 5, 10, Vector(72, 54))) sch.add_action(actions.Blink(bob, 8, 12)) assert len(sch.active_actions) == 0 # 0 sch.next() assert len(sch.active_actions) == 0 # 1 sch.next() assert len(sch.active_actions) == 0 # 2 sch.next() assert len(sch.active_actions) == 0 # 3 sch.next() assert len(sch.active_actions) == 0 # 4 sch.next() assert len(sch.active_actions) == 0 # 5 sch.next() assert len(sch.active_actions) == 1 # 6 sch.next() assert len(sch.active_actions) == 1 # 7 sch.next() assert len(sch.active_actions) == 1 # 8 sch.next() assert len(sch.active_actions) == 2 # 9 sch.next() assert len(sch.active_actions) == 2 # 10 sch.next() assert len(sch.active_actions) == 1 # 11 sch.next() assert len(sch.active_actions) == 1 # 12 sch.next() assert len(sch.active_actions) == 0 # 13 sch.next() assert len(sch.active_actions) == 0 # 14 sch.next() assert len(sch.active_actions) == 0 # 15
Rect('k4', w=e, h=h, color=blue).offseted(-w / 2 - e, -h - e - w / 2) Rect('k5', w=h, h=e, color=blue).offseted(w / 2 + e, w / 2) Rect('k6', w=h, h=e, color=blue).offseted(w / 2 + e, -w / 2 - e) Rect('k7', w=h, h=e, color=blue).offseted(-h - e - w / 2, w / 2) Rect('k8', w=h, h=e, color=blue).offseted(-h - e - w / 2, -w / 2 - e) Rect('s1', w=h, h=w, color=blue).offseted(-h / 2, -w / 2) Rect('s2', w=w, h=h, color=blue).offseted(-w / 2, -h / 2) #--- ActorS -------------------------------------------------------------------- ''' shapes are added to the scene via an ordered list of Actors and displayed FIFO ''' Actor('b1', shape='b1') Actor('k1', shape='k1') Actor('k2', shape='k2') Actor('k3', shape='k3') Actor('k4', shape='k4') Actor('k5', shape='k5') Actor('k6', shape='k6') Actor('k7', shape='k7') Actor('k8', shape='k8') Actor('s1', shape='s1', vel=Vel(V, 0, 0)) Actor('s2', shape='s2', vel=Vel(0, V, 0)) #Actor('c2', cshapes='pac', peg=dk) # possibly give either 2 or 3 coord or peg TODO #--- RULES --------------------------------------------------------------------
def test_actor_destroyed_not_clashing(self): "Tests that a destroyed actor can't clash, even if it is neighbor of another actor" ator = Actor(2, 2) ator.clash(ator, 0) # clashing actor with itself make its status equals to destroyed ator2 = Actor(2, 2) self.assert_not_clashing(ator, ator2) self.assert_not_clashing(Actor(2, 3), ator) self.assert_not_clashing(Actor(3, 3), ator) self.assert_not_clashing(Actor(3, 2), ator) self.assert_not_clashing(Actor(3, 1), ator) self.assert_not_clashing(Actor(2, 1), ator) self.assert_not_clashing(Actor(1, 1), ator) self.assert_not_clashing(Actor(1, 2), ator) self.assert_not_clashing(Actor(1, 3), ator) self.assert_not_clashing(ator2, ator) self.assert_not_clashing(Actor(2, 3), ator) self.assert_not_clashing(Actor(3, 3), ator) self.assert_not_clashing(Actor(3, 2), ator) self.assert_not_clashing(Actor(3, 1), ator) self.assert_not_clashing(Actor(2, 1), ator) self.assert_not_clashing(Actor(1, 1), ator) self.assert_not_clashing(Actor(1, 2), ator) self.assert_not_clashing(Actor(1, 3), ator)
def test_active_actors_not_neighbors_do_not_clash(self): 'Tests that not neighbors actor does not clash' self.assert_not_clashing(Actor(2, 2), Actor(2, 4)) self.assert_not_clashing(Actor(2, 2), Actor(3, 4)) self.assert_not_clashing(Actor(2, 2), Actor(4, 2)) self.assert_not_clashing(Actor(2, 2), Actor(3, 0)) self.assert_not_clashing(Actor(2, 2), Actor(2, 0)) self.assert_not_clashing(Actor(2, 2), Actor(0, 1)) self.assert_not_clashing(Actor(2, 2), Actor(0, 2)) self.assert_not_clashing(Actor(2, 2), Actor(0, 4))
def test_active_actors_clash_with_non_default_interval(self): # With interval equals to 2, not the default value 1, this clash must occur self.assert_active_actors_clash(Actor(2, 2), Actor(2, 4), 2)
def test_clash_between_active_actors(self): """ Initially actors have ACTIVE status. After clashing it must be changed to DESTROYED assert_active_actors_clash asserts that 2 active actor clash when they are neighbors. """ ator = Actor(2, 2) # Actor created has ACTIVE status ator2 = Actor(2, 2) self.assert_active_actors_clash(ator, ator2) self.assert_active_actors_clash(Actor(2, 2), Actor(2, 3)) self.assert_active_actors_clash(Actor(2, 2), Actor(3, 3)) self.assert_active_actors_clash(Actor(2, 2), Actor(3, 2)) self.assert_active_actors_clash(Actor(2, 2), Actor(3, 1)) self.assert_active_actors_clash(Actor(2, 2), Actor(2, 1)) self.assert_active_actors_clash(Actor(2, 2), Actor(1, 1)) self.assert_active_actors_clash(Actor(2, 2), Actor(1, 2)) self.assert_active_actors_clash(Actor(2, 2), Actor(1, 3))