Esempio n. 1
0
def test_get_lr(test_ctx):
    # Tests that the likelihood ratio values are not empty for extreme values and are realistic.
    with mock_install_continuous_data(test_ctx):
        r = SimilarityRecommender(test_ctx)
        cache = r._get_cache({})
        assert r.get_lr(0.0001, cache) is not None
        assert r.get_lr(10.0, cache) is not None
        assert r.get_lr(0.001, cache) > r.get_lr(5.0, cache)
Esempio n. 2
0
def test_compute_clients_dist(test_ctx):
    # Test the distance function computation.
    with mock_install_continuous_data(test_ctx):
        r = SimilarityRecommender(test_ctx)
        test_clients = [
            {
                "client_id": "test-client-002",
                "activeAddons": [],
                "geo_city": "sfo-us",
                "subsession_length": 1,
                "locale": "en-US",
                "os": "windows",
                "bookmark_count": 1,
                "tab_open_count": 1,
                "total_uri": 1,
                "unique_tlds": 1,
            },
            {
                "client_id": "test-client-003",
                "activeAddons": [],
                "geo_city": "brasilia-br",
                "subsession_length": 1,
                "locale": "br-PT",
                "os": "windows",
                "bookmark_count": 10,
                "tab_open_count": 1,
                "total_uri": 1,
                "unique_tlds": 1,
            },
            {
                "client_id": "test-client-004",
                "activeAddons": [],
                "geo_city": "brasilia-br",
                "subsession_length": 100,
                "locale": "br-PT",
                "os": "windows",
                "bookmark_count": 10,
                "tab_open_count": 10,
                "total_uri": 100,
                "unique_tlds": 10,
            },
        ]
        per_client_test = []

        # Compute a different set of distances for each set of clients.
        cache = r._get_cache({})
        for tc in test_clients:
            test_distances = r.compute_clients_dist(tc, cache)
            assert len(test_distances) == len(CONTINUOUS_FEATURE_FIXTURE_DATA)
            per_client_test.append(test_distances[2][0])

        # Ensure the different clients also had different distances to a specific donor.
        assert per_client_test[0] >= per_client_test[1] >= per_client_test[2]