Programming Clojure (The Pragmatic Programmers) by Alex Miller & Stuart Halloway & Aaron Bedra

Programming Clojure (The Pragmatic Programmers) by Alex Miller & Stuart Halloway & Aaron Bedra

Author:Alex Miller & Stuart Halloway & Aaron Bedra [Miller, Alex]
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
Publisher: Pragmatic Bookshelf
Published: 2018-02-22T23:00:00+00:00


Generating Examples

The argument spec we used above was (s/cat :ns (s/? string?) :name string?). To simulate how check generates random arguments from that spec, we can use the s/exercise function, which produces pairs of examples and their conformed values:

(s/exercise (s/cat :ns (s/? string?) :name string?))

-> ([("" "") {:ns "", :name ""}]

[("F" "") {:ns "F", :name ""}]

[("s" "73") {:ns "s", :name "73"}]

[("u") {:name "u"}]

[("") {:name ""}]

[("" "3y") {:ns "", :name "3y"}]

[("t" "9pudu") {:ns "t", :name "9pudu"}]

[("Xhw25" "nPR7C9C") {:ns "Xhw25", :name "nPR7C9C"}]

[("FXs3E" "N") {:ns "FXs3E", :name "N"}]

[("UhUN5dZK1" "le8") {:ns "UhUN5dZK1", :name "le8"}])

This example works, but sometimes spec can’t automatically create a valid generator, or you need to create a custom generator for related arguments. In the following sections, we’ll see how to address these issues. First, let’s consider a case where an s/and spec doesn’t produce any values.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.