Пример #1
0
# pass_check: None -> Str
# Examples:
# If the user enters 'hi there' when pass_check() is called, prints 
#   'Invalid password'
# If the user enters 'boB35' when pass_check() is called, prints 'Thank you!'
#   and 'boB35' is returned
def pass_check():
    my_password = str(input(welcome_msg))
    if valid_password(my_password, 0):
        print(end_msg)
        return my_password
    else:
        print(invalid_msg)
        return pass_check()
    
# Test Valid password
check.set_input(["Ab3"])
check.set_screen("Thank you!")
check.expect("Q1T1", pass_check(), "Ab3")

# Test Invalid password, only contain number, lower-case or upper-case
check.set_input(["abc", "123", "ABC","Af3"])
check.set_screen("Invalid password\nInvalid password\nInvalid password\nThank you!")
check.expect("Q1T2", pass_check(), "Af3")

# Test Invalid password, contain two of number, lower-case or upper-case
check.set_input(["af3", "afFFG", "AF346", "AFfe3"])
check.set_screen("Invalid password\nInvalid password\nInvalid password\nThank you!")
check.expect("Q1T3", pass_check(), "AFfe3")

Пример #2
0
# Example: the function will give "Thank you!" only when all the checks above/
#          are met
def pass_check():
    s = input(welcome_msg)
    i = len(s) - 1
    if check_lower(s, i) > 0 and check_upper(s, i) > 0 and check_num(
            s, i) > 0 and check_space(s, i):
        print(end_msg)
    else:
        print(invalid_msg)
        return pass_check()
    return s


# Tests:
check.set_screen('welcome_msg and end_msg are printed')
check.set_input(['Boc123'])
check.expect("Q1T1", pass_check(), 'Boc123')

check.set_screen(
    'welcome_msg and end_msg are printed with 1 error because of/ missing upper case'
)
check.set_input(['boc123', 'Boc123'])
check.expect("Q1T2", pass_check(), 'Boc123')

check.set_screen(
    'welcome_msg and end_msg are printed with 1 error because of/ missing lower case'
)
check.set_input(['BOC123', 'Boc123'])
check.expect("Q1T3", pass_check(), 'Boc123')
    elif password.isdigit():
        print('The password ("' + password + '") failed a basic test')
        return False
    if len(password) < 5:
        strength_points = strength_points - 10
    if len(password) > 8:
        strength_points = strength_points + 10
    if password.lower() != password and has_digit(password):
        strength_points = strength_points + 10
    specials = num_of_sp(password, "")
    if specials > 0:
        strength_points = strength_points + (20 + (5 * (specials - 1)))
    return strength_points

# Q1 Test 1: Empty string
check.set_screen('The password ("") failed a basic test')
check.expect("T1", password_strength(""), False)

# Q1 Test 2: lower case password
check.set_screen('The password ("PaSSword") failed a basic test')
check.expect("T2", password_strength("PaSSword"), False)

# Q1 Test 3: only lower case
check.set_screen('The password ("newpassword") failed a basic test')
check.expect("T3", password_strength("newpassword"), False)

# Q1 Test 4: only upper case
check.set_screen('The password ("ASDF") failed a basic test')
check.expect("T4", password_strength("ASDF"), False)

