Fork me on GitHub
#test-check
<
2022-10-28
>
Jared Langson17:10:42

If you're checking multiple related properties in one test, is better to use one = or multiple =? Does which method you use affect shrinkage? tree/node-healthy? returns a boolean

(defspec add-remove-node-maintains-health
  (prop/for-all [k gen/small-integer
                 size gen/nat]
    ;; +1 to prevent removing nodes from empty trees
    (let [tree (make-integer-tree (+ 1 size))]
      (=
        (tree/node-healthy? (tree/node-add tree k))
        (tree/node-healthy? (tree/node-remove-least tree))
        (tree/node-healthy? (tree/node-remove-greatest tree))
        (tree/node-healthy? (->> tree tree/node-random node/-k (tree/node-remove tree)))))))
or
(defspec add-remove-node-maintains-health
  (prop/for-all [k gen/small-integer
                 size gen/nat]
    ;; +1 to prevent removing nodes from empty trees
    (let [tree (make-integer-tree (+ 1 size))]
      (= (tree/node-healthy? (tree/node-add tree k)))
      (= (tree/node-healthy? (tree/node-remove-least tree)))
      (= (tree/node-healthy? (tree/node-remove-greatest tree)))
      (= (tree/node-healthy? (->> tree tree/node-random node/-k (tree/node-remove tree)))))))
or
(defspec add-remove-node-maintains-health
  (prop/for-all [k gen/small-integer
                 size gen/nat]
    ;; +1 to prevent removing nodes from empty trees
    (let [tree (make-integer-tree (+ 1 size))]
      (= (and
           (tree/node-healthy? (tree/node-add tree k))
           (tree/node-healthy? (tree/node-remove-least tree))
           (tree/node-healthy? (tree/node-remove-greatest tree))
           (tree/node-healthy? (->> tree tree/node-random node/-k (tree/node-remove tree))))))))

Joerg Schmuecker21:05:26

Hi Jared, I ran into a very similar brick wall. I ended up looking at chuck: https://github.com/gfredericks/test.chuck.

hiredman17:10:50

doesn't matter

Jared Langson17:10:11

Stylistically, is one preferred?

hiredman17:10:32

the body of your property is basically just a predicate

hiredman17:10:13

and (= x) is always true

dpsutton17:10:21

(= false) is true. And iā€™d worry if all of your predicates uniformly returned false and you misinterpreted this

šŸ‘ 1
hiredman17:10:56

= doesn't do anything special

dpsutton17:10:08

(for the (= (pred) (pred) (pred))

hiredman17:10:08

so basically all 3 of your examples are bogus

hiredman17:10:13

the first sort of works, but will also report a success if all your node-healthy? calls return false

hiredman17:10:29

the second always is a success

hiredman17:10:41

and so is the third

hiredman17:10:14

if you remove the call to = the third is likely what you want

šŸ‘ 1
Jared Langson17:10:08

regarding the first, if I add false or (> size 10) inside the (= block it fails So why would it pass when it should fail, if node-healthy? is false?

hiredman17:10:58

because (= false false false) is true

Jared Langson17:10:52

appreciate it. Thanks šŸ™‚