lemma-engine 0.8.7

A language that means business.
Documentation
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
use proptest::prelude::*;
use rust_decimal::{prelude::FromPrimitive, Decimal};
use std::{collections::HashMap, str::FromStr};

use lemma::parsing::ast::DateTimeValue;
use lemma::{Engine, ValueKind};

/// Get the result of a rule evaluation.
/// Panics if the rule is not found (test failure).
/// Returns the OperationResult which must be checked explicitly.
fn get_rule_result(
    engine: &mut Engine,
    spec_name: &str,
    rule_name: &str,
) -> lemma::OperationResult {
    let now = DateTimeValue::now();
    let response = engine
        .run(spec_name, Some(&now), HashMap::new(), false)
        .unwrap();
    response
        .results
        .values()
        .find(|r| r.rule.name == rule_name)
        .map(|r| r.result.clone())
        .unwrap_or_else(|| panic!("Rule '{}' not found in spec '{}'", rule_name, spec_name))
}

proptest! {
    #![proptest_config(ProptestConfig {
        cases: 100,
        ..ProptestConfig::default()
    })]

    #[test]
    fn prop_multiplication_by_zero(n in -1000.0..1000.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact x: {}
rule result: x * 0
"#, n);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let result = get_rule_result(&mut engine, "test", "result");
        let val = result
            .value()
            .expect("Expected value result, got veto")
            .clone();
        if let ValueKind::Number(num) = &val.value {
            prop_assert_eq!(*num, Decimal::from_str("0").unwrap());
        }
    }

    #[test]
    fn prop_multiplication_identity(n in -100.0..100.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact x: {}
rule result: x * 1
"#, n);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let result = get_rule_result(&mut engine, "test", "result");
        let val = result
            .value()
            .expect("Expected value result, got veto")
            .clone();
        if let ValueKind::Number(num) = &val.value {
            let expected = Decimal::from_f64(n).unwrap();
            let diff = (num - expected).abs();
            prop_assert!(diff < Decimal::from_str("0.001").unwrap());
        }
    }

    #[test]
    fn prop_addition_identity(n in -100.0..100.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact x: {}
rule result: x + 0
"#, n);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let result = get_rule_result(&mut engine, "test", "result");
        let val = result
            .value()
            .expect("Expected value result, got veto")
            .clone();
        if let ValueKind::Number(num) = &val.value {
            let expected = Decimal::from_f64(n).unwrap();
            let diff = (num - expected).abs();
            prop_assert!(diff < Decimal::from_str("0.001").unwrap());
        }
    }

    #[test]
    fn prop_comparison_consistency(n in -100.0..100.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact x: {}
rule eq_self: x == x
rule lte_self: x <= x
"#, n);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let result = get_rule_result(&mut engine, "test", "eq_self");
        let val = result.value().expect("Expected value result, got veto").clone();
        if let ValueKind::Boolean(b) = &val.value {
            prop_assert!(*b);
        }

        let result = get_rule_result(&mut engine, "test", "lte_self");
        let val = result.value().expect("Expected value result, got veto").clone();
        if let ValueKind::Boolean(b) = &val.value {
            prop_assert!(*b);
        }
    }

    #[test]
    fn prop_fact_binding_works(n in -100.0..100.0) {
        let mut engine = Engine::new();
        let code = r#"
spec test
fact x: [number]
rule doubled: x * 2
"#;
        engine.load(code, lemma::SourceType::Labeled("test")).unwrap();

        let mut facts: std::collections::HashMap<String, String> = std::collections::HashMap::new();
        facts.insert("x".to_string(), format!("{}", n));
        let now = DateTimeValue::now();
        let response = engine.run("test", Some(&now), facts, false).unwrap();

        let result = response
            .results.values()
            .find(|r| r.rule.name == "doubled")
            .expect("Rule 'doubled' not found");
        let val = result
            .result
            .value()
            .expect("Expected value result, got veto")
            .clone();
        if let ValueKind::Number(num) = &val.value {
            let expected = Decimal::from_f64(n * 2.0).unwrap();
            let diff = (num - expected).abs();
            prop_assert!(diff < Decimal::from_str("0.001").unwrap());
        }
    }

    #[test]
    fn prop_addition_commutative(a in -100.0..100.0, b in -100.0..100.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
rule sum1: a + b
rule sum2: b + a
"#, a, b);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let v1_result = get_rule_result(&mut engine, "test", "sum1");
        let v1 = v1_result.value().expect("Expected value, got veto").clone();
        let v2_result = get_rule_result(&mut engine, "test", "sum2");
        let v2 = v2_result.value().expect("Expected value, got veto").clone();

        if let (ValueKind::Number(val1), ValueKind::Number(val2)) = (&v1.value, &v2.value) {
            let diff = (val1 - val2).abs();
            prop_assert!(diff < Decimal::from_str("0.001").unwrap());
        }
    }

    #[test]
    fn prop_multiplication_commutative(a in -50.0..50.0, b in -50.0..50.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
rule prod1: a * b
rule prod2: b * a
"#, a, b);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let v1_result = get_rule_result(&mut engine, "test", "prod1");
        let v1 = v1_result.value().expect("Expected value, got veto").clone();
        let v2_result = get_rule_result(&mut engine, "test", "prod2");
        let v2 = v2_result.value().expect("Expected value, got veto").clone();

        if let (ValueKind::Number(val1), ValueKind::Number(val2)) = (&v1.value, &v2.value) {
            let diff = (val1 - val2).abs();
            prop_assert!(diff < Decimal::from_str("0.001").unwrap());
        }
    }

    #[test]
    fn prop_addition_associative(a in -50.0..50.0, b in -50.0..50.0, c in -50.0..50.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
fact c: {}
rule sum1: (a + b) + c
rule sum2: a + (b + c)
"#, a, b, c);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let v1_result = get_rule_result(&mut engine, "test", "sum1");
        let v1 = v1_result.value().expect("Expected value, got veto").clone();
        let v2_result = get_rule_result(&mut engine, "test", "sum2");
        let v2 = v2_result.value().expect("Expected value, got veto").clone();

        if let (ValueKind::Number(val1), ValueKind::Number(val2)) = (&v1.value, &v2.value) {
            let diff = (val1 - val2).abs();
            prop_assert!(diff < Decimal::from_str("0.001").unwrap());
        }
    }

    #[test]
    fn prop_multiplication_associative(a in -20.0..20.0, b in -20.0..20.0, c in -20.0..20.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
fact c: {}
rule prod1: (a * b) * c
rule prod2: a * (b * c)
"#, a, b, c);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let v1_result = get_rule_result(&mut engine, "test", "prod1");
        let v1 = v1_result.value().expect("Expected value, got veto").clone();
        let v2_result = get_rule_result(&mut engine, "test", "prod2");
        let v2 = v2_result.value().expect("Expected value, got veto").clone();

        if let (ValueKind::Number(val1), ValueKind::Number(val2)) = (&v1.value, &v2.value) {
            let diff = (val1 - val2).abs();
            prop_assert!(diff < Decimal::from_str("0.01").unwrap());
        }
    }

    #[test]
    fn prop_distributive(a in -50.0..50.0, b in -50.0..50.0, c in -50.0..50.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
fact c: {}
rule dist1: a * (b + c)
rule dist2: (a * b) + (a * c)
"#, a, b, c);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let v1_result = get_rule_result(&mut engine, "test", "dist1");
        let v1 = v1_result.value().expect("Expected value, got veto").clone();
        let v2_result = get_rule_result(&mut engine, "test", "dist2");
        let v2 = v2_result.value().expect("Expected value, got veto").clone();

        if let (ValueKind::Number(val1), ValueKind::Number(val2)) = (&v1.value, &v2.value) {
            let diff = (val1 - val2).abs();
            prop_assert!(diff < Decimal::from_str("0.01").unwrap());
        }
    }

    #[test]
    fn prop_negation_involution(n in -100.0..100.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact x: {}
rule double_neg: -(-x)
"#, n);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let result = get_rule_result(&mut engine, "test", "double_neg");


        let val = result.value().expect("Expected value result, got veto").clone();


        if let ValueKind::Number(val) = &val.value {
            let expected = Decimal::from_f64(n).unwrap();
            let diff = (val - expected).abs();
            prop_assert!(diff < Decimal::from_str("0.001").unwrap());
        }
    }

    #[test]
    fn prop_subtraction_as_addition_of_negative(a in -100.0..100.0, b in -100.0..100.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
rule sub: a - b
rule add_neg: a + (-b)
"#, a, b);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let v1_result = get_rule_result(&mut engine, "test", "sub");
        let v1 = v1_result.value().expect("Expected value, got veto").clone();
        let v2_result = get_rule_result(&mut engine, "test", "add_neg");
        let v2 = v2_result.value().expect("Expected value, got veto").clone();

        if let (ValueKind::Number(val1), ValueKind::Number(val2)) = (&v1.value, &v2.value) {
            let diff = (val1 - val2).abs();
            prop_assert!(diff < Decimal::from_str("0.001").unwrap());
        }
    }

    #[test]
    fn prop_division_inverse_of_multiplication(a in 1.0..100.0, b in 1.0..100.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
rule product: a * b
rule back: product / b
"#, a, b);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let result = get_rule_result(&mut engine, "test", "back");


        let val = result.value().expect("Expected value result, got veto").clone();


        if let ValueKind::Number(val) = &val.value {
            let expected = Decimal::from_f64(a).unwrap();
            let diff = (val - expected).abs();
            prop_assert!(diff < Decimal::from_str("0.01").unwrap());
        }
    }

    #[test]
    fn prop_boolean_not_involution(b in prop::bool::ANY) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact b: {}