# Q1 Test 5: all digits
Пример #4
0
  update_dashes("bubble", "b-bb--", "e") -> None 
  and prints "b-bb-e"
  
  update_dashes("python", "p-----", "x") -> None 
  and prints "p-----"
  
  update_dashes("cs", "-s", "c") -> None 
  and prints "cs"
  '''
    replace_dashes = dashes.replace("-", guess)
    answer = compare_and_replace(secret, replace_dashes)
    print(answer)


## Guess at end str
check.set_screen("b-bb-e")
check.expect("Q3E1:", update_dashes("bubble", "b-bb--", "e"), None)

## Replacing more than 1 of the same char in dashes
check.set_screen("b-bb--")
check.expect("Q3E2:", update_dashes("bubble", "------", "b"), None)

## Guess not in secret
check.set_screen("p-----")
check.expect("Q3E3:", update_dashes("python", "p-----", "x"), None)

## Types of dashes: Case 1
check.set_screen("c-")
check.expect("Q3E4:", update_dashes("cs", "--", "c"), None)

## Types of dashes: Case 2
Пример #5
0
        if u_l_and_d and special_chars == 1:
            return score + 30
        if not (u_l_and_d) and special_chars == 1:
            return score + 20
        if u_l_and_d and special_chars == 0:
            return score + 10
        if not (u_l_and_d) and special_chars == 0:
            return score
        if u_l_and_d and special_chars > 1:
            return score + 10 + 20 + (special_chars - 1) * 5
        if not (u_l_and_d) and special_chars > 1:
            return score + 20 + (special_chars - 1) * 5


# Tests for password strength
check.set_screen('The password  failed a basic test')
check.expect('Q1T0', password_strength(''), False)

check.set_screen('The password PassWORd failed a basic test')
check.expect('Q1T1', password_strength('PassWORd'), False)

check.set_screen('The password lowercase failed a basic test')
check.expect('Q1T2', password_strength('lowercase'), False)

check.set_screen('The password UPPERCASE failed a basic test')
check.expect('Q1T3', password_strength('UPPERCASE'), False)

check.set_screen('The password 123456 failed a basic test')
check.expect('Q1T4', password_strength('123456'), False)

check.expect('Q1T5', password_strength('123f'), -10)
            if (c + r) % 2 == 0:
                print(" ", end = "")
            elif (c + r) % 2 != 0:
                print("#", end = "")
            if c == cols - 1:
                print("|")
        if r == rows - 1:
            for c in range(cols):
                if c == 0:
                    print("+", end = "")
                print("-", end = "")
                if c == cols - 1:
                    print("+")
                    
# Q2 Test 1: small even board - 2x2
check.set_screen("+--+\n| #|\n|# |\n+--+")
check.expect("T1", print_checkerboard(2,2), None)

# Q2 Test 2: small odd board - 3x3
check.set_screen("+---+\n| # |\n|# #|\n| # |\n+---+")
check.expect("T2", print_checkerboard(3,3), None)

# Q2 Test 3: small even/odd board - 2x3
check.set_screen("+---+\n| # |\n|# #|\n+---+")
check.expect("T3", print_checkerboard(2,3), None)

# Q2 Test 4: large even board - 10x12
check.set_screen("+------------+\n| # # # # # #|\n|# # # # # # |\n| # # # # # #|\n|# # # # # # |\n| # # # # # #|\n|# # # # # # |\n| # # # # # #|\n|# # # # # # |\n| # # # # # #|\n|# # # # # # |\n+------------+")
check.expect("T4", print_checkerboard(10,12), None)

# Q2 Test 5: large odd board - 7x7
Пример #7
0
        print("Enter 1 to take " + str(board[0]))
        print("Enter 2 to take " + str(board[1]))
        print("Enter 3 to take " + str(board[2]))
        print("Enter 4 to take " + str(board[3]))
        player_input = int(input(prompt))
        taken_row = board[player_input - 1]
        board[player_input - 1] = [card]
        return taken_row
    smallest_index = list_of_diff.index(min_diff)
    if len(board[smallest_index]) == full_row:
        old_row = board[smallest_index]
        board[smallest_index] = [card]
        return old_row
    else:
        board[smallest_index].append(card)
        return True
    
# Q4 Test 1 card smaller than all last elements:
check.set_screen('"Enter (row number) to take my_board[row number - 1]" for all 4 rows followed \
by "Enter choice: "')
check.set_input(["3"])
check.expect("T1", turn_6nimmt(my_board, 4), [8])
check.expect("T1{my_board}", my_board, [[67, 70], [9, 18, 19], [4], [13, 30, 50, 88, 93]])

# Q4 Test 2 card on full row
check.expect("T2", turn_6nimmt(my_board, 94), [13, 30, 50, 88, 93])
check.expect("T2{my_board}", my_board, [[67, 70], [9, 18, 19], [4], [94]])

# Q4 Test 3 card on not full row
check.expect("T3", turn_6nimmt(my_board, 20), True)
check.expect("T3{my_board}", my_board, [[67, 70], [9, 18, 19, 20], [4], [94]])
        comp_ans_num = fib_rec(game_num) % 3
        if comp_ans_num == 0:
            comp_ans = "r"
        elif comp_ans_num == 1:
            comp_ans = "p"
        else:
            comp_ans = "s"
        if (player_ans == "r" and comp_ans == "p") or (player_ans == "p" and comp_ans == "s") or (player_ans == "s" and comp_ans == "r"):
            comp_wins = comp_wins + 1
            print("Player plays: " + player_ans + ". Computer plays: " + comp_ans + ". Computer won.")
        elif (player_ans == "p" and comp_ans == "r") or (player_ans == "s" and comp_ans == "p") or (player_ans == "r" and comp_ans == "s"):
            player_wins = player_wins + 1
            print("Player plays: " + player_ans + ". Computer plays: " + comp_ans + ". Player won.")
        elif player_ans == comp_ans:
            tied_games = tied_games + 1
            print("Player plays: " + player_ans + ". Computer plays: " + comp_ans + ". Tied.")
    print("Thank you for playing! Total game statistics:")
    print("Tied games: " + str(tied_games) + ".")
    print("Player won " + str(player_wins) + " times.")
    print("Computer won " + str(comp_wins) + " times.")
    
# Q4 Test 1: one response
check.set_screen("Welcome to the Rock-Paper-Scissors game!\nHow would you like to play next [r/p/s/q]?\nPlayer plays: r. \
Computer plays: p. Computer won.\nHow would you like to play next [r/p/s/q]?\nThank you for playing! Total game statistics:\nTied games 0.\nPlayer won 0 times.\nComputer won 1 times.")
check.set_input(["r","q"])
check.expect("T1", play_rps(), None)

# Q4 Test 2: many responses
check.set_screen("Welcome to the Rock-Paper-Scissors game!\nHow would you like to play next [r/p/s/q]?\nPlayer plays: r. Computer plays: p. Computer won.\nHow would you like to play next [r/p/s/q]?\nPlayer plays: s. Computer plays: p. Player won.\nHow would you like to play next [r/p/s/q]?\nPlayer plays: p. Computer plays: s. Computer won.\nHow would you like to play next [r/p/s/q]?\nPlayer plays: s. Computer plays: r. Computer won.\nHow would you like to play next [r/p/s/q]?\nThank you for playing! Total game statistics:\nTied games 0.\nPlayer won 1 times.\nComputer won 3 times.")
check.set_input(["r","s","p","s","q"])
check.expect("T2", play_rps(), None)
Пример #9
0
# n is a natural number greater than 0
# Examples:
# make_poem("How many Lowes would Rob Lowe rob if Rob Lowe could rob Lowes", 3) 
#           will print:
#  How many Lowes
#  would Rob Lowe
#  rob if Rob
#  Lowe could rob
#  Lowes
def make_poem(s,n):
    k = space_position(s, n)
    if k >= len(s):
        print(s)
    else:
        print(s[0:k])
        make_poem(s[k+1:], n)

# Test Example, n = 3
check.set_screen("How many Lowes\nwould Rob Lowe\nrob if Rob\nLowe could rob\nLowes")
check.expect("Q4T1", make_poem("How many Lowes would Rob Lowe rob if Rob Lowe could rob Lowes", 3), 
             None)

# Test when n = 1
check.set_screen("abc\ndef\nhijk\nlmno\npQ")
check.expect("Q4T2", make_poem("abc def hijk lmno pQ",1), None)

# Test When n = 4
check.set_screen("my job is very\nawaresome and my dad\nis superman")
check.expect("Q4T3", make_poem("my job is very awaresome and my dad is superman", 4), None)

Пример #10
0
# Examples:
# If the user input is ["40" "49" "39" "13" "10"], number_game() prints "Your 
#   original number is 10"
def number_game():
    mul_4 = int(input(step1_msg))
    my_num = mul_4/4
    subtract_ori = plus_9(mul_4)
    divide_3 = sub_ori(subtract_ori, my_num)
    subtract_3 = div_3(divide_3)
    final_num = sub_3(subtract_3)
    print(final_msg.format(final_num))
    

# original number = 10
check.set_input(["40", "49", "39", "13", "10"])
check.set_screen("Your original number is 10")
check.expect("original number = 10", number_game(), None)

# original number = 7
check.set_input(["28", "32", "37", "30", "10", "7"])
check.set_screen("Think of a number. Multiply your number by 4:"
                 "Add 9:"
                 "That is not correct"
                 "Subtract the original number:"
                 "Divide by 3:"
                 "Your original number is 7")
check.expect("original number = 7", number_game(), None)

# original number = 1
check.set_input(["4", "13", "12", "3", "4", "1"])
check.set_screen("Think of a number. Multiply your number by 4:"
Пример #11
0
# ddddd
#  ddd
#   d
def print_diamond(k):
    num_spaces = k
    num_ds = 1
    for i in range(0,k):
        print " "*num_spaces + "d"*num_ds
        num_spaces = num_spaces - 1
        num_ds = num_ds + 2
    print "d"*num_ds
    for i in range(0,k):
        num_spaces = num_spaces + 1
        num_ds = num_ds - 2
        print " "*num_spaces + "d"*num_ds
check.set_screen('d')
check.expect("diamondT1", print_diamond(0), None)     
check.set_screen('Prints a diamond, 11-d wide at middle')
check.expect("diamondT1", print_diamond(5), None)

# Situation 3: using raw_input
# email: None -> str[len>=1]
# Produces a "friendly" uw email address for the first and last name 
# entered by the user
# Effects: Prompts the user for first and last name, and reads them in
# Example: If the user enters "Lori" and "Case" as first and last names, 
# produces "*****@*****.**"
def email(): 
    first_name = raw_input("enter your first name:\n")
    last_name = raw_input("enter your last name:\n")
    email = first_name + '.' + last_name + '@uwaterloo.ca'
Пример #12
0

def pass_check():
    enter = input(welcome_msg)
    if not(' ' in enter) and check_upper(enter) and \
       check_lower(enter) and check_digit(enter):
        print(end_msg)
        return enter
    else:
        print(invalid_msg)
        return pass_check()


## Tests:
check.set_input(['a', '3a', '3a A', '3aA'])
check.set_screen("the user tried 3 times and succeeded in the last time")
check.expect('t18', pass_check(), '3aA')
check.set_input(['5344rffFEFA###22!!'])
check.set_screen("the user succeed in the first time")
check.expect('t19', pass_check(), '5344rffFEFA###22!!')
check.set_input(
    ['aaAA', '2342A ERugfre 44 waterloo', '2342AERugfre44waterloo'])
check.set_screen("the user tried 2 times and succeed after removing the space")
check.expect('t20', pass_check(), '2342AERugfre44waterloo')
check.set_input(['chen', 'CHEN', 'Chen', 'Chen387'])
check.set_screen("the user succeeded in the last time")
check.expect('t21', pass_check(), 'Chen387')
check.set_input(['', ' ', 'C387Chen'])
check.set_screen("the user succeeded in the last time")
check.expect('t22', pass_check(), 'C387Chen')
check.set_input(['C333Chen Cuiyin', 'C333ChenCuiyin!!!'])
Пример #13
0
            continue

    f.close()
    return appt_book


# Test 1: empty text file
book1 = AppointmentBook()
check.expect("Q2T1", buildApptBook("q2_empty.txt"), book1)

# Test 2: text file with just a 'Make' command
book2 = AppointmentBook()
book2.makeAppointment(32, 12.0, "checkup")
check.expect("Q2T2", buildApptBook("q2_make.txt"), book2)

# Test 3: text file with just a 'Cancel' command
check.set_screen("There is no appointment at 9.5 on 10.")
check.expect("Q2T3", buildApptBook("q2_cancel.txt"), book1)

# Test 4: text file with just a 'Change' command
check.expect("Q2T4", buildApptBook("q2_change.txt"), book1)

# Test 5: text file with invalid inputs (values given are out of range)
check.expect("Q2T5", buildApptBook("q2_invalid.txt"), book1)

# Test 6: general case
book6 = AppointmentBook()
book6.makeAppointment(45, 10.5, "meeting")
book6.makeAppointment(120, 12.0, "discussion")
check.set_screen("There is no appointment at 15.0 on 80.")
check.expect("Q2T6", buildApptBook("appointment.txt"), book6)
Пример #14
0
    and prints [""]
  '''
  L[:] = list(map(lambda old_string: old_string[0:i] + s + old_string[i:], L))
  print(L)

