webpage_quality_analyzer 1.0.2

High-performance webpage quality analyzer with 115 comprehensive metrics - Rust library with WASM, C++, and Python bindings
Documentation
//! Score Differentiation Validation Tests
//! Updated for Phase 3 Profile-Aware Scoring System

use webpage_quality_analyzer::analyze;

const LOGIN: &str = "<html><head><title>Login</title></head><body><form><input type=text><input type=password><button>Login</button></form></body></html>";
const ARTICLE: &str = "<html lang=en><head><title>Complete Web Development Guide Best Practices Modern Techniques</title><meta name=description content='Comprehensive guide'><meta charset=UTF-8></head><body><article><h1>Web Development</h1><p>Modern web development requires understanding multiple technologies. This guide explores essential concepts every developer should master.</p><h2>Frontend</h2><p>Frontend development encompasses HTML CSS and JavaScript. Modern frameworks like React Vue and Angular have revolutionized interfaces. Component-based architecture promotes reusability and maintainability.</p><h2>Backend</h2><p>Server-side development handles data processing business logic and database operations. RESTful APIs provide standardized communication. GraphQL offers flexible querying.</p><h2>Performance</h2><p>Page load speed impacts user experience and conversion rates. Code splitting reduces bundle sizes. Lazy loading defers resources. Image optimization reduces bandwidth.</p><h2>Security</h2><p>Web security protects user data and maintains integrity. HTTPS encryption secures data. Content Security Policy prevents attacks. Input validation protects against injection.</p><h2>Testing</h2><p>Testing ensures code quality and prevents regressions. Unit tests verify component behavior. Integration tests validate interactions. End-to-end tests simulate workflows.</p><h2>Deployment</h2><p>Modern deployment practices enable rapid reliable releases. Continuous integration automates builds. Continuous deployment releases to production.</p><h2>Conclusion</h2><p>Web development evolves constantly. Mastering fundamentals while staying current enables building robust scalable applications.</p></article></body></html>";

#[tokio::test]
async fn test_login_low_score() {
    let r = analyze("https://t.co/l", Some(LOGIN)).await.unwrap();
    println!("\nLogin score: {:.2}", r.score);
    // Phase 3 scoring is stricter - login pages score very low due to minimal content
    assert!(r.score < 5.0, "Expected < 5.0, got {:.2}", r.score);
}

#[tokio::test]
async fn test_article_high_score() {
    let r = analyze("https://t.co/a", Some(ARTICLE)).await.unwrap();
    println!("\nArticle score: {:.2}", r.score);
    // Phase 3 scoring - expect modest score for decent article (10-20 range is realistic)
    assert!(r.score > 10.0, "Expected > 10.0, got {:.2}", r.score);
}

#[tokio::test]
async fn test_dramatic_difference() {
    let l = analyze("https://t.co/l", Some(LOGIN)).await.unwrap();
    let a = analyze("https://t.co/a", Some(ARTICLE)).await.unwrap();
    let d = a.score - l.score;
    println!(
        "\nLogin: {:.2}, Article: {:.2}, Diff: {:.2}",
        l.score, a.score, d
    );
    // Phase 3 scoring - expect at least 10 point difference
    assert!(d > 10.0, "Expected diff > 10.0, got {:.2}", d);
}

#[tokio::test]
async fn test_summary() {
    println!("\n=== VALIDATION SUMMARY (Phase 3 Scoring) ===");
    let l = analyze("https://t.co/l", Some(LOGIN)).await.unwrap();
    let a = analyze("https://t.co/a", Some(ARTICLE)).await.unwrap();
    let d = a.score - l.score;

    let r1 = l.score < 5.0;
    let r2 = a.score > 10.0;
    let r3 = d > 10.0;

    println!(
        "Login < 5:    {} ({:.2})",
        if r1 { "PASS" } else { "FAIL" },
        l.score
    );
    println!(
        "Article > 10: {} ({:.2})",
        if r2 { "PASS" } else { "FAIL" },
        a.score
    );
    println!(
        "Diff > 10:    {} ({:.2})",
        if r3 { "PASS" } else { "FAIL" },
        d
    );

    assert!(r1 && r2 && r3, "All must pass");
    println!("ALL REQUIREMENTS MET!");
}