mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Fix doctests and builds in various files (#6233)
* Fix doctest in hamming distance * add line break * try to fix quantum_riper_adder * fix floating point build
This commit is contained in:
parent
89fc7bf0b0
commit
9135a1f411
@ -19,8 +19,11 @@ def polar_force(
|
|||||||
True
|
True
|
||||||
>>> math.isclose(force[1], 7.0710678118654755)
|
>>> math.isclose(force[1], 7.0710678118654755)
|
||||||
True
|
True
|
||||||
>>> polar_force(10, 3.14, radian_mode=True)
|
>>> force = polar_force(10, 3.14, radian_mode=True)
|
||||||
[-9.999987317275396, 0.01592652916486828]
|
>>> math.isclose(force[0], -9.999987317275396)
|
||||||
|
True
|
||||||
|
>>> math.isclose(force[1], 0.01592652916486828)
|
||||||
|
True
|
||||||
"""
|
"""
|
||||||
if radian_mode:
|
if radian_mode:
|
||||||
return [magnitude * cos(angle), magnitude * sin(angle)]
|
return [magnitude * cos(angle), magnitude * sin(angle)]
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# https://en.wikipedia.org/wiki/Controlled_NOT_gate
|
# https://en.wikipedia.org/wiki/Controlled_NOT_gate
|
||||||
|
|
||||||
from qiskit import Aer, QuantumCircuit, execute
|
from qiskit import Aer, QuantumCircuit, execute
|
||||||
from qiskit.providers import BaseBackend
|
from qiskit.providers import Backend
|
||||||
|
|
||||||
|
|
||||||
def store_two_classics(val1: int, val2: int) -> tuple[QuantumCircuit, str, str]:
|
def store_two_classics(val1: int, val2: int) -> tuple[QuantumCircuit, str, str]:
|
||||||
@ -62,7 +62,7 @@ def full_adder(
|
|||||||
def ripple_adder(
|
def ripple_adder(
|
||||||
val1: int,
|
val1: int,
|
||||||
val2: int,
|
val2: int,
|
||||||
backend: BaseBackend = Aer.get_backend("qasm_simulator"), # noqa: B008
|
backend: Backend = Aer.get_backend("qasm_simulator"), # noqa: B008
|
||||||
) -> int:
|
) -> int:
|
||||||
"""
|
"""
|
||||||
Quantum Equivalent of a Ripple Adder Circuit
|
Quantum Equivalent of a Ripple Adder Circuit
|
||||||
|
@ -18,6 +18,8 @@ def hamming_distance(string1: str, string2: str) -> int:
|
|||||||
>>> hamming_distance("00000", "11111")
|
>>> hamming_distance("00000", "11111")
|
||||||
5
|
5
|
||||||
>>> hamming_distance("karolin", "kath")
|
>>> hamming_distance("karolin", "kath")
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
ValueError: String lengths must match!
|
ValueError: String lengths must match!
|
||||||
"""
|
"""
|
||||||
if len(string1) != len(string2):
|
if len(string1) != len(string2):
|
||||||
|
Loading…
Reference in New Issue
Block a user