CS2613/assignments/A2/A2.rkt

43 lines
1.1 KiB
Racket
Raw Normal View History

2022-10-07 11:41:22 -03:00
#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")))