File size: 2,711 Bytes
e70050b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import unittest
import sys
import os

# Point to parent directory (MonCode) so we can import 'syscred' package
# Current file is in MonCode/syscred/test_suite.py
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from syscred.verification_system import CredibilityVerificationSystem
from syscred.api_clients import ExternalAPIClients

class TestSysCRED(unittest.TestCase):
    
    @classmethod
    def setUpClass(cls):
        print("\n[TestSysCRED] Setting up system...")
        cls.system = CredibilityVerificationSystem(load_ml_models=False)
        cls.client = cls.system.api_clients
        
    def test_backlink_estimation_heuristic(self):
        """Test that backlink estimation respects reputation."""
        lemonde = self.client.estimate_backlinks("https://www.lemonde.fr")
        infowars = self.client.estimate_backlinks("https://infowars.com")
        
        self.assertGreater(lemonde['estimated_count'], infowars['estimated_count'], 
                           "High reputation should have more backlinks than Low")
        self.assertEqual(lemonde['method'], 'heuristic_v2.1')

    def test_coherence_heuristic(self):
        """Test coherence scoring heuristic."""
        good_text = "This is a coherent sentence. It follows logically."
        bad_text = "This is. Random words. Banana. Cloud."
        
        score_good = self.system._calculate_coherence(good_text)
        score_bad = self.system._calculate_coherence(bad_text)
        
        self.assertTrue(0 <= score_good <= 1)
        # Note: Heuristic using sentence length variance might be sensitive
        # bad_text has very short sentences, so average length is small -> penalty
        # good_text has normal length
        self.assertGreaterEqual(score_good, score_bad, "Coherent text should score >= incoherent")

    def test_bias_heuristic(self):
        """Test bias detection heuristic."""
        neutral = "The economy grew by 2%."
        biased = "The radical corrupt regime is destroying us!"
        
        res_neutral = self.system._analyze_bias(neutral)
        res_biased = self.system._analyze_bias(biased)
        
        self.assertLess(res_neutral['score'], res_biased['score'])
        self.assertIn("biased", res_biased['label'].lower())

    def test_full_pipeline(self):
        """Test the full verification pipeline (integration test)."""
        input_data = "https://www.example.com"
        result = self.system.verify_information(input_data)
        
        self.assertIn('scoreCredibilite', result)
        self.assertIn('resumeAnalyse', result)
        self.assertIsNotNone(result['scoreCredibilite'])

if __name__ == '__main__':
    unittest.main()