Skip to content

Instantly share code, notes, and snippets.

@leifp
Created March 25, 2015 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leifp/bf5c74eea98026329a76 to your computer and use it in GitHub Desktop.
Save leifp/bf5c74eea98026329a76 to your computer and use it in GitHub Desktop.
Best way to test multiple implementations of a protocol?
(ns test.multiple.implementations
(:require [clojure.test :refer [deftest is]]))
;;; Protocol and records that implement it
(defprotocol P (value [this]))
(defrecord One [] P (value [_] 1))
(defrecord Three [] P (value [_] 3))
;; potentially several more...
;;; Test suite that should hold for any implementation
(deftest is-positive
(is (pos? (value (->One)))))
(deftest is-odd
(is (odd? (value (->One)))))
;;; Now, how to actually test *all* implementations?
;; Goals:
;; * No unnecessary repetition.
;; * Error messages should be informative, i.e. the failing
;; implementation should be present in the test output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment