def test_netflix_sample(self):
     """ tests netflix_solve on sample test data """
     reader = StringIO("123:\n1\n2\n3")
     writer = StringIO()
     init(self.actual_ratings, self.movie_averages, self.customer_averages,
          self.customer_year_averages, self.movie_years)
     netflix_solve(reader, writer)
     self.assertEqual(writer.getvalue(),
                      "123:\n2.2\n3.4\n4.1\nRMSE: 0.93\n")
 def test_init2(self):
     """ tests init works on None """
     init(None, None, None, None, None)
     self.assertEqual(None, Netflix.actual_ratings)
     self.assertEqual(None, Netflix.movie_averages)
     self.assertEqual(None, Netflix.customer_averages)
     self.assertEqual(None, Netflix.customer_year_averages)
     self.assertEqual(None, Netflix.movie_years)
     self.assertTrue(Netflix.initialized)
 def test_reset1(self):
     " test that reset() works"
     init(self.actual_ratings, self.movie_averages, self.customer_averages,
          self.customer_year_averages, self.movie_years)
     reset()
     self.assertEqual({}, Netflix.actual_ratings)
     self.assertEqual({}, Netflix.movie_averages)
     self.assertEqual({}, Netflix.customer_averages)
     self.assertEqual({}, Netflix.customer_year_averages)
     self.assertEqual({}, Netflix.movie_years)
     self.assertFalse(Netflix.initialized)
 def test_init1(self):
     """ tests init works on one test caches """
     init(self.actual_ratings, self.movie_averages, self.customer_averages,
          self.customer_year_averages, self.movie_years)
     self.assertEqual(self.actual_ratings, Netflix.actual_ratings)
     self.assertEqual(self.movie_averages, Netflix.movie_averages)
     self.assertEqual(self.customer_averages, Netflix.customer_averages)
     self.assertEqual(self.customer_year_averages,
                      Netflix.customer_year_averages)
     self.assertEqual(self.movie_years, Netflix.movie_years)
     self.assertTrue(Netflix.initialized)
 def test_netflix_all(self):
     """ tests netflix_solve on a test data """
     init(self.actual_ratings, self.movie_averages, self.customer_averages,
          self.customer_year_averages, self.movie_years)
     reader = StringIO(
         "123:\n1\n2\n3\n456:\n1\n2\n3\n789:\n1\n2\n3\n349:\n1\n2\n3\n")
     writer = StringIO()
     netflix_solve(reader, writer)
     self.assertEqual(
         writer.getvalue(),
         "123:\n2.2\n3.4\n4.1\n" + "456:\n2.6\n2.1\n3.6\n" +
         "789:\n2.6\n3.8\n3.9\n" + "349:\n2.5\n2.0\n3.1\n" + "RMSE: 0.78\n")
 def test_check_init2(self):
     """ test check_init works after calling init """
     init(self.actual_ratings, self.movie_averages, self.customer_averages,
          self.customer_year_averages, self.movie_years)
     check_init()  # will pass if check_init does not throw exception
 def test_netflix_eval6(self):
     """ tests netflix_eval on test data """
     init(self.actual_ratings, self.movie_averages, self.customer_averages,
          self.customer_year_averages, self.movie_years)
     prediction = netflix_eval(2, 789)
     self.assertEqual(prediction, 3.8)