示例#1
0
    def test_Thresholds(self):
        r1_text = 'licensed under the GPL, licensed under the GPL'
        r1 = models.Rule(text_file='r1', license_expression='apache-1.1', stored_text=r1_text)
        r2_text = 'licensed under the GPL, licensed under the GPL' * 10
        r2 = models.Rule(text_file='r1', license_expression='apache-1.1', stored_text=r2_text)
        _idx = index.LicenseIndex([r1, r2])

        results = models.compute_thresholds_occurences(r1.minimum_coverage, r1.length, r1.high_length)
        expected_min_cov = 80
        expected_min_matched_length = 8
        expected_min_high_matched_length = 4
        expected = expected_min_cov, expected_min_matched_length, expected_min_high_matched_length
        assert results == expected

        results = models.compute_thresholds_unique(
            r1.minimum_coverage, r1.length, r1.length_unique, r1.high_length_unique)

        expected_min_matched_length_unique = 3
        expected_min_high_matched_length_unique = 2
        expected = expected_min_matched_length_unique, expected_min_high_matched_length_unique
        assert results == expected

        results = models.compute_thresholds_occurences(r2.minimum_coverage, r2.length, r2.high_length)
        expected_min_cov = 0.0
        expected_min_matched_length = 4
        expected_min_high_matched_length = 3
        expected = expected_min_cov, expected_min_matched_length, expected_min_high_matched_length
        assert results == expected

        results = models.compute_thresholds_unique(
            r2.minimum_coverage, r2.length, r2.length_unique, r2.high_length_unique)
        expected_min_matched_length_unique = 4
        expected_min_high_matched_length_unique = 1
        expected = expected_min_matched_length_unique, expected_min_high_matched_length_unique
        assert results == expected
示例#2
0
    def test_compute_thresholds_occurences(self):
        minimum_coverage = 0.0
        length = 54
        high_length = 11

        results = models.compute_thresholds_occurences(minimum_coverage, length, high_length)
        expected_min_cov = 0.0
        expected_min_matched_length = 4
        expected_min_high_matched_length = 3
        expected = expected_min_cov, expected_min_matched_length, expected_min_high_matched_length
        assert results == expected

        length_unique = 39
        high_length_unique = 7

        results = models.compute_thresholds_unique(
            minimum_coverage, length, length_unique, high_length_unique)
        expected_min_matched_length_unique = 4
        expected_min_high_matched_length_unique = 3
        expected = expected_min_matched_length_unique, expected_min_high_matched_length_unique
        assert results == expected