## Examples
L1 = ["h"]
L2 = ["cat", "dog", "hamster"]
L3 = ["helloworld", "alphabet", "university"]
L4 = ["hi", "me", "it"]
L5 = [""]
L6 = []
L7 = ["cat", "doggo", "hamster"]
L8 = ["a", "b", "c"]
## i is equal to the length of string in L
check.set_screen(["height"])
check.expect("Q3E1", expand_strings(L1, "eight", 1), None)
# list with strings less than the index and a string more than the index
check.set_screen(['cat12345', 'dog12345', 'hams12345ter'])
check.expect("Q3E2", expand_strings(L2, "12345", 4), None)

## Tests
## list with strings with lengths more than the index
check.set_screen(["hell111oworld", "alph111abet", "univ111ersity"])
check.expect("Q3T1", expand_strings(L3, "111", 4), None)

## list with strings of same length but is less than the index
check.set_screen(["hi111", "me111", "it111"])
check.expect("Q3T2", expand_strings(L4, "111", 4), None)

## list with an empty string
            board[3]) == 5:
        old_row = board[3]
        board[3] = [card]
        return old_row


# Tests for turn_6nimmt
check.expect('Q4T1a', turn_6nimmt(my_board, 71), True)
check.expect('Q4T1b', my_board,
             [[67, 70, 71], [9, 18, 19], [8], [13, 30, 50, 88, 93]])
