Created
March 25, 2015 01:18
-
-
Save leifp/bf5c74eea98026329a76 to your computer and use it in GitHub Desktop.
Best way to test multiple implementations of a protocol?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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