reasonkit-core 0.1.8

The Reasoning Engine — Auditable Reasoning for Production AI | Rust-Native | Turn Prompts into Protocols
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
//! # Toulmin Argumentation Model
//!
//! Implements the Toulmin model of argumentation for structured reasoning.
//! Based on Stephen Toulmin's "The Uses of Argument" (1958).
//!
//! ## Scientific Foundation
//!
//! - Toulmin (1958): The Uses of Argument - foundational argumentation theory
//! - NL2FOL (arXiv:2405.02318): Achieves 78-80% F1 on fallacy detection
//!
//! ## The Six Components
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────────┐
//! │                    TOULMIN ARGUMENT MODEL                          │
//! ├─────────────────────────────────────────────────────────────────────┤
//! │                                                                     │
//! │   GROUNDS ──────────► WARRANT ──────────► CLAIM                    │
//! │   (Evidence)           (Connection)        (Conclusion)            │
//! │       ▲                    │                   ▲                   │
//! │       │                    ▼                   │                   │
//! │       │               BACKING             QUALIFIER                │
//! │       │           (Support for           (Strength)                │
//! │       │             warrant)                 │                     │
//! │       │                                      ▼                     │
//! │       └──────────────────────────────── REBUTTAL                  │
//! │                                       (Exceptions)                 │
//! └─────────────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Usage
//!
//! ```rust,ignore
//! use reasonkit::thinktool::toulmin::{ToulminArgument, ArgumentBuilder};
//!
//! let argument = ArgumentBuilder::new()
//!     .claim("AI will transform education")
//!     .grounds("Studies show 40% improvement in learning outcomes")
//!     .warrant("Personalized learning leads to better outcomes")
//!     .backing("Meta-analysis of 200 educational AI studies")
//!     .qualifier(Qualifier::Probably)
//!     .rebuttal("Unless access inequality persists")
//!     .build()?;
//!
//! let evaluation = argument.evaluate()?;
//! ```

use serde::{Deserialize, Serialize};

/// The six components of a Toulmin argument
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToulminArgument {
    /// The assertion being made
    pub claim: Claim,
    /// Evidence supporting the claim
    pub grounds: Vec<Ground>,
    /// Logical bridge from grounds to claim
    pub warrant: Option<Warrant>,
    /// Support for the warrant itself
    pub backing: Vec<Backing>,
    /// Strength/certainty modifier
    pub qualifier: Qualifier,
    /// Conditions that would invalidate the claim
    pub rebuttals: Vec<Rebuttal>,
}

