class TestPMFRecommendation(TestCase):
    """Test the core recommendations task."""
    def setUp(self):
        """Instantiate the resources required for the tests."""
        self.fs = LocalFileSystem(src_dir='tests/test_data')
        self.assertTrue(self.fs.get_name().endswith('tests/test_data'))
        self.pmf_rec = PMFRecommendation(2, data_store=self.fs, num_latent=5)

    def test__find_closest_user_in_training_set(self):
        """Test if we are getting correct "closest user" from the training set."""
        # Full match
        closest = self.pmf_rec._find_closest_user_in_training_set(
            [17190, 14774, 15406, 16594, 29063])
        self.assertIsNotNone(closest)
        # Partial
        closest = self.pmf_rec._find_closest_user_in_training_set(
            [17190, 14774, 15406])
        self.assertIsNotNone(closest)
        # Negative
        closest = self.pmf_rec._find_closest_user_in_training_set([3, 4])
        self.assertIsNone(closest)

    def test__sigmoid(self):
        """Test if the sigmoid function is behaving correctly."""
        self.assertEqual(self.pmf_rec._sigmoid(0), 0.5)

    def test_predict(self):
        """Test the prediction flow."""
        # Test for a new stack.
        missing, recommendation, ptm = self.pmf_rec.predict(['pon-logger'])
        self.assertFalse(missing)
        # Should have two recommendations here.
        self.assertEqual(len(recommendation), 2)

        # Tests for missing package.
        missing, recommendation, _ = self.pmf_rec.predict(
            ['pon-logger', 'missing'])
        self.assertTrue(missing)
        # Test if still getting recommendation as no. of missing = no. of known
        self.assertGreater(len(recommendation), 0)

        missing, _, package_tag_map = self.pmf_rec.predict(['missing'])
        self.assertDictEqual(package_tag_map, {})

        # Test for precomputed stack.
        _, recommendation, _ = self.pmf_rec.predict(
            ['async', 'colors', 'request', 'underscore', 'pkginfo'])
        self.assertTrue(recommendation)
class TestPMFRecommendation(TestCase):
    """Test the core recommendations task."""
    def setUp(self):
        """Instantiate the resources required for the tests."""
        self.fs = LocalDataStore('tests/test_data')
        self.assertTrue(self.fs.get_name().endswith('tests/test_data'))
        self.pmf_rec = PMFRecommendation(2, data_store=self.fs, num_latent=50)

    def test__find_closest_user_in_training_set(self):
        """Test if we are getting correct "closest user" from the training set."""
        # Full match
        closest = self.pmf_rec._find_closest_user_in_training_set(
            [21, 107, 89, 14])
        self.assertIsNotNone(closest)
        # Negative
        closest = self.pmf_rec._find_closest_user_in_training_set(
            [17190, 14774, 15406])
        self.assertIsNone(closest)
        # Partial
        closest = self.pmf_rec._find_closest_user_in_training_set([3, 4])
        self.assertIsNotNone(closest)

    def test__sigmoid(self):
        """Test if the sigmoid function is behaving correctly."""
        self.assertEqual(self.pmf_rec._sigmoid(0), 0.5)

    def test_predict(self):
        """Test the prediction flow."""
        # Test for a new stack.
        missing, recommendation, ptm = self.pmf_rec.predict(["nopt"])
        self.assertFalse(missing)
        # Should have two recommendations here.
        self.assertEqual(len(recommendation), 2)

        # Tests for missing package.
        missing, recommendation, _ = self.pmf_rec.predict(['iferr', 'missing'])
        self.assertTrue(missing)
        # Test if still getting recommendation as no. of missing = no. of known
        self.assertGreater(len(recommendation), 0)

        missing, _, package_tag_map = self.pmf_rec.predict(['missing'])
        self.assertDictEqual(package_tag_map, {})

        # Test for precomputed stack.
        _, recommendation, _ = self.pmf_rec.predict(
            ["statuses", "debuglog", "unpipe"])
        self.assertTrue(recommendation)
class TestPMFRecommendation(TestCase):
    """Test the core recommendations task."""
    def setUp(self):
        """Instantiate the resources required for the tests."""
        self.fs = LocalFileSystem(src_dir='tests/test_data')
        self.pmf_rec = PMFRecommendation(2, data_store=self.fs, num_latent=5)

    def test__find_closest_user_in_training_set(self):
        """Test if we are getting correct "closest user" from the training set."""
        closest = self.pmf_rec._find_closest_user_in_training_set(
            [17190, 14774, 15406, 16594, 29063])
        # Check that closest is not empty
        self.assertIsNotNone(closest)
        # Negative
        closest = self.pmf_rec._find_closest_user_in_training_set([3, 4])
        # should be empty
        self.assertIsNone(closest)

    def test__sigmoid(self):
        """Test if the sigmoid function is behaving correctly."""
        self.assertEqual(self.pmf_rec._sigmoid(0), 0.5)

    def test_predict(self):
        """Test the prediction flow."""
        # Test for a new stack.
        missing, recommendation, ptm = self.pmf_rec.predict(['pon-logger'])
        self.assertFalse(missing)
        # Should have two recommendations here.
        self.assertEqual(len(recommendation), 2)

        # Tests for missing package.
        missing, _, _ = self.pmf_rec.predict(['pon-logger', 'missing'])
        self.assertTrue(missing)

        missing, _, package_tag_map = self.pmf_rec.predict(['missing'])
        self.assertDictEqual(package_tag_map, {})