|
| 1 | +use super::*; |
| 2 | +use niffyinsure::types::{PolicyType, RegionTier}; |
| 3 | +use soroban_sdk::Env; |
| 4 | +use std::collections::HashMap; |
| 5 | + |
| 6 | +#[test] |
| 7 | +fn premium_pure_table_tests() { |
| 8 | + let env = Env::default(); |
| 9 | + |
| 10 | + // Spreadsheet export parity vectors. |
| 11 | + // Format: JSON/CSV with cols: policy_type, region, age, risk_score, expected_total_stroops, expected_line_items (optional) |
| 12 | + // Docs: Col A PolicyType -> PremiumFactors::new type_f |
| 13 | + // Col B RegionTier -> region_f |
| 14 | + // Col C age -> age_f logic |
| 15 | + // Col D risk_score -> risk_f |
| 16 | + // Col E expected = compute_premium_pure |
| 17 | + |
| 18 | + let test_cases_json = r#" |
| 19 | +[ |
| 20 | + { |
| 21 | + "policy_type": "Auto", |
| 22 | + "region": "Medium", |
| 23 | + "age": 30, |
| 24 | + "risk_score": 6, |
| 25 | + "expected_total": 49000000 |
| 26 | + }, |
| 27 | + { |
| 28 | + "policy_type": "Health", |
| 29 | + "region": "High", |
| 30 | + "age": 22, |
| 31 | + "risk_score": 3, |
| 32 | + "expected_total": 58400000 |
| 33 | + }, |
| 34 | + { |
| 35 | + "policy_type": "Property", |
| 36 | + "region": "Low", |
| 37 | + "age": 65, |
| 38 | + "risk_score": 1, |
| 39 | + "expected_total": 30100000 |
| 40 | + }, |
| 41 | + { |
| 42 | + "policy_type": "Auto", |
| 43 | + "region": "High", |
| 44 | + "age": 18, |
| 45 | + "risk_score": 10, |
| 46 | + "expected_total": 63800000 |
| 47 | + } |
| 48 | +] |
| 49 | +"#; |
| 50 | + |
| 51 | + let test_cases: Vec<HashMap<String, serde_json::Value>> = serde_json::from_str(test_cases_json).unwrap(); |
| 52 | + |
| 53 | + for case in test_cases { |
| 54 | + let policy_type = match case["policy_type"].as_str().unwrap() { |
| 55 | + "Auto" => PolicyType::Auto, |
| 56 | + "Health" => PolicyType::Health, |
| 57 | + "Property" => PolicyType::Property, |
| 58 | + _ => panic!("invalid policy_type"), |
| 59 | + }; |
| 60 | + let region = match case["region"].as_str().unwrap() { |
| 61 | + "Low" => RegionTier::Low, |
| 62 | + "Medium" => RegionTier::Medium, |
| 63 | + "High" => RegionTier::High, |
| 64 | + _ => panic!("invalid region"), |
| 65 | + }; |
| 66 | + let age: u32 = case["age"].as_u64().unwrap() as u32; |
| 67 | + let risk_score: u32 = case["risk_score"].as_u64().unwrap() as u32; |
| 68 | + let expected_total: i128 = case["expected_total"].as_str().unwrap().parse().unwrap(); |
| 69 | + |
| 70 | + let client = NiffyInsureClient::new(&env, &contract_id); // assume initialized, but pure no need |
| 71 | + |
| 72 | + let factors = premium_pure::PremiumFactors::new(&policy_type, ®ion, age, risk_score).unwrap(); |
| 73 | + let computed = premium_pure::compute_premium_pure(&factors).unwrap(); |
| 74 | + |
| 75 | + assert_eq!(computed, expected_total, "mismatch for {:?}", case); |
| 76 | + } |
| 77 | +} |
| 78 | + |
0 commit comments