-
Notifications
You must be signed in to change notification settings - Fork 0
/
hrbb_unittest.py
executable file
·88 lines (79 loc) · 2.38 KB
/
hrbb_unittest.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
#!/usr/bin/env python
import unittest
from hrbb import *
i1 = Item(100,2000)
i2 = Item(100,2000)
i3 = Item(300,300)
i4 = Item(400,400)
class TestSequenceFunctions(unittest.TestCase):
def test_one(self):
pool = [i1]
N = len(pool)
W = 1000
L = 3000
S = sum([s.value() for s in pool])
r = Segment(L,W,0,0)
items = copy.copy(pool)
vmax,success = r.layout(pool, S, 0, 0)
for p in pool:
items.remove(p)
self.assertEqual(N,len(items))
self.assertTrue(r.contains(items))
def test_fail(self):
pool = [i1]
N = len(pool)
W = 1000
L = 1000
S = sum([s.value() for s in pool])
r = Segment(L,W,0,0)
items = copy.copy(pool)
vmax,success = r.layout(pool, S, 0, 0)
for p in pool:
items.remove(p)
self.assertNotEqual(N,len(items))
self.assertFalse(success)
def test_normal(self):
pool = [i1,i2]
N = len(pool)
W = 1000
L = 3000
S = sum([s.value() for s in pool])
r = Segment(L,W,0,0)
items = copy.copy(pool)
vmax,success = r.layout(pool, S, 0, 0)
for p in pool:
items.remove(p)
self.assertEqual(N,len(items))
self.assertTrue(r.contains(items))
self.assertFalse(overlap(items))
def test_rotated(self):
pool = [i1,i2]
N = len(pool)
W = 3000
L = 1000
S = sum([s.value() for s in pool])
r = Segment(L,W,0,0)
items = copy.copy(pool)
vmax,success = r.layout(pool, S, 0, 0)
for p in pool:
items.remove(p)
self.assertEqual(N,len(items))
self.assertTrue(r.contains(items))
self.assertFalse(overlap(items))
def test_three(self):
# a test case which asserts a bug
pool = [Item(1540,700),Item(650,1502),Item(301,762),]
N = len(pool)
W = 1830
L = 1540
S = sum([s.value() for s in pool])
r = Segment(L,W,0,0)
items = copy.copy(pool)
vmax,success = r.layout(pool, S, 0, 0)
for p in pool:
items.remove(p)
self.assertEqual(N,len(items))
self.assertTrue(r.contains(items))
self.assertFalse(overlap(items))
if __name__ == '__main__':
unittest.main()