Regression Tests for Calculator Customized for Quantum Computation Equations

Table of Contents

Introduction
Gates
Dirac Notation
perm
qcc

Introduction

Here I only test the functions I added on top of math.js, because I'm assuming math.js is ok. I use the assert function, which acts just like eq when things are equal, but throws an error when they aren't, so it's easy to catch a failure.

Besides acting as regression tests, they're also examples of how to use the functions.

Gates

The goal is for the descriptions here to be more easily visually verifiable than in the javascript code.

Some of these are a function of one to three angles (because no symbolic evaluation available.) I generate random angles to verify. If you want to try different angles, you can click on the visible equations to get the buttons, then click on Re-evaluate to get new random values.

Dirac Notation

First we test \(\left| \Psi \right\rangle\).

Then we verify the others. They're defined like this, as functions of ket, in the code, but at least this is more visually verifiable.

perm

Define three unique states and use them to test if they're routed by perm as expected for all the permutations of three qubits.

qcc

First let's make sure qcc puts the internal gates in the right place.

Then how about if there is a 2-qubit internal gate involved.

And now test to see if control gates are working under a few conditions.

Or we can build some controlled gates.