#lang racket

(require xml)
(define (load-xexpr path)
  (xml->xexpr (document-element (read-xml (open-input-file path)))))


(define (load-rubrics path)
  (define rubrics (load-xexpr path))
  (define (get-rubrics rubrics)
    (cond
      [(null? rubrics) '()]
      [(list? rubrics) (append (get-rubrics (car rubrics)) (get-rubrics (cdr rubrics)))]
      [else (list rubrics)]))
  (get-rubrics rubrics))


; test for load-rubrics

(module+ test
  (require rackunit)
  (define rubrics (load-rubrics  "rubrics.xml"))
  (check-equal? (length rubrics) 5)
  (for ([elt rubrics])
    (check-equal? (first elt) 'rubric)))



; test for assoc*

(module+ test
  (define test-list '(1 [keep 2] 3 [keep 4] [keep 5] 6))
  (check-equal? (assoc* 'keep test-list) 2)
  (check-equal? (assoc* 'discard test-list) #f))

(define (rubric-name rubric)
  (assoc* 'name (second rubric)))

(module+ test
  (check-equal?
   (sort (map rubric-name rubrics) string<=?)
   '("JavaScript Assignment" "Journal Entry" "Octave Assignment" "Python Assignment"
                             "Racket assignment")))