From 4bfc2f9e956fdb5b6253a31f79e857b7eff5ea1d Mon Sep 17 00:00:00 2001 From: Ryan Byrne Date: Thu, 27 Jun 2024 17:44:15 -0400 Subject: [PATCH] Add fibonacci tests in test_main --- python/tests/test_main.py | 223 ++++++++++++++++++++++++-------------- 1 file changed, 142 insertions(+), 81 deletions(-) diff --git a/python/tests/test_main.py b/python/tests/test_main.py index 0af4f16..8936153 100644 --- a/python/tests/test_main.py +++ b/python/tests/test_main.py @@ -5,9 +5,11 @@ import sh -def exec(cmds: list[str]): +def exec(model, cmds: list[str]): os.chdir('python/anyon_braiding_simulator') + # Insert the model at the beginning of cmds, & join them into a single string + cmds.insert(0, model) cmd_string = '\n'.join(cmds) try: @@ -18,141 +20,200 @@ def exec(cmds: list[str]): finally: os.chdir('../..') +# Although later tests frequently use 'vac' charge to allow model parametrization, some anyon tests here include +# both models to account for different charges. class TestInit: + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_model_ising(self): - cmds = ['ising', 'exit'] - exec(cmds) + def test_model_ising(self, model): + cmds = ['exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_model_fibonacci(self): - cmds = ['fibonacci', 'exit'] - exec(cmds) - - @pytest.mark.main - def test_one_anyon_vac(self): - cmds = ['ising', 'anyon1 vac', 'done', 'exit'] - exec(cmds) + def test_one_anyon_vac(self, model): + cmds = ['anyon1 vac', 'done', 'exit'] + exec(model, cmds) @pytest.mark.main def test_one_anyon_sigma(self): - cmds = ['ising', 'anyon1 sigma', 'done', 'exit'] - exec(cmds) + model = 'ising' + cmds = ['anyon1 sigma', 'done', 'exit'] + exec(model, cmds) @pytest.mark.main def test_one_anyon_psi(self): - cmds = ['ising', 'anyon1 psi', 'done', 'exit'] - exec(cmds) + model = 'ising' + cmds = ['anyon1 psi', 'done', 'exit'] + exec(model, cmds) + + @pytest.mark.main + def test_one_anyon_tau(self): + model = 'fibonacci' + cmds = ['anyon1 tau', 'done', 'exit'] + exec(model, cmds) + + @pytest.mark.main + def test_one_anyon_2D_ising(self): + model = 'ising' + cmds = ['anyon1 psi {1,2}', 'done', 'exit'] + exec(model, cmds) + + @pytest.mark.main + def test_one_anyon_2D_fib(self): + model = 'fibonacci' + cmds = ['anyon1 tau {1,2}', 'done', 'exit'] + exec(model, cmds) @pytest.mark.main - def test_one_anyon_2D(self): - cmds = ['ising', 'anyon1 psi {1,2}', 'done', 'exit'] - exec(cmds) + def test_two_anyons_ising(self): + model = 'ising' + cmds = ['anyon1 psi', 'anyon2 vac', 'done', 'exit'] + exec(model, cmds) @pytest.mark.main - def test_two_anyons(self): - cmds = ['ising', 'anyon1 psi', 'anyon2 vac', 'done', 'exit'] - exec(cmds) + def test_two_anyons_fib(self): + model = 'fibonacci' + cmds = ['anyon1 tau', 'anyon2 vac', 'done', 'exit'] + exec(model, cmds) @pytest.mark.main - def test_three_anyons(self): - cmds = ['ising', 'anyon1 vac', 'anyon2 sigma', 'anyon3 sigma', 'done', 'exit'] - exec(cmds) + def test_three_anyons_ising(self): + model = 'ising' + cmds = ['anyon1 vac', 'anyon2 sigma', 'anyon3 sigma', 'done', 'exit'] + exec(model, cmds) + + @pytest.mark.main + def test_three_anyons_fib(self): + model = 'fibonacci' + cmds = ['anyon1 vac', 'anyon2 tau', 'anyon3 tau', 'done', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_three_anyons_2D(self): - cmds = ['ising', 'anyon1 psi {-1,-1}', 'anyon2 vac {2,-1}', 'anyon3 vac {0,0}', 'done', 'exit'] - exec(cmds) + def test_three_anyons_2D(self, model): + cmds = ['anyon1 vac {-1,-1}', 'anyon2 vac {2,-1}', 'anyon3 vac {0,0}', 'done', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_three_anyons_2D_overlapping(self): - cmds = ['ising', 'anyon1 psi {-1,-1}', 'anyon2 vac {2,-1}', 'anyon3 vac {2,-1}', 'done', 'exit'] - exec(cmds) + def test_three_anyons_2D_overlapping(self, model): + cmds = ['anyon1 vac {-1,-1}', 'anyon2 vac {2,-1}', 'anyon3 vac {2,-1}', 'done', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_four_anyons(self): - cmds = ['ising', 'anyon1 psi', 'anyon2 psi', 'anyon3 psi', 'anyon4 psi', 'done', 'exit'] - exec(cmds) + def test_four_anyons(self, model): + cmds = ['anyon1 vac', 'anyon2 vac', 'anyon3 vac', 'anyon4 vac', 'done', 'exit'] + exec(model, cmds) class TestBraidAndFuse: @pytest.mark.main - def test_braid_and_print(self): - cmds = ['ising', 'anyon1 psi', 'anyon2 sigma', 'anyon3 psi', 'done', 'braid swap anyon1 anyon2', 'braid print', 'exit'] - exec(cmds) + def test_braid_and_print_ising(self): + model = 'ising' + cmds = ['anyon1 psi', 'anyon2 sigma', 'anyon3 psi', 'done', 'braid swap anyon1 anyon2', 'braid print', 'exit'] + exec(model, cmds) + + @pytest.mark.main + def test_braid_and_print_fib(self): + model = 'fibonacci' + cmds = ['anyon1 tau', 'anyon2 tau', 'anyon3 tau', 'done', 'braid swap anyon1 anyon2', 'braid print', 'exit'] + exec(model, cmds) + + @pytest.mark.main + def test_braid_and_print_2D_ising(self): + model = 'ising' + cmds = ['anyon1 psi {8,-4}', 'anyon2 sigma {5,5}', 'anyon3 psi {1,-1}', 'done', 'braid swap anyon1 anyon2', 'braid print', 'exit'] + exec(model, cmds) @pytest.mark.main - def test_braid_and_print_2D(self): - cmds = ['ising', 'anyon1 psi {8,-4}', 'anyon2 sigma {5,5}', 'anyon3 psi {1,-1}', 'done', 'braid swap anyon1 anyon2', 'braid print', 'exit'] - exec(cmds) + def test_braid_and_print_2D_fib(self): + model = 'fibonacci' + cmds = ['anyon1 tau {8,-4}', 'anyon2 tau {5,5}', 'anyon3 tau {1,-1}', 'done', 'braid swap anyon1 anyon2', 'braid print', 'exit'] + exec(model, cmds) class TestListAndHelp: + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_list_one_anyon(self): - cmds = ['ising', 'anyon1 psi', 'done', 'list', 'exit'] - exec(cmds) + def test_list_one_anyon(self, model): + cmds = ['anyon1 vac', 'done', 'list', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_list_three_anyons(self): - cmds = ['ising', 'anyon1 psi', 'anyon2 psi', 'anyon3 vac', 'done', 'list', 'exit'] - exec(cmds) + def test_list_three_anyons(self, model): + cmds = ['anyon1 vac', 'anyon2 vac', 'anyon3 vac', 'done', 'list', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_list_three_anyons_2D(self): - cmds = ['ising', 'anyon1 psi {9,17}', 'anyon2 psi {4,-106}', 'anyon3 vac {-1,4}', 'done', 'list', 'exit'] - exec(cmds) + def test_list_three_anyons_2D(self, model): + cmds = ['anyon1 vac {9,17}', 'anyon2 vac {4,-106}', 'anyon3 vac {-1,4}', 'done', 'list', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_help_command(self): - cmds = ['ising', 'anyon1 psi', 'done', 'help', 'exit'] - exec(cmds) + def test_help_command(self, model): + cmds = ['anyon1 vac', 'done', 'help', 'exit'] + exec(model, cmds) class TestInvalidCommands: @pytest.mark.main def test_model_invalid(self): - cmds = ['derp', 'exit'] - exec(cmds) + model = 'derp' + cmds = ['exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_anyon_invalid_charge(self): - cmds = ['ising', 'anyon1 derp', 'exit'] - exec(cmds) + def test_anyon_invalid_charge(self, model): + cmds = ['anyon1 derp', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_anyon_invalid_position1(self): - cmds = ['ising', 'anyon1 psi {3, 4, 5}', 'exit'] - exec(cmds) + def test_anyon_invalid_position1(self, model): + cmds = ['anyon1 vac {3, 4, 5}', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_anyon_invalid_position2(self): - cmds = ['ising', 'anyon1 psi {5,}', 'exit'] - exec(cmds) + def test_anyon_invalid_position2(self, model): + cmds = ['anyon1 vac {5,}', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_anyon_invalid_position3(self): - cmds = ['ising', 'anyon1 psi [4,5]', 'exit'] - exec(cmds) + def test_anyon_invalid_position3(self, model): + cmds = ['anyon1 vac [4,5]', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_anyon_invalid_position4(self): - cmds = ['ising', 'anyon1 psi {3; 5}', 'exit'] - exec(cmds) + def test_anyon_invalid_position4(self, model): + cmds = ['anyon1 vac {3; 5}', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_invalid_command_post_init(self): - cmds = ['ising', 'anyon1 psi', 'anyon2 psi', 'anyon3 psi', 'done', 'derp', 'exit'] - exec(cmds) + def test_invalid_command_post_init(self, model): + cmds = ['anyon1 vac', 'anyon2 vac', 'anyon3 vac', 'done', 'derp', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_invalid_braid_syntax(self): - cmds = ['ising', 'anyon1 psi', 'anyon2 psi', 'anyon3 psi', 'done', 'braid swap derp derp', 'exit'] - exec(cmds) + def test_invalid_braid_syntax(self, model): + cmds = ['anyon1 vac', 'anyon2 vac', 'anyon3 vac', 'done', 'braid swap derp derp', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_model_post_init(self): - cmds = ['ising', 'anyon1 psi', 'done', 'model fibonacci', 'exit'] - exec(cmds) + def test_model_post_init(self, model): + cmds = ['anyon1 vac', 'done', 'model fibonacci', 'exit'] + exec(model, cmds) + @pytest.mark.parametrize('model', ['ising', 'fibonacci']) @pytest.mark.main - def test_anyon_post_init(self): - cmds = ['ising', 'anyon1 psi', 'done', 'anyon anyon2 psi', 'exit'] - exec(cmds) + def test_anyon_post_init(self, model): + cmds = ['anyon1 vac', 'done', 'anyon anyon2 vac', 'exit'] + exec(model, cmds)