-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_rec.py
58 lines (42 loc) · 1.5 KB
/
test_rec.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
import unittest
from flask import Flask
import config, rec
from model import (Repo, User, Follower, Account,
Stargazer, Dislike,
Watcher, Contributor,
Language, RepoLanguage,
db, connect_to_db)
from test_model import example_data
app = Flask(__name__)
class TestRec(unittest.TestCase):
"""Test rec functions that use the DB."""
def setUp(self):
"""Connect to database, create tables, generate test data."""
self.client = app.test_client()
app.config["TESTING"] = True
connect_to_db(app, config.TEST_DB_URI)
db.drop_all()
db.create_all()
example_data()
# update_pkey_seqs.update_pkey_seqs()
def tearDown(self):
"""Close session, drop db."""
db.session.close()
db.drop_all()
def test_build_ratings_dataframe(self):
M = [[1, -1], [1, 1]]
R = rec.build_ratings_dataframe().as_matrix().tolist()
self.assertEqual(R, M)
def test_build_repo_predictions_matrix(self):
M = [[1, -1], [1, 1]]
preds = rec.build_repo_predictions_matrix().as_matrix().tolist()
self.assertEqual(preds, M)
def test_get_repo_suggestions(self):
M = [2, 1]
preds = rec.get_repo_suggestions(2)
self.assertEqual(preds, M)
def test_compare_recs(self):
ratio = rec.compare_recs(2, 3)
self.assertEqual(ratio, 1)
if __name__ == "__main__":
unittest.main()