rule double_not: not (not b)
"#, b);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let result = get_rule_result(&mut engine, "test", "double_not");


        let val = result.value().expect("Expected value result, got veto").clone();


        if let ValueKind::Boolean(val) = &val.value {
            prop_assert_eq!(*val, b);
        }
    }

    #[test]
    fn prop_and_commutative(a in prop::bool::ANY, b in prop::bool::ANY) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
rule and1: a and b
rule and2: b and a
"#, a, b);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let v1_result = get_rule_result(&mut engine, "test", "and1");
        let v1 = v1_result.value().expect("Expected value, got veto").clone();
        let v2_result = get_rule_result(&mut engine, "test", "and2");
        let v2 = v2_result.value().expect("Expected value, got veto").clone();

        if let (ValueKind::Boolean(val1), ValueKind::Boolean(val2)) = (&v1.value, &v2.value) {
            prop_assert_eq!(val1, val2);
        }
    }

    #[test]
    fn prop_comparison_transitivity(a in 1.0..100.0, b in 1.0..100.0) {
        let (min, max) = if a < b { (a, b) } else { (b, a) };
        let mid = (min + max) / 2.0;

        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact a: {}
fact b: {}
fact c: {}
rule ab: a < b
rule bc: b < c
rule ac: a < c
"#, min, mid, max);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let ab_result = get_rule_result(&mut engine, "test", "ab");
        let ab = ab_result.value().expect("Expected value, got veto").clone();
        let bc_result = get_rule_result(&mut engine, "test", "bc");
        let bc = bc_result.value().expect("Expected value, got veto").clone();
        let ac_result = get_rule_result(&mut engine, "test", "ac");
        let ac = ac_result.value().expect("Expected value, got veto").clone();

        if let (ValueKind::Boolean(ab_val), ValueKind::Boolean(bc_val), ValueKind::Boolean(ac_val)) = (&ab.value, &bc.value, &ac.value) {
            if *ab_val && *bc_val {
                prop_assert!(*ac_val);
            }
        }
    }

    #[test]
    fn prop_unless_last_matching_wins(n in 1.0..100.0) {
        let mut engine = Engine::new();
        let code = format!(r#"
spec test
fact x: {}
rule discount: 0
  unless x > 10 then 10
  unless x > 20 then 20
  unless x > 50 then 50
"#, n);
        engine.load(&code, lemma::SourceType::Labeled("test")).unwrap();

        let result = get_rule_result(&mut engine, "test", "discount");


        let val = result.value().expect("Expected value result, got veto").clone();


        if let ValueKind::Number(val) = &val.value {
            let expected = if n > 50.0 {
                Decimal::from(50)
            } else if n > 20.0 {
                Decimal::from(20)
            } else if n > 10.0 {
                Decimal::from(10)
            } else {
                Decimal::from(0)
            };
            prop_assert_eq!(*val, expected);
        }
    }
}

