Skip to content

Commit

Permalink
Parametrized tests with a decorator
Browse files Browse the repository at this point in the history
Runs all tests with both trie constructors now, when adding a new test,
use the same decorator and it will run the test func twice
  • Loading branch information
petr-tik committed Feb 9, 2018
1 parent 1864b37 commit 89db4db
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,38 @@
from py_trie import PyTrie


def test_find_added():
tr = cTrie()
constructors = [cTrie, PyTrie]


@pytest.mark.parametrize("constructor", constructors)
def test_find_added(constructor):
tr = constructor()
tr.add("bob")
assert tr.find("bob") == 1


def test_find_incomplete():
tr = cTrie()
@pytest.mark.parametrize("constructor", constructors)
def test_find_incomplete(constructor):
tr = constructor()
tr.add("boban")
assert tr.find("bob") == 0


def test_find_missing_missing_letter_before():
tr = cTrie()
@pytest.mark.parametrize("constructor", constructors)
def test_find_missing_missing_letter_before(constructor):
tr = constructor()
tr.add("bob")
assert tr.find("alice") == 0


def test_find_missing_letters_exist_after():
tr = cTrie()
@pytest.mark.parametrize("constructor", constructors)
def test_find_missing_letters_exist_after(constructor):
tr = constructor()
tr.add("bob")
assert tr.find("zlice") == 0


def test_find_missing_before_add():
tr = cTrie()
@pytest.mark.parametrize("constructor", constructors)
def test_find_missing_before_add(constructor):
tr = constructor()
assert tr.find("me") == 0

0 comments on commit 89db4db

Please sign in to comment.