import pytest
from services.Challenges import Challenges
@pytest.fixture
def challenges():
challenges = Challenges()
return challenges
@pytest.mark.usefixtures()
class TestFind:
def test_empty_empty_not_found( self ):
assert -1 == Challenges.find( '' , '' )
def test_empty_source_not_found( self ):
assert -1 == Challenges.find( 'test_source' , '' )
def test_empty_target_not_found( self ):
assert -1 == Challenges.find( '' , 'empty_source' )
def test_target_longer_than_source_not_found( self ):
assert -1 == Challenges.find( 'abcd' , 'abc' )
def test_single_character_first_match( self ):
assert 0 == Challenges.find( 'a' , 'abcd' )
def test_single_character_middle_match( self ):
assert 1 == Challenges.find( 'b' , 'abcd' )
def test_single_character_end_match( self ):
assert 3 == Challenges.find( 'd' , 'abcd' )
def test_single_character_not_found( self ):
assert -1 == Challenges.find( 'z' , 'abcd' )
def test_two_characters_first_match( self ):
assert 0 == Challenges.find( 'ab' , 'abcd' )
def test_two_characters_middle_match( self ):
assert 1 == Challenges.find( 'bc' , 'abcd' )
def test_two_characters_end_match( self ):
assert 2 == Challenges.find( 'cd' , 'abcd' )
def test_multi_match_first_match( self ):
assert 1 == Challenges.find( 'cat' , 'acatcarcat' )
def test_multi_match_second_match( self ):
assert 7 == Challenges.find( 'cat' , 'acatcarcat', start_index=2 )
@pytest.mark.usefixtures()
class TestRemove:
def test_empty_empty_not_found( self ):
assert not Challenges.remove( '' , '' )
def test_empty_source_not_found( self ):
assert not Challenges.remove( 'test_source' , '' )
def test_empty_target_not_found( self ):
assert not Challenges.remove( '' , 'empty_source' )
def test_target_longer_than_source_not_found( self ):
assert not Challenges.remove( 'abcd' , 'abc' )
def test_single_character_first_match( self ):
assert 'bcd' == Challenges.remove( 'a' , 'abcd' )
def test_single_character_middle_match( self ):
assert 'acd' == Challenges.remove( 'b' , 'abcd' )
def test_single_character_end_match( self ):
assert 'abc' == Challenges.remove( 'd' , 'abcd' )
def test_single_character_not_found( self ):
assert None == Challenges.remove( 'z' , 'abcd' )
def test_two_characters_first_match( self ):
assert 'cd' == Challenges.remove( 'ab' , 'abcd' )
def test_two_characters_middle_match( self ):
assert 'ad' == Challenges.remove( 'bc' , 'abcd' )
def test_two_characters_end_match( self ):
assert 'ab' == Challenges.remove( 'cd' , 'abcd' )
def test_multi_match( self ):
assert 'acarcatcat' == Challenges.remove( 'cat' , 'acatcarcatcat' )
def test_multi_match_second_duplicate_match( self ):
assert 'acatcarcat' == Challenges.remove( 'cat' , 'acatcarcatcat', start_index=2 )
def test_multi_match_third_duplicate_match( self ):
assert 'acatcarcat' == Challenges.remove( 'cat' , 'acatcarcatcat', start_index=8 )
def test_multi_match_second_match( self ):
assert 'acatcarbcat' == Challenges.remove( 'cat' , 'acatcarcatbcat', start_index=2 )
def test_multi_match_third_match( self ):
assert 'acatcarcatb' == Challenges.remove( 'cat' , 'acatcarcatbcat', start_index=8 )
@pytest.mark.usefixtures()
class TestRemoveAll:
def test_two_characters_middle_match( self ):
assert 'ad' == Challenges.remove_all( 'bc' , 'abcd' )
def test_duplicate_characters( self ):
assert 'd' == Challenges.remove_all( 'a' , 'aaad' )
def test_match( self ):
assert 'acar' == Challenges.remove_all( 'cat' , 'acatcarcat' )
#TODO: what if it skips somehow?