bj,

Is 'current-date' a top-level var in that file?  If so, a good start might
be a test which used with with-redefs
<https://clojuredocs.org/clojure.core/with-redefs> to supply a contrived
value for 'current-date', and then validated dates on either side of it.
It may be less brittle to support something like this:

(defn validate-date
 ([now date-for-validation] (<= (Integer/parseInt date-for-validation)
(Integer/parseInt now)))
 ([date-for-validation]     (validate-date current-date
date-for-validation)))

You'd then only test the arity which accepts an explicit current-date, and
separately test whatever is responsible for deriving 'current-date'.  A few
notes:

- Having a static current-date is going to be a problem for long-running
programs - computing it at the point of validation may be a safer approach.
- If these values (current-date, date-for-validation) are used more than
once, converting them from strings elsewhere, and passing them around as
numbers may be more convenient.  validate-date just becomes <=, in that
case, and may not require a test.

Take care,
Moe


On Thu, Mar 29, 2018 at 2:20 AM, bj <pbi...@gmail.com> wrote:

> What is the best way to write unit test case for following situation?
>
> [date-for-validation]
> (if (>= (Integer/parseInt current-date)
> (Integer/parseInt date-for-validation)) true false))
>
> --
> 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.
>

-- 
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