I think this is almost borderline to be too trivial to test, and
definitively rewriting the same logic in the test is normally not a
good idea..

I would just consider on some simple cases and on the the corner cases.
For example:

(is (false (valid-vector? {:vec []}))
(is (true (valid-vector? {:vec [1 2]}))

And if it makes sense to check that it does not blow up when the input
is very large:
(is (true (valid-vector? {:vec (vec (range 10000))})))

So for me you should really just think about the use cases and worry
more about testing the more complex parts of the code.


2015-03-27 7:13 GMT+00:00 John Louis Del Rosario <joh...@gmail.com>:
> I have a function I want to try out test.check on. But I'm having trouble
> grokking how to write the tests.
> Basically the function checks if a vector value in a hash-map has at least 2
> elements.
>
> (defn valid-vector?
>   [d]
>   (>= 2 (count (:vec d))))
>
>
> and in my tests (I'm using test.chuck)
>
> (def gen-data
>   (gen/hash-map :v (gen/vector gen/string)))
>
> (deftest valid-vector-test
>   (checking "data with at least 2 elements in :vec" 100 [d gen-data]
>     ;; what to do here?
>   ))
>
> I'm confused on how I should write the body of the test. My first thought is
> to do something like:
>
> (checking "data with at least 2 elements in :vec" 100 [d gen-data]
>   (if (>= 2 (count (:vec d)))
>     (is (true? (valid-vector d)))
>     (is (false? (valid-vector d)))))
>
> But that means I just re-wrote my function definition in the `if` condition.
> Is there a better way to test my function? Or does test.check just not a
> good fit for it?
>
> Thanks.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to