-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwampTest.py
57 lines (49 loc) · 2.09 KB
/
SwampTest.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
import unittest
import tools
from swamp import Duck, Shrimp, Newt
class SwampTest(unittest.TestCase):
duck = Duck([20, 20])
duck.set_attributes(7, "egg", 10, 30)
def test_move_to_target(self):
print(f"{self.duck}")
target = [50, 50]
x, y = self.duck.x, self.duck.y
self.duck.move_to_target(target)
x2, y2 = self.duck.x, self.duck.y
origin_dis = tools.manhattan_distance(target, [x, y])
now_dis = tools.manhattan_distance(target, [x2, y2])
self.assertLess(now_dis, origin_dis, "incorrect")
def test_move_away_from(self):
print(f"{self.duck}")
target = [10, 10]
x, y = self.duck.x, self.duck.y
self.duck.move_away_from(target)
x2, y2 = self.duck.x, self.duck.y
print(f"duck moved from position ({x},{y}) to position: "
f"({x2},{y2}) with velocity {self.duck.velocity} ")
origin_dis = tools.manhattan_distance(target, [x, y])
now_dis = tools.manhattan_distance(target, [x2, y2])
self.assertGreater(now_dis, origin_dis, "incorrect")
def test_random_run(self):
print(f"{self.duck}")
x, y = self.duck.x, self.duck.y
self.duck.random_run()
x2, y2 = self.duck.x, self.duck.y
print(f"duck moved from position ({x},{y}) to position: "
f"({x2},{y2}) with velocity {self.duck.velocity} ")
dis = tools.manhattan_distance([x2, y2], [x, y])
self.assertLess(dis, self.duck.velocity, "incorrect")
def test_search_nearst_target(self):
print(f"{self.duck}")
pos_list = [[0, 0], [1, 1], [20, 26], [22, 23]]
x, y = self.duck.x, self.duck.y
pos = self.duck.search_nearst_target(pos_list)
self.assertEqual(pos, [22, 23], "incorrect")
def test_under_one_step(self):
print(f"{self.duck}")
pos = [20, 30]
x, y = self.duck.x, self.duck.y
result = self.duck.under_one_step(pos)
self.assertTrue(result, "incorrect")
dis = tools.manhattan_distance(pos, [x, y])
self.assertLessEqual(dis, self.duck.velocity, "incorrect")