Work on A2

This commit is contained in:
Isaac Shoebottom 2022-10-07 11:41:22 -03:00
parent 6809a95041
commit 585fb2e9e8
4 changed files with 54 additions and 0 deletions

1
assignments/A2/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
A2temp.rkt

43
assignments/A2/A2.rkt Normal file
View File

@ -0,0 +1,43 @@
#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")))

View File

@ -0,0 +1,9 @@
#lang racket
(require xml)
(define (load-xexpr path)
(xml->xexpr (document-element (read-xml (open-input-file path)))))
(require explorer)
(define data (load-xexpr "rubrics.xml"))
(explore data)

File diff suppressed because one or more lines are too long