def test_check_happy(): test = Animal() test.happiness = 50 test.check_happy() assert (test.how_happy == '\033[1;32msuper HAPPY') test.happiness = 49 test.check_happy() assert (test.how_happy == '\033[0;36mHAPPY') test.happiness = 11 test.check_happy() assert (test.how_happy == '\033[0;36mHAPPY') test.happiness = 10 test.check_happy() assert (test.how_happy == '\033[0;31mUNHAPPY') test.happiness = 9 test.check_happy() assert (test.how_happy == '\033[0;31mUNHAPPY')
def test_check_healthy(): test = Animal() test.health = 25 test.check_health() assert (test.how_healthy == '\033[1;32mexcellent HEALTH') test.health = 24 test.check_health() assert (test.how_healthy == '\033[0;36mfair HEALTH') test.health = 11 test.check_health() assert (test.how_healthy == '\033[0;36mfair HEALTH') test.health = 10 test.check_health() assert (test.how_healthy == '\033[0;31mpoor HEALTH') test.health = 9 test.check_health() assert (test.how_healthy == '\033[0;31mpoor HEALTH')
import datetime from virtual_pet.virtual_pet import Animal test = Animal() test.type = 'save' test.name = 'George' test.health = 10 test.how_healthy = '\033[1;32mexcellent HEALTH' test.happiness = 20 test.how_happy = '\033[1;32msuper HAPPY' test.hunger = 5 test.how_hungry = '\033[1;32mreally HUNGRY' test.age = datetime.datetime.now() # don't need milliseconds in file name datestamp. filename = 'vp_{}_{}.vps'.format( test.name, str(datetime.datetime.now()).replace(' ', '_')[:-7]) filename = filename.replace('/', '').replace(':', '') # print filename # with open(filename, 'a') as save_file: # save_file.write('{}|{}|{}|{}|{}\n'.format(test.name, test.health, test.happiness, test.hunger, test.age)) # loads a file and sets the stats, then runs the checks path_list = '/Users/darwright/Python/PM_2015_SUMMER/StudentWork/DarWright/' load_filename = path_list + 'vp_George_2015-06-26_111415.vps' # print load_filename with open(load_filename) as load_pet_file: for line in load_pet_file: test.name, test.health, test.happiness, test.hunger, test.age = line.split(
def test_time_passed_10_seconds(): test = Animal() time.sleep(10) test.time_passed() assert (test.health == 4) assert (test.hunger == 1)
def test_check_happy(): test = Animal() test.happiness = 50 test.check_happy() assert test.how_happy == "\033[1;32msuper HAPPY" test.happiness = 49 test.check_happy() assert test.how_happy == "\033[0;36mHAPPY" test.happiness = 11 test.check_happy() assert test.how_happy == "\033[0;36mHAPPY" test.happiness = 10 test.check_happy() assert test.how_happy == "\033[0;31mUNHAPPY" test.happiness = 9 test.check_happy() assert test.how_happy == "\033[0;31mUNHAPPY"
import datetime from virtual_pet.virtual_pet import Animal test = Animal() test.type = 'save' test.name = 'George' test.health = 10 test.how_healthy = '\033[1;32mexcellent HEALTH' test.happiness = 20 test.how_happy = '\033[1;32msuper HAPPY' test.hunger = 5 test.how_hungry = '\033[1;32mreally HUNGRY' test.age = datetime.datetime.now() # don't need milliseconds in file name datestamp. filename = 'vp_{}_{}.vps'.format(test.name, str(datetime.datetime.now()).replace(' ', '_')[:-7]) filename = filename.replace('/', '').replace(':', '') # print filename # with open(filename, 'a') as save_file: # save_file.write('{}|{}|{}|{}|{}\n'.format(test.name, test.health, test.happiness, test.hunger, test.age)) # loads a file and sets the stats, then runs the checks path_list = '/Users/darwright/Python/PM_2015_SUMMER/StudentWork/DarWright/' load_filename = path_list + 'vp_George_2015-06-26_111415.vps' # print load_filename with open(load_filename) as load_pet_file: for line in load_pet_file: test.name, test.health, test.happiness, test.hunger, test.age = line.split('|') # print test.name, test.health, test.happiness, test.hunger, test.age test.show_checks()
def test_bath(): # base stats 5 health, 15 happiness, 0 hunger test = Animal() test.bath() # hunger + 1 assert test.health == 4 # time passes -2 health assert test.happiness == 15 assert test.hunger == 2 # time passes + 2 to hunger
def test_feed(): # base stats 5 health, 15 happiness, 0 hunger test = Animal() test.feed() # health + 5, happy + 5, hunger -2 assert (test.health == 10) assert (test.happiness == 20) assert (test.hunger == -2)
def test_feed(): # base stats 5 health, 15 happiness, 0 hunger test = Animal() test.feed() # health + 5, happy + 5, hunger -2 assert test.health == 10 assert test.happiness == 20 assert test.hunger == -2
def test_walk(): # base stats 5 health, 15 happiness, 0 hunger test = Animal() test.walk() # happy + 5, hungry + 2 assert test.health == 4 # time passes - 1 health assert test.happiness == 20 assert test.hunger == 3 # time passes + 1 to hunger
def test_set_name(): test = Animal() test.set_name("Garfield") assert test.name == "Garfield"
def test_check_hunger(): test = Animal() test.hunger = 10 test.check_hunger() assert test.how_hungry == "\033[1;32mreally HUNGRY" test.hunger = 9 test.check_hunger() assert test.how_hungry == "\033[0;36mHUNGRY" test.hunger = 3 test.check_hunger() assert test.how_hungry == "\033[0;36mHUNGRY" test.hunger = 0 test.check_hunger() assert test.how_hungry == "\033[0;31mnot HUNGRY" test.hunger = -1 test.check_hunger() assert test.how_hungry == "\033[0;31mnot HUNGRY"
def test_check_healthy(): test = Animal() test.health = 25 test.check_health() assert test.how_healthy == "\033[1;32mexcellent HEALTH" test.health = 24 test.check_health() assert test.how_healthy == "\033[0;36mfair HEALTH" test.health = 11 test.check_health() assert test.how_healthy == "\033[0;36mfair HEALTH" test.health = 10 test.check_health() assert test.how_healthy == "\033[0;31mpoor HEALTH" test.health = 9 test.check_health() assert test.how_healthy == "\033[0;31mpoor HEALTH"
def test_check_hunger(): test = Animal() test.hunger = 10 test.check_hunger() assert (test.how_hungry == '\033[1;32mreally HUNGRY') test.hunger = 9 test.check_hunger() assert (test.how_hungry == '\033[0;36mHUNGRY') test.hunger = 3 test.check_hunger() assert (test.how_hungry == '\033[0;36mHUNGRY') test.hunger = 0 test.check_hunger() assert (test.how_hungry == '\033[0;31mnot HUNGRY') test.hunger = -1 test.check_hunger() assert (test.how_hungry == '\033[0;31mnot HUNGRY')
def test_pet_the_pet(): test = Animal() test.pet_the_pet() # happiness + 10 assert test.health == 5 assert test.happiness == 25 assert test.hunger == 0
def test_set_name(): test = Animal() test.set_name('Garfield') assert (test.name == 'Garfield')
def test_time_passed_20_seconds(): test = Animal() time.sleep(20) test.time_passed() assert test.health == 3 assert test.hunger == 2
def test_walk(): # base stats 5 health, 15 happiness, 0 hunger test = Animal() test.walk() # happy + 5, hungry + 2 assert (test.health == 4) # time passes - 1 health assert (test.happiness == 20) assert (test.hunger == 3) # time passes + 1 to hunger
def test_time_passed_10_seconds(): test = Animal() time.sleep(10) test.time_passed() assert test.health == 4 assert test.hunger == 1