Created
April 15, 2019 17:32
-
-
Save mightybyte/33c290da70a25db8c83da9388118ae33 to your computer and use it in GitHub Desktop.
Pact formal verification example
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
;; | |
;; A little example showing off the merits of formal | |
;; verification and why it pays off. | |
;; | |
;; Keysets cannot be created in code, thus we read them in | |
;; from the load message data. | |
(define-keyset 'admin-keyset (read-keyset "admin-keyset")) | |
;; Define the module. | |
(module verification 'admin-keyset | |
@doc "Little example to show off the usefulness of formal verification." | |
(defun absBug:integer (num:integer) | |
@doc "Ensure positive result" | |
;; This property fails: Would you have caught that with unit tests? | |
@model [(property (>= result 0))] | |
(if (= (- (* (- num 6) (+ num 11)) (* 42 num)) (* (* 64 7) 52270780833)) | |
(- 1) | |
(abs num) | |
) | |
) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment