Skip to content

Commit

Permalink
natural->bitstring: protect against 0 min-width argument
Browse files Browse the repository at this point in the history
So this library gives a nice error, instead of blaming itself with a
huge message from `~r`
  • Loading branch information
bennn committed Apr 16, 2018
1 parent 39f3722 commit d23a421
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
(-> any/c boolean?)]

[natural->bitstring
(-> exact-nonnegative-integer? #:bits exact-nonnegative-integer? string?)]
(-> exact-nonnegative-integer? #:bits exact-positive-integer? string?)]
;; (natural->bitstring n k) converts `n` into a `k`-digit string of 1's and 0's

[bitstring->natural
Expand Down Expand Up @@ -596,6 +596,8 @@

(test-case "natural->bitstring"
(check-apply* natural->bitstring
[0 #:bits 4
==> "0000"]
[2 #:bits 2
==> "10"]
[2 #:bits 10
Expand Down

0 comments on commit d23a421

Please sign in to comment.