#[test]
fn test_arithmetic_properties() {
    let test_values = vec![-100.0, -1.0, 0.0, 1.0, 42.0, 100.0];

    for n in test_values {
        let mut engine = Engine::new();
        let code = format!(
            r#"
spec test
fact x: {}
rule zero: x * 0
rule identity_mul: x * 1
rule identity_add: x + 0
rule commutative1: x + 5
rule commutative2: 5 + x
"#,
            n
        );
        engine
            .load(&code, lemma::SourceType::Labeled("test"))
            .unwrap();

        let result = get_rule_result(&mut engine, "test", "zero");

        let val = result
            .value()
            .expect("Expected value result, got veto")
            .clone();

        if let ValueKind::Number(val) = &val.value {
            assert_eq!(
                *val,
                Decimal::from_str("0").unwrap(),
                "Multiplication by zero failed for {}",
                n
            );
        }

        let result = get_rule_result(&mut engine, "test", "identity_mul");

        let val = result
            .value()
            .expect("Expected value result, got veto")
            .clone();

        if let ValueKind::Number(val) = &val.value {
            let expected = Decimal::from_f64(n).unwrap();
            assert!(
                (val - expected).abs() < Decimal::from_str("0.001").unwrap(),
                "Multiplication identity failed for {}",
                n
            );
        }

        let result = get_rule_result(&mut engine, "test", "identity_add");

        let val = result
            .value()
            .expect("Expected value result, got veto")
            .clone();

        if let ValueKind::Number(val) = &val.value {
            let expected = Decimal::from_f64(n).unwrap();
            assert!(
                (val - expected).abs() < Decimal::from_str("0.001").unwrap(),
                "Addition identity failed for {}",
                n
            );
        }

        let comm1_result = get_rule_result(&mut engine, "test", "commutative1");
        let comm1 = comm1_result
            .value()
            .expect("Expected value, got veto")
            .clone();
        let comm2_result = get_rule_result(&mut engine, "test", "commutative2");
        let comm2 = comm2_result
            .value()
            .expect("Expected value, got veto")
            .clone();
        if let (ValueKind::Number(v1), ValueKind::Number(v2)) = (&comm1.value, &comm2.value) {
            assert!(
                (v1 - v2).abs() < Decimal::from_str("0.001").unwrap(),
                "Commutativity failed for {}",
                n
            );
        }
    }
}

