-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest_Automata.py
52 lines (35 loc) · 1.01 KB
/
Test_Automata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pytest
from Automata import Automaton
from Other import make_random_automaton
COOPERATE = 0
DEFECT = 1
t1 = [[1, 1],
[1, 1]]
def defects(p0):
return Automaton(DEFECT, p0, t1, DEFECT)
t2 = [[0, 0],
[0, 0]]
def cooperates(p0):
return Automaton(COOPERATE, p0, t2, COOPERATE)
t3 = [[0, 1],
[0, 1]]
def tit_for_tat(p0):
return Automaton(COOPERATE, p0, t3, COOPERATE)
t4 = [[0, 1],
[1, 1]]
def grim_trigger(p0):
return Automaton(COOPERATE, p0, t4, COOPERATE)
def test_automata1():
result = defects(0).interact(cooperates(0), 10)
assert result[0].pay() == 40
assert result[1].pay() == 0
def test_automata2():
result = defects(0).interact(tit_for_tat(0), 10)
assert result[0].pay() == 13
assert result[1].pay() == 9
def test_automata3():
result = tit_for_tat(0).interact(defects(0), 10)
assert result[0].pay() == 9
assert result[1].pay() == 13
def test_make_random_automaton():
assert isinstance(make_random_automaton(3), Automaton)