;;; Generated Guile module; edit the LP fragments.
(define-module
 (lp-example mce checks)
 #:use-module
 ((lp-example mce entry) #:select (run))
 #:export
 (run-checks))

;;; Generated from an LP program; edit the fragment sources.
;;; Execution order follows the declared program.

;;; mce-project-cases — unknown source
(define examples
  '((factorial
     ((define (factorial n) (if (= n 0) 1 (* n (factorial (- n 1)))))
      (factorial 6))
     720)
    (lexical
     ((define x 10)
      (define add-x (lambda (y) (+ x y)))
      ((lambda (x) (add-x 2)) 100))
     12)
    (closure
     ((define (make-adder x) (lambda (y) (+ x y)))
      (define add-three (make-adder 3))
      (add-three 4))
     7)
    (lazy-if ((if #t 7 missing)) 7)
    (truth ((if 0 1 2)) 1)
    (mapping ((map (lambda (x) (* x x)) '(1 2 3 4))) (1 4 9 16))
    (application ((apply + '(1 2 3))) 6)
    (named-let
     ((let loop ((n 5) (total 0))
        (if (= n 0) total (loop (- n 1) (+ total n)))))
     15)
    (let-star ((let* ((x 3) (y (+ x 4))) (* x y))) 21)
    (short-circuit ((list (and #f missing) (or 9 missing))) (#f 9))
    (conditional ((cond ((= 1 2) missing) ((= 2 2) 8) (else 0))) 8)))


(define errors
  '((missing (missing) mce-unbound)
    (arity (((lambda (x) x) 1 2)) mce-arity)
    (call ((1 2)) mce-not-procedure)
    (syntax ((if #t 1)) mce-syntax)
    (parameters ((lambda (x x) x)) mce-syntax)))


;;; mce-project-checks — lp-000A.plant:33
(define (caught-key thunk)
       (catch #t (lambda () (thunk) 'returned)
         (lambda (key . arguments) key)))

(define (run-checks)
       (for-each
         (lambda (example)
           (unless (equal? (run (cadr example)) (caddr example))
             (error "Result mismatch" (car example)))) examples)
       (for-each
         (lambda (example)
           (unless (eq? (caught-key (lambda () (run (cadr example)))) (caddr example))
             (error "Exception mismatch" (car example)))) errors)
       (list (length examples) (length errors)))
