Skip to content

Commit

Permalink
Remove string_to_fraction test as it is in pyzx now
Browse files Browse the repository at this point in the history
  • Loading branch information
boldar99 committed Nov 15, 2023
1 parent 7f25048 commit de4a725
Showing 1 changed file with 1 addition and 52 deletions.
53 changes: 1 addition & 52 deletions test/test_editor_base_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,9 @@

import pytest

from zxlive.editor_base_panel import string_to_fraction, string_to_complex
from zxlive.poly import Poly, Term, Var, new_var
from zxlive.editor_base_panel import string_to_complex


def test_string_to_fraction() -> None:
types_dict = {'a': False, 'b': False}

def _new_var(name: str) -> Poly:
return new_var(name, types_dict)

# Test empty input clears the phase.
assert string_to_fraction('', _new_var) == Fraction(0)

# Test different ways of specifying integer multiples of pi.
assert string_to_fraction('3', _new_var) == Fraction(3)
assert string_to_fraction('3pi', _new_var) == Fraction(3)
assert string_to_fraction('3*pi', _new_var) == Fraction(3)
assert string_to_fraction('pi*3', _new_var) == Fraction(3)

# Test different ways of specifying fractions.
assert string_to_fraction('pi/2', _new_var) == Fraction(1, 2)
assert string_to_fraction('-pi/2', _new_var) == Fraction(-1, 2)
assert string_to_fraction('5/2', _new_var) == Fraction(5, 2)
assert string_to_fraction('5pi/2', _new_var) == Fraction(5, 2)
assert string_to_fraction('5*pi/2', _new_var) == Fraction(5, 2)
assert string_to_fraction('pi*5/2', _new_var) == Fraction(5, 2)
assert string_to_fraction('5/2pi', _new_var) == Fraction(5, 2)
assert string_to_fraction('5/2*pi', _new_var) == Fraction(5, 2)
assert string_to_fraction('5/pi*2', _new_var) == Fraction(5, 2)

# Test different ways of specifying floats.
assert string_to_fraction('5.5', _new_var) == Fraction(11, 2)
assert string_to_fraction('5.5pi', _new_var) == Fraction(11, 2)
assert string_to_fraction('25e-1', _new_var) == Fraction(5, 2)
assert string_to_fraction('5.5*pi', _new_var) == Fraction(11, 2)
assert string_to_fraction('pi*5.5', _new_var) == Fraction(11, 2)

# Test a fractional phase specified with variables.
assert (string_to_fraction('a*b', _new_var) ==
Poly([(1, Term([(Var('a', types_dict), 1), (Var('b', types_dict), 1)]))]))
assert (string_to_fraction('2*a', _new_var) ==
Poly([(2, Term([(Var('a', types_dict), 1)]))]))
assert (string_to_fraction('2a', _new_var) ==
Poly([(2, Term([(Var('a', types_dict), 1)]))]))
assert (string_to_fraction('3/2a', _new_var) ==
Poly([(3/2, Term([(Var('a', types_dict), 1)]))]))
assert (string_to_fraction('3a+2b', _new_var) ==
Poly([(3, Term([(Var('a', types_dict), 1)])), (2, Term([(Var('b', types_dict), 1)]))]))


# Test bad input.
with pytest.raises(ValueError):
string_to_fraction('bad input', _new_var)

def test_string_to_complex() -> None:
# Test empty input clears the phase.
assert string_to_complex('') == 0
Expand Down

0 comments on commit de4a725

Please sign in to comment.