test-check

liamd 2016-09-30T18:14:35.000066Z

i was wondering how to write good properties for property based testing

liamd 2016-09-30T18:14:51.000067Z

for instance i have this function:

(defn pixel->tile [position tile-size]
  {:x (Math/floor (/ (:x position) tile-size))
   :y (Math/floor (/ (:y position) tile-size))})

liamd 2016-09-30T18:14:59.000068Z

which is pretty simple

liamd 2016-09-30T18:15:50.000069Z

i suppose i’d want to check that the output is non-nil and > 0? but that doesn’t seem to ensure the logic of it

liamd 2016-09-30T18:15:56.000070Z

is this too simple for property based testing?

lucasbradstreet 2016-09-30T20:24:56.000071Z

It’s a pretty simple function, so it might be hard to come up with something much better. You could check whether the returned x is <= to the position x

2016-09-30T22:17:37.000072Z

you could probably come up with a distance-scaling property

2016-09-30T22:17:54.000073Z

a relationship between (distance p1 p2) and (distance (f p1) (f p2))

2016-09-30T22:18:35.000074Z

or more generally the 2d-vector representing the offset between them