/// The main claim/conclusion of the argument
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Claim {
    /// The assertion text
    pub statement: String,
    /// Type of claim
    pub claim_type: ClaimType,
    /// Scope of the claim
    pub scope: Scope,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ClaimType {
    /// Statement of fact
    Fact,
    /// Value judgment
    Value,
    /// Proposed action/policy
    Policy,
    /// Predicted outcome
    Prediction,
    /// Causal relationship
    Causal,
    /// Definition or classification
    Definition,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Scope {
    /// Applies to all cases
    Universal,
    /// Applies to most cases
    General,
    /// Applies to some cases
    Particular,
    /// Applies to specific case
    Singular,
}

/// Evidence/data supporting the claim
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ground {
    /// The evidence statement
    pub evidence: String,
    /// Type of evidence
    pub evidence_type: EvidenceType,
    /// Source of the evidence
    pub source: Option<String>,
    /// Credibility score (0.0-1.0)
    pub credibility: f32,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum EvidenceType {
    /// Statistical data
    Statistical,
    /// Expert testimony
    Testimonial,
    /// Concrete example
    Example,
    /// Documentary evidence
    Documentary,
    /// Physical/empirical evidence
    Empirical,
    /// Common knowledge
    CommonGround,
    /// Analogical reasoning
    Analogical,
}

/// Logical principle connecting grounds to claim
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Warrant {
    /// The principle/rule being invoked
    pub principle: String,
    /// Type of warrant
    pub warrant_type: WarrantType,
    /// Whether this is explicit or implicit
    pub is_explicit: bool,
    /// Strength of the warrant
    pub strength: f32,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum WarrantType {
    /// Based on authority
    Authority,
    /// Based on cause-effect
    Causal,
    /// Based on classification
    Classification,
    /// Based on signs/indicators
    Sign,
    /// Based on comparison
    Comparison,
    /// Based on generalization
    Generalization,
    /// Based on principle/rule
    Principle,
}

/// Support for the warrant itself
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Backing {
    /// The supporting statement
    pub support: String,
    /// Type of backing
    pub backing_type: BackingType,
    /// Source if applicable
    pub source: Option<String>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum BackingType {
    /// Legal or regulatory
    Legal,
    /// Scientific research
    Scientific,
    /// Historical precedent
    Historical,
    /// Cultural norm
    Cultural,
    /// Expert consensus
    Consensus,
}

/// Qualifier - degree of certainty
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Qualifier {
    /// Certainly true (100%)
    Certainly,
    /// Very likely (90%+)
    Presumably,
    /// Probably (70%+)
    Probably,
    /// Possibly (50%+)
    Possibly,
    /// Unlikely (<50%)
    Unlikely,
    /// Qualified by specific condition
    Conditionally,
}

impl Qualifier {
    pub fn confidence(&self) -> f32 {
        match self {
            Qualifier::Certainly => 0.99,
            Qualifier::Presumably => 0.90,
            Qualifier::Probably => 0.75,
            Qualifier::Possibly => 0.50,
            Qualifier::Unlikely => 0.25,
            Qualifier::Conditionally => 0.60,
        }
    }

    pub fn label(&self) -> &'static str {
        match self {
            Qualifier::Certainly => "certainly",
            Qualifier::Presumably => "presumably",
            Qualifier::Probably => "probably",
            Qualifier::Possibly => "possibly",
            Qualifier::Unlikely => "unlikely",
            Qualifier::Conditionally => "if conditions hold",
        }
    }
}

/// Conditions that would invalidate the claim
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Rebuttal {
    /// The exception/condition
    pub exception: String,
    /// How likely is this exception
    pub likelihood: f32,
    /// Severity if exception occurs
    pub severity: RebuttalSeverity,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum RebuttalSeverity {
    /// Minor qualification
    Minor,
    /// Moderate impact
    Moderate,
    /// Major impact on claim
    Major,
    /// Completely defeats claim
    Fatal,
}

/// Builder for constructing Toulmin arguments
#[derive(Debug, Default)]
pub struct ArgumentBuilder {
    claim: Option<Claim>,
    grounds: Vec<Ground>,
    warrant: Option<Warrant>,
    backing: Vec<Backing>,
    qualifier: Option<Qualifier>,
    rebuttals: Vec<Rebuttal>,
}

impl ArgumentBuilder {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn claim(mut self, statement: impl Into<String>) -> Self {
        self.claim = Some(Claim {
            statement: statement.into(),
            claim_type: ClaimType::Fact,
            scope: Scope::General,
        });
        self
    }

    pub fn claim_full(
        mut self,
        statement: impl Into<String>,
        claim_type: ClaimType,
        scope: Scope,
    ) -> Self {
        self.claim = Some(Claim {
            statement: statement.into(),
            claim_type,
            scope,
        });
        self
    }

    pub fn grounds(mut self, evidence: impl Into<String>) -> Self {
        self.grounds.push(Ground {
            evidence: evidence.into(),
            evidence_type: EvidenceType::Empirical,
            source: None,
            credibility: 0.7,
        });
        self
    }

    pub fn grounds_full(
        mut self,
        evidence: impl Into<String>,
        evidence_type: EvidenceType,
        source: Option<String>,
        credibility: f32,
    ) -> Self {
        self.grounds.push(Ground {
            evidence: evidence.into(),
            evidence_type,
            source,
            credibility,
        });
        self
    }

    pub fn warrant(mut self, principle: impl Into<String>) -> Self {
        self.warrant = Some(Warrant {
            principle: principle.into(),
            warrant_type: WarrantType::Principle,
            is_explicit: true,
            strength: 0.8,
        });
        self
    }

    pub fn warrant_full(
        mut self,
        principle: impl Into<String>,
        warrant_type: WarrantType,
        strength: f32,
    ) -> Self {
        self.warrant = Some(Warrant {
            principle: principle.into(),
            warrant_type,
            is_explicit: true,
            strength,
        });
        self
    }

    pub fn backing(mut self, support: impl Into<String>) -> Self {
        self.backing.push(Backing {
            support: support.into(),
            backing_type: BackingType::Scientific,
            source: None,
        });
        self
    }

    pub fn qualifier(mut self, qualifier: Qualifier) -> Self {
        self.qualifier = Some(qualifier);
        self
    }

    pub fn rebuttal(mut self, exception: impl Into<String>) -> Self {
        self.rebuttals.push(Rebuttal {
            exception: exception.into(),
            likelihood: 0.3,
            severity: RebuttalSeverity::Moderate,
        });
        self
    }

    pub fn rebuttal_full(
        mut self,
        exception: impl Into<String>,
        likelihood: f32,
        severity: RebuttalSeverity,
    ) -> Self {
        self.rebuttals.push(Rebuttal {
            exception: exception.into(),
            likelihood,
            severity,
        });
        self
    }

    pub fn build(self) -> Result<ToulminArgument, ArgumentError> {
        let claim = self.claim.ok_or(ArgumentError::MissingClaim)?;

        if self.grounds.is_empty() {
            return Err(ArgumentError::MissingGrounds);
        }

        Ok(ToulminArgument {
            claim,
            grounds: self.grounds,
            warrant: self.warrant,
            backing: self.backing,
            qualifier: self.qualifier.unwrap_or(Qualifier::Probably),
            rebuttals: self.rebuttals,
        })
    }
}

#[derive(Debug, Clone)]
pub enum ArgumentError {
    MissingClaim,
    MissingGrounds,
    InvalidWarrant(String),
}

impl std::fmt::Display for ArgumentError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ArgumentError::MissingClaim => write!(f, "Argument requires a claim"),
            ArgumentError::MissingGrounds => write!(f, "Argument requires at least one ground"),
            ArgumentError::InvalidWarrant(msg) => write!(f, "Invalid warrant: {}", msg),
        }
    }
}

impl std::error::Error for ArgumentError {}

/// Evaluation of an argument's strength
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArgumentEvaluation {
    /// Overall argument strength (0.0-1.0)
    pub overall_strength: f32,
    /// Grounds quality
    pub grounds_score: f32,
    /// Warrant validity
    pub warrant_score: f32,
    /// Backing support
    pub backing_score: f32,
    /// Impact of rebuttals
    pub rebuttal_impact: f32,
    /// Issues found
    pub issues: Vec<ArgumentIssue>,
    /// Is the argument valid?
    pub is_valid: bool,
    /// Is the argument sound?
    pub is_sound: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArgumentIssue {
    pub component: ToulminComponent,
    pub issue: String,
    pub severity: IssueSeverity,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ToulminComponent {
    Claim,
    Grounds,
    Warrant,
    Backing,
    Qualifier,
    Rebuttal,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum IssueSeverity {
    Minor,
    Moderate,
    Serious,
    Critical,
}

impl ToulminArgument {
    /// Evaluate the argument's strength
    pub fn evaluate(&self) -> ArgumentEvaluation {
        let mut issues = Vec::new();

        // Score grounds
        let grounds_score = if self.grounds.is_empty() {
            issues.push(ArgumentIssue {
                component: ToulminComponent::Grounds,
                issue: "No supporting evidence provided".into(),
                severity: IssueSeverity::Critical,
            });
            0.0
        } else {
            self.grounds.iter().map(|g| g.credibility).sum::<f32>() / self.grounds.len() as f32
        };

        // Score warrant
        let warrant_score = if let Some(ref w) = self.warrant {
            if !w.is_explicit {
                issues.push(ArgumentIssue {
                    component: ToulminComponent::Warrant,
                    issue: "Warrant is implicit - should be made explicit".into(),
                    severity: IssueSeverity::Minor,
                });
            }
            w.strength
        } else {
            issues.push(ArgumentIssue {
                component: ToulminComponent::Warrant,
                issue: "Missing warrant connecting evidence to claim".into(),
                severity: IssueSeverity::Serious,
            });
            0.3 // Implicit warrant assumed
        };

        // Score backing
        let backing_score = if self.backing.is_empty() {
            0.5 // Neutral - backing not always needed
        } else {
            0.7 + 0.1 * self.backing.len().min(3) as f32
        };

        // Calculate rebuttal impact
        let rebuttal_impact: f32 = self
            .rebuttals
            .iter()
            .map(|r| {
                let severity_weight = match r.severity {
                    RebuttalSeverity::Minor => 0.1,
                    RebuttalSeverity::Moderate => 0.25,
                    RebuttalSeverity::Major => 0.5,
                    RebuttalSeverity::Fatal => 1.0,
                };
                r.likelihood * severity_weight
            })
            .sum::<f32>()
            .min(0.8); // Cap at 80% reduction

        // Add issues for high-impact rebuttals
        for rebuttal in &self.rebuttals {
            if rebuttal.likelihood > 0.5 && rebuttal.severity == RebuttalSeverity::Fatal {
                issues.push(ArgumentIssue {
                    component: ToulminComponent::Rebuttal,
                    issue: format!("High likelihood fatal rebuttal: {}", rebuttal.exception),
                    severity: IssueSeverity::Critical,
                });
            }
        }

        // Overall strength calculation
        let base_strength =
            grounds_score * 0.35 + warrant_score * 0.30 + backing_score * 0.20 + 0.15;

        let qualified_strength = base_strength * self.qualifier.confidence();
        let overall_strength = (qualified_strength * (1.0 - rebuttal_impact)).max(0.0);

        // Determine validity and soundness
        let is_valid = warrant_score >= 0.5 && grounds_score > 0.0;
        let is_sound = is_valid
            && grounds_score >= 0.6
            && !issues.iter().any(|i| i.severity == IssueSeverity::Critical);

        ArgumentEvaluation {
            overall_strength,
            grounds_score,
            warrant_score,
            backing_score,
            rebuttal_impact,
            issues,
            is_valid,
            is_sound,
        }
    }

    /// Format as structured text
    pub fn format(&self) -> String {
        let mut output = String::new();

        output
            .push_str("┌─────────────────────────────────────────────────────────────────────┐\n");
        output
            .push_str("│                    TOULMIN ARGUMENT STRUCTURE                       │\n");
        output
            .push_str("├─────────────────────────────────────────────────────────────────────┤\n");

        // Claim
        output.push_str(&format!(
            "│ CLAIM ({:?}, {:?}):                                                   \n",
            self.claim.claim_type, self.claim.scope
        ));
        output.push_str(&format!(
            "{} {}\n",
            self.qualifier.label(),
            self.claim.statement
        ));

        // Grounds
        output
            .push_str("├─────────────────────────────────────────────────────────────────────┤\n");
        output.push_str("│ GROUNDS (Evidence):                                                 \n");
        for ground in &self.grounds {
            output.push_str(&format!(
                "│   • [{}] {} (credibility: {:.0}%)\n",
                format!("{:?}", ground.evidence_type).to_uppercase(),
                ground.evidence,
                ground.credibility * 100.0
            ));
        }

        // Warrant
        if let Some(ref warrant) = self.warrant {
            output.push_str(
                "├─────────────────────────────────────────────────────────────────────┤\n",
            );
            output.push_str(&format!(
                "│ WARRANT ({:?}, strength: {:.0}%):                                   \n",
                warrant.warrant_type,
                warrant.strength * 100.0
            ));
            output.push_str(&format!("{}\n", warrant.principle));
        }

        // Backing
        if !self.backing.is_empty() {
            output.push_str(
                "├─────────────────────────────────────────────────────────────────────┤\n",
            );
            output.push_str(
                "│ BACKING:                                                            \n",
            );
            for backing in &self.backing {
                output.push_str(&format!("│   • {}\n", backing.support));
            }
        }

        // Rebuttals
        if !self.rebuttals.is_empty() {
            output.push_str(
                "├─────────────────────────────────────────────────────────────────────┤\n",
            );
            output.push_str(
                "│ REBUTTALS (Exceptions):                                             \n",
            );
            for rebuttal in &self.rebuttals {
                output.push_str(&format!(
                    "│   • UNLESS: {} ({:?}, {:.0}% likely)\n",
                    rebuttal.exception,
                    rebuttal.severity,
                    rebuttal.likelihood * 100.0
                ));
            }
        }

        output
            .push_str("└─────────────────────────────────────────────────────────────────────┘\n");

        output
    }
}

/// Prompt templates for generating Toulmin arguments
pub struct ToulminPrompts;

impl ToulminPrompts {
    /// Generate a Toulmin analysis of a claim
    pub fn analyze_claim(claim: &str) -> String {
        format!(
            r#"Analyze this claim using the Toulmin model of argumentation.

CLAIM: {claim}

Provide a structured analysis with:

1. CLAIM CLASSIFICATION
   - Type: Fact/Value/Policy/Prediction/Causal/Definition
   - Scope: Universal/General/Particular/Singular

2. GROUNDS (Evidence needed)
   - What evidence would support this claim?
   - What type of evidence (Statistical/Testimonial/Example/Documentary/Empirical)?
   - Rate credibility (0-100%)

3. WARRANT (Logical bridge)
   - What principle connects the evidence to the claim?
   - Type: Authority/Causal/Classification/Sign/Comparison/Generalization/Principle
   - Is it explicit or assumed?

4. BACKING (Warrant support)
   - What supports the warrant itself?
   - Source type: Legal/Scientific/Historical/Cultural/Consensus

5. QUALIFIER (Certainty level)
   - How certain is this claim? (Certainly/Presumably/Probably/Possibly/Unlikely)

6. REBUTTALS (Exceptions)
   - What conditions would invalidate this claim?
   - How likely are these exceptions?
   - Severity: Minor/Moderate/Major/Fatal

Respond in JSON format."#,
            claim = claim
        )
    }

    /// Evaluate argument strength
    pub fn evaluate_argument(argument: &str) -> String {
        format!(
            r#"Evaluate this argument for logical strength and soundness.

ARGUMENT:
{argument}

Identify:
1. The main CLAIM
2. The supporting GROUNDS (evidence)
3. The WARRANT (logical connection)
4. Any BACKING for the warrant
5. The QUALIFIER (certainty level)
6. Potential REBUTTALS

Then evaluate:
- Grounds quality (0-100%)
- Warrant validity (0-100%)
- Overall argument strength (0-100%)
- Is it VALID? (logical structure correct)
- Is it SOUND? (valid AND true premises)

List any logical fallacies or weaknesses found.

Respond in JSON format."#,
            argument = argument
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_argument_builder() {
        let argument = ArgumentBuilder::new()
            .claim("Climate change is caused by human activity")
            .grounds("CO2 levels have risen 50% since industrialization")
            .warrant("CO2 is a greenhouse gas that traps heat")
            .backing("Established physics of radiative forcing")
            .qualifier(Qualifier::Presumably)
            .rebuttal("Unless natural cycles are the primary driver")
            .build()
            .unwrap();

        assert_eq!(argument.grounds.len(), 1);
        assert!(argument.warrant.is_some());
        assert_eq!(argument.rebuttals.len(), 1);
    }

    #[test]
    fn test_argument_evaluation() {
        let argument = ArgumentBuilder::new()
            .claim("Regular exercise improves health")
            .grounds_full(
                "Meta-analysis of 100 studies shows 30% reduction in mortality",
                EvidenceType::Statistical,
                Some("Lancet 2023".into()),
                0.9,
            )
            .warrant_full(
                "Physical activity strengthens cardiovascular system",
                WarrantType::Causal,
                0.95,
            )
            .backing("Established medical consensus")
            .qualifier(Qualifier::Presumably)
            .build()
            .unwrap();

        let eval = argument.evaluate();

        assert!(eval.is_valid);
        assert!(eval.is_sound);
        assert!(eval.overall_strength > 0.7);
    }

    #[test]
    fn test_weak_argument() {
        let argument = ArgumentBuilder::new()
            .claim("All swans are white")
            .grounds_full(
                "I've only seen white swans",
                EvidenceType::Example,
                None,
                0.3,
            )
            .qualifier(Qualifier::Certainly)
            .rebuttal_full(
                "Black swans exist in Australia",
                0.9,
                RebuttalSeverity::Fatal,
            )
            .build()
            .unwrap();

        let eval = argument.evaluate();

        assert!(!eval.is_sound);
        assert!(eval.overall_strength < 0.5);
        assert!(!eval.issues.is_empty());
    }

    #[test]
    fn test_qualifier_confidence() {
        assert!(Qualifier::Certainly.confidence() > Qualifier::Probably.confidence());
        assert!(Qualifier::Probably.confidence() > Qualifier::Possibly.confidence());
    }
}