transport-link-cell-check.scm 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Marcus Crestani
  3. (define-test-suite transport-link-cell-tests)
  4. (define max-number-of-tlcs 999)
  5. (define-test-case constructor-predicate transport-link-cell-tests
  6. (check-that
  7. (transport-link-cell? (make-transport-link-cell 'key 'value 'tconc 'next))
  8. (is-true)))
  9. (define-test-case accessors transport-link-cell-tests
  10. (let* ((key (cons 23 42))
  11. (value (cons 65 99))
  12. (tconc 'tconc)
  13. (next 'next)
  14. (tlc (make-transport-link-cell key value tconc next)))
  15. (check (transport-link-cell-key tlc) => key)
  16. (check (transport-link-cell-value tlc) => value)
  17. (check (transport-link-cell-tconc tlc) => tconc)
  18. (check (transport-link-cell-next tlc) => next)))
  19. (define-test-case setters transport-link-cell-tests
  20. (let* ((key (cons 23 42))
  21. (value (cons 65 99))
  22. (tconc 'tconc)
  23. (next 'next)
  24. (tlc (make-transport-link-cell key value tconc next)))
  25. (check (transport-link-cell-key tlc) => key)
  26. (check (transport-link-cell-value tlc) => value)
  27. (check (transport-link-cell-tconc tlc) => tconc)
  28. (check (transport-link-cell-next tlc) => next)
  29. (let ((new-value 'value)
  30. (new-tconc (cons #f #f))
  31. (new-next "I'm next!"))
  32. (set-transport-link-cell-value! tlc new-value)
  33. (set-transport-link-cell-tconc! tlc new-tconc)
  34. (set-transport-link-cell-next! tlc new-next)
  35. (check (transport-link-cell-key tlc) => key)
  36. (check (transport-link-cell-value tlc) => new-value)
  37. (check (transport-link-cell-tconc tlc) => new-tconc)
  38. (check (transport-link-cell-next tlc) => new-next))))
  39. (define-test-case collection transport-link-cell-tests
  40. (do-ec
  41. (:range n 1 max-number-of-tlcs)
  42. (let* ((key (cons 23 42))
  43. (value (cons 65 99))
  44. (tconc (make-tconc-queue))
  45. (next #f)
  46. (tlc (make-transport-link-cell key value tconc next)))
  47. (collect)
  48. (let ((tlc-tconc (transport-link-cell-tconc tlc)))
  49. (if tlc-tconc
  50. (check-that (tconc-queue-empty? tlc-tconc) (is-true))
  51. (begin
  52. (check-that (eq? (tconc-queue-dequeue! tconc) tlc) (is-true))
  53. (check-that (tconc-queue-empty? tconc) (is-true))))))))
  54. (define-test-case collection-one-tconc transport-link-cell-tests
  55. (let ((tconc (make-tconc-queue)))
  56. (do-ec
  57. (:range n 1 max-number-of-tlcs)
  58. (let* ((key (cons 23 42))
  59. (value (cons 65 99))
  60. (next #f)
  61. (tlc (make-transport-link-cell key value tconc next)))
  62. (collect)
  63. (let ((tlc-tconc (transport-link-cell-tconc tlc)))
  64. (if tlc-tconc
  65. (check-that (tconc-queue-empty? tlc-tconc) (is-true))
  66. (begin
  67. (check-that (eq? (tconc-queue-dequeue! tconc) tlc) (is-true))
  68. (check-that (tconc-queue-empty? tconc) (is-true)))))))))
  69. (define-test-case collection-no-tconc transport-link-cell-tests
  70. (let ((key (cons 23 42))
  71. (value (cons 65 99))
  72. (next #f))
  73. (let* ((tconc 23)
  74. (tlc (make-transport-link-cell key value tconc next)))
  75. (collect)
  76. (check (transport-link-cell-tconc tlc) => tconc))
  77. (let* ((tconc (cons 23 42))
  78. (tlc (make-transport-link-cell key value tconc next)))
  79. (collect)
  80. (check (transport-link-cell-tconc tlc) => tconc)
  81. (check (car (transport-link-cell-tconc tlc)) => (car tconc))
  82. (check (cdr (transport-link-cell-tconc tlc)) => (cdr tconc)))
  83. (let* ((tconc (cons (cons 23 42) 65))
  84. (tlc (make-transport-link-cell key value tconc next)))
  85. (collect)
  86. (check (transport-link-cell-tconc tlc) => tconc)
  87. (check (car (transport-link-cell-tconc tlc)) => (car tconc))
  88. (check (car (car (transport-link-cell-tconc tlc))) => (car (car tconc)))
  89. (check (cdr (car (transport-link-cell-tconc tlc))) => (cdr (car tconc)))
  90. (check (cdr (transport-link-cell-tconc tlc)) => (cdr tconc)))
  91. (let* ((tconc (cons 23 (cons 42 65)))
  92. (tlc (make-transport-link-cell key value tconc next)))
  93. (collect)
  94. (check (transport-link-cell-tconc tlc) => tconc)
  95. (check (car (transport-link-cell-tconc tlc)) => (car tconc))
  96. (check (car (cdr (transport-link-cell-tconc tlc))) => (car (cdr tconc)))
  97. (check (cdr (cdr (transport-link-cell-tconc tlc))) => (cdr (cdr tconc)))
  98. (check (car (transport-link-cell-tconc tlc)) => (car tconc)))))
  99. (define-test-case collect-n transport-link-cell-tests
  100. (let* ((tconc (make-tconc-queue))
  101. (tlcs (list-ec
  102. (: n 1 max-number-of-tlcs)
  103. (let* ((key (cons n n))
  104. (value (cons (+ 1000 n) (+ 1000 n)))
  105. (next #f)
  106. (tlc (make-transport-link-cell key value tconc next)))
  107. tlc))))
  108. (collect)
  109. (for-each
  110. (lambda (tlc)
  111. (let ((tlc-tconc (transport-link-cell-tconc tlc)))
  112. (if tlc-tconc
  113. (check-that (tconc-queue? tlc-tconc) (is-true))
  114. (tconc-queue-dequeue! tconc))))
  115. tlcs)
  116. (check-that (tconc-queue-empty? tconc) (is-true))))
  117. (define-test-case collect-n-one-key transport-link-cell-tests
  118. (let* ((tconc (make-tconc-queue))
  119. (key (cons 23 42))
  120. (tlcs (list-ec
  121. (: n 1 max-number-of-tlcs)
  122. (let* ((value (cons (+ 1000 n) (+ 1000 n)))
  123. (next #f)
  124. (tlc (make-transport-link-cell key value tconc next)))
  125. tlc))))
  126. (collect)
  127. (for-each
  128. (lambda (tlc)
  129. (let ((tlc-tconc (transport-link-cell-tconc tlc)))
  130. (if tlc-tconc
  131. (check-that (tconc-queue? tlc-tconc) (is-true))
  132. (tconc-queue-dequeue! tconc))))
  133. tlcs)
  134. (check-that (tconc-queue-empty? tconc) (is-true))))
  135. (define-test-case collect-n-one-unmovable-key transport-link-cell-tests
  136. (let* ((tconc (make-tconc-queue))
  137. (key 23)
  138. (tlcs (list-ec
  139. (: n 1 max-number-of-tlcs)
  140. (let* ((value (cons (+ 1000 n) (+ 1000 n)))
  141. (next #f)
  142. (tlc (make-transport-link-cell key value tconc next)))
  143. tlc))))
  144. (collect)
  145. (for-each
  146. (lambda (tlc)
  147. (let ((tlc-tconc (transport-link-cell-tconc tlc)))
  148. (check-that (tconc-queue-empty? tlc-tconc) (is-true))))
  149. tlcs)
  150. (check-that (tconc-queue-empty? tconc) (is-true))))