#[test]
fn test_comparison_properties() {
    let mut engine = Engine::new();
    let code = r#"
spec test
fact a: 10
fact b: 20
fact c: 30
rule a_lt_b: a < b
rule b_lt_c: b < c
rule a_lt_c: a < c
rule a_eq_a: a == a
rule a_lte_a: a <= a
rule a_gte_a: a >= a
"#;
    engine
        .load(code, lemma::SourceType::Labeled("test"))
        .unwrap();

    let result = get_rule_result(&mut engine, "test", "a_eq_a");

    let val = result
        .value()
        .expect("Expected value result, got veto")
        .clone();

    if let ValueKind::Boolean(val) = &val.value {
        assert!(*val, "Reflexive equality failed");
    }

    let result = get_rule_result(&mut engine, "test", "a_lte_a");

    let val = result
        .value()
        .expect("Expected value result, got veto")
        .clone();

    if let ValueKind::Boolean(val) = &val.value {
        assert!(*val, "Reflexive <= failed");
    }

    let result = get_rule_result(&mut engine, "test", "a_gte_a");

    let val = result
        .value()
        .expect("Expected value result, got veto")
        .clone();

    if let ValueKind::Boolean(val) = &val.value {
        assert!(*val, "Reflexive >= failed");
    }

    let ab_result = get_rule_result(&mut engine, "test", "a_lt_b");
    let ab = ab_result.value().expect("Expected value, got veto").clone();
    let bc_result = get_rule_result(&mut engine, "test", "b_lt_c");
    let bc = bc_result.value().expect("Expected value, got veto").clone();
    let ac_result = get_rule_result(&mut engine, "test", "a_lt_c");
    let ac = ac_result.value().expect("Expected value, got veto").clone();

    if let (ValueKind::Boolean(true), ValueKind::Boolean(true), ValueKind::Boolean(val)) =
        (&ab.value, &bc.value, &ac.value)
    {
        assert!(*val, "Transitivity of < failed");
    }
}

