-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestNetflix.py
92 lines (70 loc) · 2.02 KB
/
TestNetflix.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
#!/usr/bin/env python3
# -------------------------------
# projects/collatz/TestCollatz.py
# Copyright (C) 2015
# Glenn P. Downing
# -------------------------------
# https://docs.python.org/3.4/reference/simple_stmts.html#grammar-token-assert_stmt
# -------
# imports
# -------
from io import StringIO
from unittest import main, TestCase
from Netflix import netflix_solve, rmse
# -----------
# TestNetflix
# -----------
class TestNetflix (TestCase) :
# ----
# rmse
# ----
def test_rmse1 (self) :
i = [1, 1, 1]
j = [1, 1, 1]
k = rmse(i, j)
self.assertEqual(0, k)
def test_rmse2 (self) :
i = [1, 2, 3]
j = [1, 1, 1]
k = rmse(i, j)
self.assertEqual(1.29, k)
def test_rmse3 (self) :
i = [-15, -100, 1000]
j = [1, 1, 1]
k = rmse(i, j)
self.assertEqual(579.79, k)
def test_rmse4 (self) :
i = [15, 1, -1]
j = [15, 1, 1]
k = rmse(i, j)
self.assertEqual(1.15, k)
def test_rmse5 (self) :
i = [12, 14, 16]
j = [13, 15, 17]
k = rmse(i, j)
self.assertEqual(1, k)
# -------------
# netflix_solve
# -------------
def test_solve (self) :
r = StringIO("1:\n30878\n2647871\n1283744\n2488120\n")
w = StringIO()
netflix_solve(r,w)
self.assertEqual(w.getvalue(), "1:\n3.7\n3.5\n3.6\n4.7\nRMSE: 0.46\n")
if __name__ == "__main__" :
main()
"""
% coverage3 run --branch TestNetflix.py > TestNetflix.out 2>&1
% coverage3 report -m >> TestNetflix.out
% cat TestNetflix.out
.......
----------------------------------------------------------------------
Ran 7 tests in 0.001s
OK
Name Stmts Miss Branch BrMiss Cover Missing
---------------------------------------------------------
Netflix 18 0 6 0 100%
TestNetflix 33 1 2 1 94% 79
---------------------------------------------------------
TOTAL 51 1 8 1 97%
"""