def create_exam(): if get_user_continue("Would you like to create an exam?") == False: return #else saved = False exam = Exam(get_user_input("name")) while True: print("1.) Add Problems") print("2.) View Exam") print("3.) Save Exam") print("99.) Exit") u_choice = input("Enter your choice: ") if u_choice == "1": while get_user_continue("Would you like to add a problem?"): problem = create_problem() points = int(get_user_input("Point Value")) exam.add_problem(problem, points) saved = False elif u_choice == "2": print(exam.as_string()) elif u_choice == "3": exam.save(get_user_input("filename")) saved = True elif u_choice == "99": if not (saved) and get_user_continue( "Would you like to save your changes?"): continue else: return
def setUp(self): self.name = "Exam" self.exam = Exam(self.name) self.exam.test_fill_quotes() #self.exam.save("setup") self.problemA = Problem("Question A", "Answer A") self.problemB = Problem("Question B", "Answer B") self.problemC = Problem("Question C", "Answer C")
def test_consolidate(self): test = Exam() #test is easy if we eliminate the name otherwise we have to do a lot of str manip self.exam.set_name("") test.consolidate(self.exam, self.exam, self.exam) test_string = '\n' + ' '.join( [str(i) for i in (self.exam.get_points() * 3)]) test_string += super(Exam, self.exam).as_string().rstrip() * 3 + '\n' self.assertEqual(test.as_string(), test_string)
def test_as_string(self): ex = Exam("Exam", [1, 1, 1], ProblemSet("", self.problemA, self.problemB, self.problemC)) points = ' '.join([str(i) for i in ex.get_points()]) comp_str = "Exam" + "\n" + points + '\n' + self.problemA.as_string( ) + "\n" comp_str += self.problemB.as_string() + "\n" + self.problemC.as_string( ) + "\n" self.assertEqual(ex.as_string(), comp_str)
def main(): if len(sys.argv) == 3: option = sys.argv[1] filename = sys.argv[2] if option == "-e" and os.path.isfile(filename): exam = Exam() exam.load(filename) administer_exam(exam) elif option == "-p" and os.path.isfile(filename): ps = ProblemSet() ps.load(filename) administer_problem_set(ps) else: print_help() else: print_help()
def test_save_load(self): self.exam.save("deleteme") load_set = Exam() load_set.load("deleteme") self.assertEqual(self.exam.as_string(), load_set.as_string())
def view_exam(): filename = get_user_input("Filename where Problem Set is stored: ") ex = Exam() ex.load(filename) print(ex.as_string())
def modify_exam(): filename = get_user_input("Filename where Exam is stored: ") ex = Exam() ex.load(filename) saved = True while True: print(" 1.) View Exam") print(" 2.) Delete Problem") print(" 3.) Move Problem") print(" 4.) Add New Problem") print(" 5.) Insert New Problem") print(" 6.) Save Exam") #print(" 6.) Consolidate with Existing Problem Set") print("98.) Help") print("99.) Exit") choice = input("Enter your choice: ") if choice == '1': print(ex.as_string()) elif choice == '2': while get_user_continue("Would you like to remove a problem?"): ex.remove_index(int(get_user_input("Problem Number: "))) saved = False elif choice == '3': while get_user_continue("Would you like to move a problem?"): org = int(get_user_input("Origin Index: ")) dst = int(get_user_input("Destination Index: ")) ex.move_problem(org, dst) saved = False elif choice == '4': while get_user_continue("Would you like to add a problem?"): prob = create_problem() point = get_user_input("Point Value: ") ex.add_problem(prob, point) saved = False elif choice == '5': while get_user_continue("Would you like to insert a problem?"): prob = create_problem() point = get_user_input("Point Value: ") ind = int( get_user_input("where would like to insert this problem?")) ex.insert_problem(ind, prob, point) saved = False elif choice == "6": ex.save(get_user_input("filename")) saved = True #elif choice == '6': #print("I have no purpose") elif choice == '98': print("I can't help ya bucko.") elif choice == "99": if not (saved) and get_user_continue( "Would you like to save your changes?"): continue else: return else: print("Unrecognized Input")