def test_solve_format(self): """Tests that solve print the same movie ids on the right line""" reader = StringIO("1:\n30878\n10016:\n1751359\n234929\n") writer = StringIO() solve(reader, writer) line = writer.getvalue().split('\n', 5) self.assertEqual(line[0], "1:") self.assertEqual(line[2], "10016:")
def test_solve_1(self): fout = StringIO() fin = StringIO('1:\n1') movieratings = {1: 1} customeraverages = {1: {1: 1}} actual = {1: {1: 1}} totaverage = 1 movieyears = {1: 1} solve(fin, fout, actual, movieratings, customeraverages, totaverage, movieyears) self.assertEqual(fout.getvalue(), '1:\n3.0\nRMSE: 2.00\n')
def test_solve_format_2(self): """Tests that solve prints predictions in the right format""" reader = StringIO("1:\n30878\n10016:\n1751359\n234929\n") writer = StringIO() solve(reader, writer) line = writer.getvalue().split('\n', 5) for line_number in (1, 3, 4): self.assertEqual(len(line[line_number]), 3) self.assertTrue(line[line_number][0].isdigit()) self.assertEqual(line[line_number][1], ".") self.assertTrue(line[line_number][2].isdigit())
def test_solve_format_3(self): """Tests that solve prints RMSE in the right format""" reader = StringIO("1:\n30878\n10016:\n1751359\n234929\n") writer = StringIO() solve(reader, writer) line = writer.getvalue().split('\n', 5) self.assertEqual(len(line[5]), 11) self.assertEqual(line[5][:6], "RMSE: ") self.assertTrue(line[5][6].isdigit()) self.assertEqual(line[5][7], ".") self.assertTrue(line[5][8].isdigit()) self.assertTrue(line[5][9].isdigit())
def test_solve_3(self): r = StringIO.StringIO("10045:\n2314434\n") w = StringIO.StringIO() solve(r, w) self.assert_(w.getvalue() == "RMSE = 0.983460336694\n10045:\n3.7\n")
def test_solve_2(self): r = StringIO.StringIO("10010:\n1462925\n52050\n") w = StringIO.StringIO() solve(r, w) self.assert_(w.getvalue() == "RMSE = 0.983460336694\n10010:\n2.4\n2.2\n")
def test_solve_1(self): r = StringIO.StringIO("1001:\n1050889\n67976\n") w = StringIO.StringIO() solve(r, w) self.assert_(w.getvalue() == "RMSE = 0.983460336694\n1001:\n4.5\n3.5\n")
#!/usr/bin/env python """ To run the program % python RunNetflix.py < RunNetflix.in > RunNetflix.out % chmod ugo+x RunNetflix.py % RunNetflix.py < RunNetflix.in > RunNetflix.out To document the program % pydoc -w Netflix """ # ------- # imports # ------- import sys from Netflix import solve # ---- # main # ---- solve(sys.stdin, sys.stdout)
def test_solve_3 (self) : r = StringIO.StringIO("10045:\n2314434\n") w = StringIO.StringIO() solve(r, w) self.assert_(w.getvalue() == "RMSE = 0.983460336694\n10045:\n3.7\n")
def test_solve_2 (self) : r = StringIO.StringIO("10010:\n1462925\n52050\n") w = StringIO.StringIO() solve(r, w) self.assert_(w.getvalue() == "RMSE = 0.983460336694\n10010:\n2.4\n2.2\n")
def test_solve_1 (self) : r = StringIO.StringIO("1001:\n1050889\n67976\n") w = StringIO.StringIO() solve(r, w) self.assert_(w.getvalue() == "RMSE = 0.983460336694\n1001:\n4.5\n3.5\n")