Skip to content

Commit

Permalink
Rename test-print-instruction to test-instruction-fmt
Browse files Browse the repository at this point in the history
Rename the test and replace all

  (with-output-to-string (s)
    (cl-quil::print-instruction ... s))

with

  (format nil "~/cl-quil:instruction-fmt/" ...).

Updates #116
  • Loading branch information
appleby committed May 28, 2019
1 parent c7be6e9 commit a456d01
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions tests/printer-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,32 @@ admonition against carelessness."
(is (string= expected-output
(parse-and-print-quil-to-string expected-output)))))))))

(deftest test-print-instruction ()
(is (string= "PRAGMA gate_time CNOT \"50 ns\""
(with-output-to-string (s)
(cl-quil::print-instruction (make-instance 'quil::pragma
:words '("gate_time" "CNOT")
:freeform-string "50 ns")
s))))
(deftest test-instruction-fmt ()
(is (string= "PRAGMA gate_time CNOT \"50 ns\"" (format nil "~/cl-quil:instruction-fmt/"
(make-instance 'quil::pragma
:words '("gate_time" "CNOT")
:freeform-string "50 ns"))))
;; try a operand-free instruction
(is (string= "HALT"
(with-output-to-string (s)
(cl-quil::print-instruction (make-instance 'halt)
s))))
(is (string= "HALT" (format nil "~/cl-quil:instruction-fmt/" (make-instance 'halt))))

;; try a unary instruction
(is (string= "NEG ro[3]"
(with-output-to-string (s)
(cl-quil::print-instruction (make-instance 'quil::classical-negate
:target (mref "ro" 3))
s))))
(is (string= "NEG ro[3]" (format nil "~/cl-quil:instruction-fmt/"
(make-instance 'quil::classical-negate
:target (mref "ro" 3)))))
;; try a binary instruction
(is (string= "MEASURE 1 ro[3]"
(with-output-to-string (s)
(cl-quil::print-instruction (make-instance 'quil::measure
:address (mref "ro" 3)
:qubit (qubit 1))
s))))
(is (string= "MEASURE 1 ro[3]" (format nil "~/cl-quil:instruction-fmt/"
(make-instance 'quil::measure
:address (mref "ro" 3)
:qubit (qubit 1)))))
;; try something fancy
(is (string= "CPHASE-AND-MEASURE(%alpha) 1 3 ro[5]"
(with-output-to-string (s)
(cl-quil::print-instruction (make-instance 'cl-quil::circuit-application
:operator #.(named-operator "CPHASE-AND-MEASURE")
:parameters `(,(param "alpha"))
:arguments `(,(qubit 1)
,(qubit 3)
,(mref "ro" 5)))
s)))))
(format nil "~/cl-quil:instruction-fmt/"
(make-instance 'cl-quil::circuit-application
:operator #.(named-operator "CPHASE-AND-MEASURE")
:parameters `(,(param "alpha"))
:arguments `(,(qubit 1)
,(qubit 3)
,(mref "ro" 5)))))))

(deftest test-defgate-printing ()
(let ((befores (list "DEFGATE R(%theta, %beta):
Expand Down

0 comments on commit a456d01

Please sign in to comment.