#[test]
fn test_duration_conversion_properties() {
    let mut engine = Engine::new();
    let code = r#"
spec test
fact duration: 60 minutes
rule to_hours: duration in hours
"#;
    engine
        .load(code, lemma::SourceType::Labeled("test"))
        .unwrap();

    let result = get_rule_result(&mut engine, "test", "to_hours");

    let val = result
        .value()
        .expect("Expected value result, got veto")
        .clone();

    if let ValueKind::Duration(value, _) = &val.value {
        // 60 minutes = 1 hour (the conversion returns 1 hour, not 3600 seconds)
        assert_eq!(
            *value,
            Decimal::from_str("1").unwrap(),
            "minutes to hours conversion failed: got {}",
            value
        );
    } else {
        panic!(
            "to_hours should be a Duration after conversion, got {:?}",
            val
        );
    }
}

#[test]
fn test_percentage_properties() {
    let mut engine = Engine::new();
    let code = r#"
spec test
fact base: 200
fact rate: 10%
rule result: base * rate
"#;
    engine
        .load(code, lemma::SourceType::Labeled("test"))
        .unwrap();

    let result = get_rule_result(&mut engine, "test", "result");

    let val = result
        .value()
        .expect("Expected value result, got veto")
        .clone();

    if let ValueKind::Number(val) = &val.value {
        assert!(
            (val - Decimal::from_str("20").unwrap()).abs() < Decimal::from_str("0.01").unwrap(),
            "Percentage calculation failed"
        );
    }
}

#[test]
fn test_inverse_operations() {
    let test_values = vec![(10.0, 5.0), (100.0, 25.0), (7.5, 2.5)];

    for (a, b) in test_values {
        let mut engine = Engine::new();
        let code = format!(
            r#"
spec test
fact a: {}
fact b: {}
rule sum: a + b
rule back_sub: sum - b
rule product: a * b
rule back_div: product / b
"#,
            a, b
        );
        engine
            .load(&code, lemma::SourceType::Labeled("test"))
            .unwrap();

        let result = get_rule_result(&mut engine, "test", "back_sub");

        let val = result
            .value()
            .expect("Expected value result, got veto")
            .clone();

        if let ValueKind::Number(val) = &val.value {
            let expected = Decimal::from_f64(a).unwrap();
            assert!(
                (val - expected).abs() < Decimal::from_str("0.001").unwrap(),
                "Subtraction inverse failed for ({}, {})",
                a,
                b
            );
        }

        let result = get_rule_result(&mut engine, "test", "back_div");

        let val = result
            .value()
            .expect("Expected value result, got veto")
            .clone();

        if let ValueKind::Number(val) = &val.value {
            let expected = Decimal::from_f64(a).unwrap();
            assert!(
                (val - expected).abs() < Decimal::from_str("0.01").unwrap(),
                "Division inverse failed for ({}, {})",
                a,
                b
            );
        }
    }
}