-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_multi_neighbors.py
70 lines (56 loc) · 3.14 KB
/
test_multi_neighbors.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
import unittest
import multi_neighbors
class PseudoArticlesGenerator():
def __init__(self, settings=None, articles=None):
self.settings = settings or {}
self.articles = articles or []
class PseudoArticle():
def __init__(self, title=''):
self.title = title
def __repr__(self):
return f'{self.__class__.__name__}({self.title})'
class NeighborsTestCase(unittest.TestCase):
def setUp(self):
self.generator = PseudoArticlesGenerator(
settings={'MULTI_NEIGHBORS': 3},
articles=[
PseudoArticle('article6-newest'), # List position 0.
PseudoArticle('article5'), # List position 1.
PseudoArticle('article4'), # List position 2.
PseudoArticle('article3'), # List position 3.
PseudoArticle('article2'), # List position 4.
PseudoArticle('article1'), # List position 5.
PseudoArticle('article0-oldest'), # List position 6.
])
multi_neighbors.neighbors(self.generator)
def test_prev_next(self):
# Test prev articles.
self.assertTrue(self.generator.articles[0].prev_articles ==
[self.generator.articles[1], self.generator.articles[2], self.generator.articles[3]])
self.assertTrue(self.generator.articles[1].prev_articles ==
[self.generator.articles[2], self.generator.articles[3], self.generator.articles[4]])
self.assertTrue(self.generator.articles[2].prev_articles ==
[self.generator.articles[3], self.generator.articles[4], self.generator.articles[5]])
self.assertTrue(self.generator.articles[3].prev_articles ==
[self.generator.articles[4], self.generator.articles[5], self.generator.articles[6]])
self.assertTrue(self.generator.articles[4].prev_articles ==
[self.generator.articles[5], self.generator.articles[6]])
self.assertTrue(self.generator.articles[5].prev_articles ==
[self.generator.articles[6]])
self.assertFalse(self.generator.articles[6].prev_articles)
# Test next articles.
self.assertFalse(self.generator.articles[0].next_articles)
self.assertTrue(self.generator.articles[1].next_articles ==
[self.generator.articles[0]])
self.assertTrue(self.generator.articles[2].next_articles ==
[self.generator.articles[1], self.generator.articles[0]])
self.assertTrue(self.generator.articles[3].next_articles ==
[self.generator.articles[2], self.generator.articles[1], self.generator.articles[0]])
self.assertTrue(self.generator.articles[4].next_articles ==
[self.generator.articles[3], self.generator.articles[2], self.generator.articles[1]])
self.assertTrue(self.generator.articles[5].next_articles ==
[self.generator.articles[4], self.generator.articles[3], self.generator.articles[2]])
self.assertTrue(self.generator.articles[6].next_articles ==
[self.generator.articles[5], self.generator.articles[4], self.generator.articles[3]])
if __name__ == '__main__':
unittest.main()