exercise-2.67-test.rkt 996 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #lang racket
  2. (require rackunit
  3. "exercise-2.67-huffman-trees.rkt")
  4. (test-case
  5. "binary tree records set lookup"
  6. (check-equal?
  7. (let
  8. ([sample-tree
  9. (combine-subtrees
  10. (make-leaf 'A 4)
  11. (combine-subtrees
  12. (make-leaf 'C 3)
  13. (combine-subtrees
  14. (make-leaf 'B 2)
  15. (make-leaf 'D 2))))]
  16. ;; message: A B D B AA CCC D A
  17. [sample-message
  18. (list 0
  19. 1 1 0
  20. 1 1 1
  21. 1 1 0
  22. 0
  23. 0
  24. 1 0
  25. 1 0
  26. 1 0
  27. 1 1 1
  28. 0)])
  29. (decode sample-message sample-tree))
  30. (list 'A
  31. 'B
  32. 'D
  33. 'B
  34. 'A
  35. 'A
  36. 'C
  37. 'C
  38. 'C
  39. 'D
  40. 'A)
  41. "not working correctly")
  42. (check-equal?
  43. '()
  44. '()
  45. "not working correctly")
  46. (check-equal?
  47. '()
  48. '()
  49. "not working correctly"))