check.expect('Q4T2a', turn_6nimmt(my_board, 94), [13, 30, 50, 88, 93])
check.expect('Q4T2b', my_board, [[67, 70, 71], [9, 18, 19], [8], [94]])
check.expect('Q4T3a', turn_6nimmt(my_board, 25), True)
check.expect('Q4T3b', my_board, [[67, 70, 71], [9, 18, 19, 25], [8], [94]])
check.set_input(['2'])
check.set_screen('Choose one of the rows')
check.expect('Q4T4a', turn_6nimmt(my_board, 5), [9, 18, 19, 25])
check.expect('Q4T4b', my_board, [[67, 70, 71], [5], [8], [94]])
check.expect('Q4T5a', turn_6nimmt(my_board, 9), True)
check.expect('Q4T5b', my_board, [[67, 70, 71], [5], [8, 9], [94]])
check.expect('Q4T6a', turn_6nimmt(my_board, 10), True)
check.expect('Q4T6b', my_board, [[67, 70, 71], [5], [8, 9, 10], [94]])
check.expect('Q4T7a', turn_6nimmt(my_board, 11), True)
check.expect('Q4T7b', my_board, [[67, 70, 71], [5], [8, 9, 10, 11], [94]])
check.set_input(['3'])
check.set_screen('Choose one of the rows')
check.expect('Q4T8a', turn_6nimmt(my_board, 2), [8, 9, 10, 11])
check.expect('Q4T8b', my_board, [[67, 70, 71], [5], [2], [94]])
check.expect('Q4T9a', turn_6nimmt(my_board, 72), True)
check.expect('Q4T9b', my_board, [[67, 70, 71, 72], [5], [2], [94]])
check.expect('Q4T10a', turn_6nimmt(my_board, 73), True)
Пример #16
0
# call go_fish(L,5) should produce None and L becomes [card('spades',8), 
# card('diamonds',6)]

