Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test main.py #54

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 139 additions & 8 deletions python/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os

import pytest
from unittest.mock import patch
import sh


Expand All @@ -18,14 +19,144 @@ def exec(cmds: list[str]):
finally:
os.chdir('../..')

class TestInit:
@pytest.mark.main
def test_model_ising(self):
cmds = ['ising', 'exit']
exec(cmds)

@pytest.mark.main
def test_join():
cmds = ['ising', 'exit']
exec(cmds)
@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)

@pytest.mark.main
def test_fusion():
cmds = ['ising', 'anyon psi 0 0', 'anyon sigma 1 0', 'fusion 0 1', 'exit']
exec(cmds)
@pytest.mark.main
def test_one_anyon_sigma(self):
cmds = ['ising', 'anyon1 sigma', 'done', 'exit']
exec(cmds)

@pytest.mark.main
def test_one_anyon_psi(self):
cmds = ['ising', 'anyon1 psi', 'done', 'exit']
exec(cmds)

@pytest.mark.main
def test_one_anyon_2D(self):
cmds = ['ising', 'anyon1 psi {1,2}', 'done', 'exit']
exec(cmds)

@pytest.mark.main
def test_two_anyons(self):
cmds = ['ising', 'anyon1 psi', 'anyon2 vac', 'done', 'exit']
exec(cmds)

@pytest.mark.main
def test_three_anyons(self):
cmds = ['ising', 'anyon1 vac', 'anyon2 sigma', 'anyon3 sigma', 'done', 'exit']
exec(cmds)

@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)

@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)

@pytest.mark.main
def test_four_anyons(self):
cmds = ['ising', 'anyon1 psi', 'anyon2 psi', 'anyon3 psi', 'anyon4 psi', 'done', 'exit']
exec(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)

@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)

@pytest.mark.main
def test_fusion(self):
cmds = ['ising', 'anyon1 psi', 'anyon2 sigma', 'done', 'fusion anyon1 anyon2', 'exit']
exec(cmds)

@pytest.mark.main
def test_fusion_2D(self):
cmds = ['ising', 'anyon1 psi {0,1}', 'anyon2 sigma {-1,500}', 'done', 'fusion anyon1 anyon2', 'exit']
exec(cmds)

class TestListAndHelp:
@pytest.mark.main
def test_list_one_anyon(self):
cmds = ['ising', 'anyon1 psi', 'done', 'list', 'exit']
exec(cmds)

@pytest.mark.main
def test_list_three_anyons(self):
cmds = ['ising', 'anyon1 psi', 'anyon2 psi', 'anyon3 vac', 'done', 'list', 'exit']
exec(cmds)

@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)

@pytest.mark.main
def test_help_command(self):
cmds = ['ising', 'anyon1 psi', 'done', 'help', 'exit']
exec(cmds)

class TestInvalidCommands:
@pytest.mark.main
def test_model_invalid(self):
cmds = ['derp', 'exit']
exec(cmds)

@pytest.mark.main
def test_anyon_invalid_charge(self):
cmds = ['ising', 'anyon1 derp', 'exit']
exec(cmds)

@pytest.mark.main
def test_invalid_command_post_init(self):
cmds = ['ising', 'anyon1 psi', 'anyon2 psi', 'anyon3 psi', 'done', 'derp', 'exit']
exec(cmds)

@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)

@pytest.mark.main
def test_invalid_fusion_syntax(self):
cmds = ['ising', 'anyon1 psi', 'anyon2 psi', 'anyon3 psi', 'done', 'fusion derp derp', 'exit']
exec(cmds)

@pytest.mark.main
def test_model_post_init(self):
cmds = ['ising', 'anyon1 psi', 'done', 'model fibonacci', 'exit']
exec(cmds)

@pytest.mark.main
def test_anyon_post_init(self):
cmds = ['ising', 'anyon1 psi', 'done', 'anyon anyon2 psi', 'exit']
exec(cmds)


# @pytest.mark.main
# def test_shell():
# with patch('subprocess.run') as mock_run:
# shell = SimulatorShell()
# shell.do_shell('echo Let\'s go, Brandon!')
# mock_run.assert_called_once_with('echo Hello, World!', shell=True)