def test_justify(): text = ( 'Fusce id tincidunt arcu. Pellentesque a ' 'leo laoreet quam varius convallis. ' 'Curabitur facilisis leo tortor, nec semper diam porta eu.') result = justify.justify(text, 40) line = result.split('\n')[-2] assert line[-1] != ' ', 'Justified error'
def test_unicode(): text = ( 'Якось кішка говорила:' '-- "Щось я, мабуть, захворіла!' 'Чомусь нікуди не ходжу, ' 'Тільки все лежу й лежу.') result = justify.justify(text, 60) assert 'кішка' in result, 'Unicode error'
def main(): # the program is written by Lei Yang (ly888) # the main function to calculate and plot daily return. # if the user input is not valid, the program will let the user to input again until valid or enter quit positions = input( "Enter a list of the number of shares to buy in parallel: e.g. 1,10,100,1000 or stop this process by entering quit \n" ) positions_split = positions.split(",") # justify if the input value is valid flag = justify(positions_split) # if the user input quit, the program will stop. if the user input invalid value, the program will ask the user to input again while (positions != 'quit' and flag == 1): positions = input( "The last input is not valid. Please enter a list of the number of shares to buy in parallel: e.g. 1,10,100,1000 or stop this process by entering quit \n" ) if (positions == 'quit'): break positions_split = positions.split(",") # justify if the input value is valid flag = justify(positions_split) if (positions != 'quit'): flag = 0 num_trials = input( "How many times to randomly repeat the test? Or stop this process by entering quit \n" ) # justify if the input value is valid if num_trials.isdigit() == False: flag = 1 # if the user input quit, the program will stop. if the user input invalid value, the program will ask the user to input again while (num_trials != 'quit' and flag == 1): flag = 0 num_trials = input( "The last input is not valid. How many times to randomly repeat the test? Or stop this process by entering quit \n" ) # justify if the input value is valid if num_trials.isdigit() == False: flag = 1 if (num_trials == 'quit'): break # if all the input are valid, the program will calculate the results and plot if (positions != 'quit' and num_trials != 'quit'): positions_list = [int(position) for position in positions_split] outcome = invest(positions_list, int(num_trials)) outcome.invest_sub()
def test_example(): paragraph = 'This is a sample text but a complicated problem to be solved, so we are adding more text to see that it actually works.' width = 20 assert justify(paragraph, width) == [ "This is a sample", "text but a", "complicated problem", "to be solved, so we", "are adding more text", "to see that it", "actually works.", ]
def main(): # the program is written by Lei Yang (ly888) # the main function to calculate and plot daily return. # if the user input is not valid, the program will let the user to input again until valid or enter quit positions = input("Enter a list of the number of shares to buy in parallel: e.g. 1,10,100,1000 or stop this process by entering quit \n") positions_split = positions.split(","); # justify if the input value is valid flag=justify(positions_split); # if the user input quit, the program will stop. if the user input invalid value, the program will ask the user to input again while(positions != 'quit' and flag==1): positions=input("The last input is not valid. Please enter a list of the number of shares to buy in parallel: e.g. 1,10,100,1000 or stop this process by entering quit \n") if(positions =='quit'): break; positions_split = positions.split(","); # justify if the input value is valid flag=justify(positions_split); if(positions != 'quit'): flag=0; num_trials = input("How many times to randomly repeat the test? Or stop this process by entering quit \n"); # justify if the input value is valid if num_trials.isdigit()==False: flag=1; # if the user input quit, the program will stop. if the user input invalid value, the program will ask the user to input again while(num_trials != 'quit' and flag==1): flag=0; num_trials = input("The last input is not valid. How many times to randomly repeat the test? Or stop this process by entering quit \n"); # justify if the input value is valid if num_trials.isdigit()==False: flag=1; if(num_trials == 'quit'): break; # if all the input are valid, the program will calculate the results and plot if(positions!='quit' and num_trials !='quit'): positions_list = [int(position) for position in positions_split]; outcome = invest(positions_list, int(num_trials)); outcome.invest_sub();
def test_line_width(): text = 'Lorem ipsum dolor sit amet. consectetur adipiscing elit.' result = justify.justify(text, 60) line = result.split('\n')[0] assert len(line) == 60, 'Incorrect line width'
def test_indentation(): text = 'Lorem ipsum' result = justify.justify(text, 60) assert result[0:4] == justify.TEXT_INDENT, 'No indentation'
def test_zero_width(): with pytest.raises(ValueError): justify('', 0)
def test_two_lines(): paragraph = 'Hello, world!' assert justify(paragraph, len(paragraph) - 1) == [ 'Hello,', 'world!' ]
def test_one_line(): paragraph = 'Hello, world!' assert justify(paragraph, len(paragraph)) == [ 'Hello, world!' ]
def test_long_word(): paragraph = 'Hello, world!' assert justify(paragraph, 1) == [ 'Hello,', 'world!' ]
def test_empty_paragraph(): assert justify('', 1) == []