-
Notifications
You must be signed in to change notification settings - Fork 0
/
domaca_naloga_3_1_2018.py.py
177 lines (154 loc) · 5.14 KB
/
domaca_naloga_3_1_2018.py.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import unittest
from math import sqrt
class Minobot:
def __init__(self):
self.smer = 90
self.prejsnja_smer = 0
self.prejsnji_ukaz = ""
self.prejsnji_premik = 0
self.x = 0
self.y = 0
def koordinate(self):
return (self.x, self.y)
def razdalja(self):
return sqrt((self.x**2)+(self.y**2))
def desno(self):
if self.smer == 360:
self.smer = 90
else:
self.smer += 90
def levo(self):
if self.smer == 90:
self.smer = 360
else:
self.smer -= 90
def naprej(self, ukaz):
if self.smer == 90:
self.x += ukaz
elif self.smer == 270:
self.y -= ukaz
elif ukaz == 360:
self.y += ukaz
else:
self.y -= ukaz
a = Minobot()
a.desno()
a.naprej(-3)
print(a.koordinate())
class TestObvezna(unittest.TestCase):
def test_minobot(self):
a = Minobot()
b = Minobot()
self.assertEqual(a.koordinate(), (0, 0))
self.assertEqual(b.koordinate(), (0, 0))
self.assertEqual(a.razdalja(), 0)
self.assertEqual(b.razdalja(), 0)
print(a.koordinate(), a.smer)
print(b.koordinate(), b.smer)
a.naprej(1)
self.assertEqual(a.koordinate(), (1, 0))
self.assertEqual(b.koordinate(), (0, 0))
self.assertEqual(a.razdalja(), 1)
self.assertEqual(b.razdalja(), 0)
a.naprej(2)
self.assertEqual(a.koordinate(), (3, 0))
self.assertEqual(b.koordinate(), (0, 0))
self.assertEqual(a.razdalja(), 3)
self.assertEqual(b.razdalja(), 0)
b.naprej(2)
self.assertEqual(a.koordinate(), (3, 0))
self.assertEqual(b.koordinate(), (2, 0))
self.assertEqual(a.razdalja(), 3)
self.assertEqual(b.razdalja(), 2)
a.desno() # zdaj je obrnjen dol
a.naprej(4)
self.assertEqual(a.koordinate(), (3, -4))
self.assertEqual(b.koordinate(), (2, 0))
self.assertEqual(a.razdalja(), 7)
self.assertEqual(b.razdalja(), 2)
a.desno() # obrnjen je levo
a.naprej(1)
self.assertEqual(a.koordinate(), (2, -4))
self.assertEqual(b.koordinate(), (2, 0))
self.assertEqual(a.razdalja(), 6)
self.assertEqual(b.razdalja(), 2)
a.desno() # obrnjen je gor
a.naprej(1)
self.assertEqual(a.koordinate(), (2, -3))
self.assertEqual(b.koordinate(), (2, 0))
self.assertEqual(a.razdalja(), 5)
self.assertEqual(b.razdalja(), 2)
a.desno() # obrnjen desno
a.naprej(3)
self.assertEqual(a.koordinate(), (5, -3))
self.assertEqual(b.koordinate(), (2, 0))
self.assertEqual(a.razdalja(), 8)
self.assertEqual(b.razdalja(), 2)
b.levo() # obrnjen gor
b.naprej(3)
self.assertEqual(b.koordinate(), (2, 3))
self.assertEqual(b.razdalja(), 5)
b.levo() # obrnjen levo
b.naprej(3)
self.assertEqual(b.koordinate(), (-1, 3))
self.assertEqual(b.razdalja(), 4)
a.naprej(5)
self.assertEqual(a.koordinate(), (10, -3))
self.assertEqual(a.razdalja(), 13)
'''
class TestDodatna(unittest.TestCase):
def test_undo(self):
a = Minobot()
a.desno() # gleda dol
a.naprej(4)
a.levo() # gleda desno
a.naprej(1)
a.naprej(2)
self.assertEqual(a.koordinate(), (3, -4))
a.razveljavi()
self.assertEqual(a.koordinate(), (1, -4))
a.naprej(1)
self.assertEqual(a.koordinate(), (2, -4))
a.razveljavi()
self.assertEqual(a.koordinate(), (1, -4))
a.razveljavi()
self.assertEqual(a.koordinate(), (0, -4))
a.naprej(1)
self.assertEqual(a.koordinate(), (1, -4))
a.razveljavi()
self.assertEqual(a.koordinate(), (0, -4))
a.razveljavi() # spet gleda dol
self.assertEqual(a.koordinate(), (0, -4))
a.naprej(2)
self.assertEqual(a.koordinate(), (0, -6))
a.razveljavi()
self.assertEqual(a.koordinate(), (0, -4))
a.razveljavi()
self.assertEqual(a.koordinate(), (0, 0))
a.naprej(3)
self.assertEqual(a.koordinate(), (0, -3))
a.razveljavi()
self.assertEqual(a.koordinate(), (0, 0))
a.razveljavi() # spet gleda desno
self.assertEqual(a.koordinate(), (0, 0))
a.naprej(3)
self.assertEqual(a.koordinate(), (3, 0))
a.razveljavi()
self.assertEqual(a.koordinate(), (0, 0))
a.razveljavi() # se ne usuje
self.assertEqual(a.koordinate(), (0, 0))
a.naprej(2)
self.assertEqual(a.koordinate(), (2, 0))
a.razveljavi()
self.assertEqual(a.koordinate(), (0, 0))
a.razveljavi() # se ne usuje
self.assertEqual(a.koordinate(), (0, 0))
a.razveljavi() # se ne usuje
self.assertEqual(a.koordinate(), (0, 0))
a.razveljavi() # se ne usuje
self.assertEqual(a.koordinate(), (0, 0))
a.razveljavi() # se ne usuje
self.assertEqual(a.koordinate(), (0, 0))
'''
if __name__ == "__main__":
unittest.main()