The SWAP Test is used to compare quantum states. It is constructed out of a Fredkin gate (controlled-SWAP) sandwiched between two Hadamard gates. The control qubit and Hadamard gates are placed on an ancilla qubit, and the SWAP gates are placed on the qubits that you want to compare. You measure only the ancilla qubit.

Two identical states measure 0 with a probability of 1, and two maximally-different states measure 0 with a probability of 50%. All other results either show how close the states are by having a probability of measuring 0 that is closer to 1, or how different they are…