def go_fish(hand, v):
    count = 0
    for card in hand:
        if card.value == v:
            hand.remove(card)
            count = count + 1
    if count == 0:
        print output_string

# Tests
## base case: given list is an empty list
L = []
check.set_screen(output_string)
check.expect('q2t1a', go_fish(L,2), None)
check.expect('q2t1b', L, L)
## case when there is no card with the given integer
L = [card('spades',8),card('hearts',5),card('diamonds',6),card('clubs',5)]
check.set_screen(output_string)
check.expect('q2t2a', go_fish(L,9), None)
check.expect('q2t2b', L, L)
## case when the given list is mutated
L = [card('spades',8),card('hearts',5),card('diamonds',6),card('clubs',5)]
new_list = [card('spades',8), card('diamonds',6)]
check.expect('q2t3a', go_fish(L,5), None)
check.expect('q2t3b', L, new_list)
## a longer list
## mutation
L = [card('hearts',6), card('spades',10), card('spades',2), card('clubs',8), \
## Effects:
##* one value is read in
##* A string is printed
##* If the number is correctly entered another string will be printed
##* The final string printed will give the original number
## number_game: Null -> Null

## Examples:
# If the user enters 32 when the program is run. The program will guide the user
# to do a few calculations though prints. The program will then print the number
# the user was originally thinking of, which is 8


def number_game():
    msg1 = int(input(step1_msg))
    print(step2(msg1))


## Tests:

check.set_input(["32", "41", "33", "11", "8"])
check.set_screen("PROMPTS THEN: Your original number is 8")
check.expect("Test1", number_game(), None)

check.set_input(["24", "0", "45", "33", "27", "9", "6"])
check.set_screen("PROMPTS AND ERROR MESSAGES THEN: Your original number is 6")
check.expect("Test2", number_game(), None)

check.set_input(["28", "37", "30", "10", "7"])
check.set_screen("PROMPTS THEN: Your original number is 7")
check.expect("Test3", number_game(), None)
Пример #18
0
                print(general_message + "Computer won.")
                computer_win = computer_win + 1
            n = n + 1
            player_move = input(prompt)
            continue
    print(goodbye_message)
    print("Tied games:" + " " + str(tied_stats) + ".")
    print("Player won" + " " + str(player_win) + " " + "times.")
    print("Computer won" + " " + str(computer_win) + " " + "times.")


# Testing

# Test 1: Player enters "q" right away
check.set_input(["q"])
check.set_screen("0 tied games, 0 player wins, 0 computer wins")
check.expect("T1", rps(), None)

# Test 2: One round, tie game
check.set_input(["p", "q"])
check.set_screen("1 tie game, 0 player wins, 0 computer wins")
check.expect("T2", rps(), None)

# Test 3: One round, player wins
check.set_input(["s", "q"])
check.set_screen("0 tied games, 1 player win, 0 computer wins")
check.expect("T3", rps(), None)

# Test 4: One round, computer wins
check.set_input(["r", "q"])
check.set_screen("0 tied games, 0 player wins, 1 computer win")
Пример #19
0
# becomes [["cust1", "kitchener", 5192345647], ["cust2", "cambridge", 5192345647]]

def add_record(all_records,cust_record):
	phone_record = map(lambda list: list[2], all_records)
	new_phone = cust_record[2]
	check_new = filter(lambda ph_num: ph_num == new_phone, phone_record)
	if check_new == []:
		return all_records.append(cust_record)
	else:
		print phone_str % new_phone

# Tests
## adding a phone number 
all_records = [["cust1","kitchener",5192345647]] 
check.expect("Q4t1", add_record(all_records,["cust2","cambridge",5193243456]), None)
check.set_screen([["cust1", "kitchener", 5192345647], \
                  ["cust2", "cambridge", 5192345647]])
## phone number already exists
all_records = [["cust1","kitchener",5192345647]]
check.expect("Q4t2", add_record(all_records, \
                                ["cust2","cambridge",5192345647]), None)
check.set_screen("Phone number 5192345647 is already in the exisiting customer records")

##**************************************************************************

# delete_record: customer_list phone -> None

# Purpose: produces none by consuming a listof customer_record (all_records)
# and a 10-digit phone number(phone)

# Effect: Mutates (all_records) by deleting the entry with phone number
# (phone)
            print('Galloping search from index {}'.format(length_L-1))
        return pos
    else:
        if L[last] > n:
            None
        elif L[-1] > n:
            print('Galloping search from index {}'.format(length_L-1))
        else:
            print('Galloping search from index {}'.format(length_L-1))
        return False
    
galloping_search(5, [1,2,3,4,5,6,7,8])    
    
# Test:
# Test1: n in the L
check.set_screen('Galloping search 0,1,3,7  Binary search 4 to 6')
check.expect('T1', galloping_search(5, [1,2,3,4,5,6,7,8]), 4)

check.set_screen('Galloping search 0')
check.expect('T2', galloping_search(1, [1,2,3,4,5,6,7,8,9]), 0)

check.set_screen('Galloping search 0,1,3,7  Binary search 4 to 6')
check.expect('T3', galloping_search(7, [1,2,3,4,5,6,7,8,9]), 6)

check.set_screen('Galloping search 0,1,3,7')
check.expect('T4', galloping_search(8, [1,2,3,4,5,6,7,8,9]), 7)

check.set_screen('Galloping search 0,1,3,7,8')
check.expect('T5', galloping_search(9, [1,2,3,4,5,6,7,8,9]), 8)

# Test2: n not in the L
        z = input('Enter frame: ')

    print((8 + x + 2 * y * (x + 2)) * z)
    print(z + (2 + x) * " " + "--" + y * ((2 * x + 2) * ' ' + '--') + ":~" + z)
    i = 0
    while i < x:
        print(z + (1 + x - i) *" " + "/" + y*((2 + 2*i)*" " + "\\" + \
                        (2* (x - i ))*" " + "/") + ((4 + i) * " ") + z)
        i = i + 1
    print(z + "--" + y * ((2 * x + 2) * " " + "--") + (4 + x) * " " + z)
    print((8 + x + 2 * y * (x + 2)) * z)


#examples
check.set_input('a', '1', '0', '#')
check.set_screen('Invalid input.\n#########\n\
#   --:~#\n#  /    #\n#--     #\n#########')
check.expect("ex1", snake(), None)

check.set_input('a', '0', '3', '1', '$$', "hello", "*")
check.set_screen('Invalid input.\nInvalid input.\nInvalid input.\n\
Invalid input.\n*********************\n*     --        --:~*\n\
*    /  \      /    *\n*   /    \    /     *\n*  /      \  /      *\n\
*--        --       *\n*********************')
check.expect("ex2", snake(), None)

#tests

check.set_input('1', '0', '#')
check.set_screen('#########\n#   --:~#\n#  /    #\n#--     #\n#########')
check.expect("Test1", snake(), None)
Пример #22
0
    if a == len(s1) - 1:
        return s1[len(s1) - 1]
    else:
        if s1[a] == " " and b == n1 - 1:
            return separate(a + 1, b + 1, s1, n1)
        elif s1[a] == " ":
            return s1[a] + separate(a + 1, b + 1, s1, n1)
        elif b == n1:
            return "\n" + s1[a] + separate(a + 1, 0, s1, n1)
        else:
            return s1[a] + separate(a + 1, b, s1, n1)


# Tests:
check.set_screen(
    '"How many Lowes would Rob Lowe rob if Rob Lowe could rob/ Lowes" is printed with 1 word in each line'
)
check.expect(
    "Q4T1",
    make_poem("How many Lowes would Rob Lowe rob if Rob Lowe/ could rob Lowes",
              1), None)

check.set_screen(
    '"How many Lowes would Rob Lowe rob if Rob Lowe could rob/ Lowes" is printed with 3 word in each line'
)
check.expect(
    "Q4T2",
    make_poem("How many Lowes would Rob Lowe rob if Rob Lowe/ could rob Lowes",
              3), None)

check.set_screen(
# If the user enters 'hi there' when pass_check() is called, prints 
#   'Invalid password'
# If the user enters 'boB35' when pass_check() is called, prints 'Thank you!'
#   and 'boB35' is returned
def pass_check():
    my_password = str(input(welcome_msg))
    if valid_password(my_password, 0):
        print(end_msg)
        return my_password
    else:
        print(invalid_msg)
        return pass_check()
    
# Test Valid password
check.set_input(["Ab3"])
check.set_screen("Thank you!")
check.expect("Q1T1", pass_check(), "Ab3")

# Test Invalid password, only contain number, lower-case or upper-case
check.set_input(["abc", "123", "ABC","Af3"])
check.set_screen("Invalid password\nInvalid password\nInvalid password\nThank you!")
check.expect("Q1T2", pass_check(), "Af3")

# Test Invalid password, contain two of number, lower-case or upper-case
check.set_input(["af3", "afFFG", "AF346", "AFfe3"])
check.set_screen("Invalid password\nInvalid password\nInvalid password\nThank you!")
check.expect("Q1T3", pass_check(), "AFfe3")



**** a03q2.py *****************************************************************
Пример #24
0
                D.update({tar_dec: value-1})
        if cmd == 'A':
            all_value = reduce(lambda x,y: x+y, D.values())
            count = len(D)
            outcome = float(all_value)/count
            print '%.2f' %outcome 
        cmd = raw_input(cmd_prompt)
    for key in sorted(D):
        value = str(D[key])
        print key, value
            
# Test
## average of the values in dictionary
D = {'mary':6,'bob':3}
check.set_input(['A'])
check.set_screen(4.50)
check.expect('q4t1a', memory(D), None)
check.expect('q4t1b', D, D)
## increse one of the value in dictionary by 1
check.set_input(['I', 'mary'])
check.expect('q4t2a', memory(D), None)
check.expect('q4t2b', D, {'mary':7,'bob':3})
## compare the two key values, G
check.set_input(['G', 'mary','bob'])
check.set_screen(True)
check.expect('q4t3a', memory(D), None)
check.expect('q4t3b', D, D)
## compare the two key values, L
check.set_input(['L', 'mary','bob'])
check.set_screen(False)
check.expect('q4t4a', memory(D), None)
Пример #25
0
            flips[3] = 0
        elif flips[2] == 4:
            b1.flip()
            flips[1] += 1
            flips[2] = 0
        elif rotations[4] == 4:
            b3.rotate()
            rotations[3] += 1
            rotations[4] = 0
        elif rotations[3] == 4:
            b2.rotate()
            rotations[2] += 1
            rotations[3] = 0
        elif rotations[2] == 4:
            b1.rotate()
            rotations[1] += 1
            rotations[2] = 0
        elif rotations[1] == 4:
            b4.flip()
            flips[4] += 1
            rotations[1] = 0
        else:
            b4.rotate()
            rotations[4] += 1
        counter += 1
    return 'No solution'


check.set_screen("prints number of moves and block states")
check.expect("test1", solve(red, spruce, birch, black), None)
Пример #26
0
    good_message = "Good" 
    password = input("Enter password: "******"goodPass12!@@")
check.set_screen("Good")
check.expect("Q4E1:", new_password(), None)

## Fair case
check.set_input("fairPass !!!")
check.set_screen("Fair")
check.expect("Q4E2:", new_password(), None)

## Weak case
check.set_input("weak12!")
check.set_screen("Weak")
check.expect("Q4E3:", new_password(), None)

## has a space, no numbers, only 1 alphanumeric
check.set_input("Hello World!")
check.set_screen("Weak")
Пример #27
0
                    print('Galloping search from index ' + str(len(L) - 1))
                    return False
        else:
            print('Galloping search from index ' + str(ind))
            L_new = L[int((ind + 1) / 2):ind]
            print('Binary search from index ' + str(int((ind + 1) / 2)) +
                  ' to ' + str(ind - 1))
            if binary_search(L_new, n) == False:
                return False
            else:
                return int((ind + 1) / 2) + binary_search(L_new, n)


# Tests:
check.set_screen(
    'Galloping search from index 0\nGalloping search from index/1\nGalloping search from index 3\nGalloping search from index 7\nBinary search from index 4 to 6'
)
check.expect('Q3T1', galloping_search(14, [1, 2, 5, 7, 9, 14, 15, 23, 29]), 5)
check.set_screen(
    'Galloping search from index 0\nGalloping search from index/1\nGalloping search from index 3'
)
check.expect('Q3T2', galloping_search(7, [1, 2, 5, 7, 9]), 3)
check.set_screen(
    'Galloping search from index 0\nGalloping search from index/1\nGalloping search from index 3\nBinary search from index 2 to 2'
)
check.expect('Q3T3', galloping_search(3, [1, 2, 5, 7, 9]), False)
check.set_screen(
    'Galloping search from index 0\nGalloping search from index/1\nGalloping search from index 3\nGalloping search from index 7\nGalloping search from index 9'
)
check.expect('Q3T4', galloping_search(100, [1, 2, 3, 4, 5, 6, 7, 8, 9, 100]),
             9)
            if index != len(L) and index * 2 > len(L):
                index = len(L)
            else:
                index = 2 * index

        else:
            print("Binary search from index " + str(index // 2) + " to " +
                  str(index - 2))
            return binary_search(L[index // 2:index - 2], n, index // 2)

    return False


# Test
check.set_screen(
    "Galloping search from index 0\nGalloping search from index 1\nBinary search from index 1 to 0"
)
check.expect("Test1", galloping_search(3, [1, 4, 7, 9, 12]), False)

check.set_screen("Galloping search from index 0")
check.expect("Test2", galloping_search(4, [4, 5, 6, 82, 88]), 0)

check.set_screen(
    "Galloping search from index 0\nGalloping search from index 1")
check.expect("Test3", galloping_search(13, [12, 13, 44, 67, 98, 123, 456]), 1)

check.set_screen(
    "Galloping search from index 0\nGalloping search from index 1\nGalloping search from index 3\nGalloping search from index 5"
)
check.expect("Test4", galloping_search(45, [1, 2, 5, 23, 24, 45]), 5)
Пример #29
0
# pass_to_c5(c4): None -> None
# Example: The value input should be a natural number that is 3 units less than/
# the number from last step
def pass_to_c5(c4):
    global c5
    c5 = input(step5_msg)
    if int(c5) == int(c4) - 3:
        print(final_msg.format(c5))
    else:
        print(error_msg)
        pass_to_c5(c4)


# Tests:
check.set_screen(
    'From step1_msg to step5_msg, and "Your orginal number is / 10" are printed'
)
check.set_input(["40", "49", "39", "13", "10"])
check.expect("Q3T1", number_game(), None)

check.set_screen(
    'From step1_msg to step5_msg with and error between step1/ and 2, and "Your orginal number is 10" are printed'
)
check.set_input(["40", "43" "49", "39", "13", "10"])
check.expect("Q3T2", number_game(), None)

check.set_screen(
    'From step1_msg to step5_msg with and error between step2/ and 3, and "Your orginal number is 10" are printed'
)
check.set_input(["40", "49", "34" "39", "13", "10"])
check.expect("Q3T3", number_game(), None)