test-check 2022-10-28

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

Stylistically, is one preferred?

the body of your property is basically just a predicate

and (= x) is always true

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

šŸ‘ 1

= doesn't do anything special

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

so basically all 3 of your examples are bogus

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

the second always is a success

and so is the third

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

šŸ‘ 1

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?

because (= false false false) is true

appreciate it. Thanks šŸ™‚