#! /bin/sh
#lang scheme
(require (planet schematics/schemeunit:3)
(planet schematics/schemeunit:3/text-ui))
(provide list->histogram main)
(define (list->histogram l)
(hash-map
(for/fold ([rv (make-immutable-hash '())])
([elt (in-list l)])
(hash-update rv elt add1 0))
cons))
(define (cdr-sort l)
(sort l < #:key cdr))
(define (main . args)
(exit
(run-tests
(test-suite
"The one and only suite"
(test-case "duh" (check-equal? (cdr-sort (list->histogram '(1 2 3 2 0 1 1 1 1 1 1)))
'((0 . 1) (3 . 1) (2 . 2) (1 . 7))))
(test-case
"non-numbers"
(check-equal?
(cdr-sort (list->histogram '((1 . 2)
(2 . 1)
(1 . 2))))
'(((2 . 1) . 1)
((1 . 2) . 2))))))))