Exemplo n.º 1
0
    def setUp(self):
        self.name = "Problem_Set"
        self.pset = ProblemSet(self.name)
        self.pset.test_fill_quotes()
        self.pset.test_fill_math(10)
        self.pset.test_fill(10)

        self.problemA = Problem("Question A", "Answer A")
        self.problemB = Problem("Question B", "Answer B")
        self.problemC = Problem("Question C", "Answer C")
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
def create_problem_set():
    if get_user_continue("Would you like to create a problem set?") == False:
        return
    #else
    saved = False
    ps = ProblemSet(get_user_input("name"))
    while True:
        print("1.) Add Problems")
        print("2.) View Problem Set")
        print("3.) Save Problem Set")
        print("99.) Exit")
        u_choice = input("Enter your choice: ")
        if u_choice == "1":
            while get_user_continue("Would you like to add a problem?"):
                ps.add_problem(create_problem())
            saved = False
        elif u_choice == "2":
            print(ps.as_string())
        elif u_choice == "3":
            ps.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
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 def test_as_string(self):
     ps = ProblemSet("ProblemSet")
     ps.add_problem(self.problemA)
     ps.add_problem(self.problemB)
     ps.add_problem(self.problemC)
     comp_str = "ProblemSet" + "\n" + self.problemA.as_string() + "\n"
     comp_str += self.problemB.as_string() + "\n" + self.problemC.as_string(
     ) + "\n"
     self.assertEqual(ps.as_string(), comp_str)
Exemplo n.º 6
0
class ProblemSetTest(unittest.TestCase):
    def setUp(self):
        self.name = "Problem_Set"
        self.pset = ProblemSet(self.name)
        self.pset.test_fill_quotes()
        self.pset.test_fill_math(10)
        self.pset.test_fill(10)

        self.problemA = Problem("Question A", "Answer A")
        self.problemB = Problem("Question B", "Answer B")
        self.problemC = Problem("Question C", "Answer C")

    def test_get_name(self):
        self.assertEqual(self.name, self.pset.get_name())

    def test_set_name(self):
        self.pset.set_name("My Problem Set")
        self.assertEqual("My Problem Set", self.pset.get_name())

    def test_add_problem(self):
        self.pset.add_problem(self.problemA)
        self.assertEqual(self.pset.get_problem(self.pset.get_length() - 1),
                         self.problemA)

    def test_find_problem(self):
        self.assertEqual(self.pset.find_problem(self.problemA), -1)
        self.pset.add_problem(self.problemA)
        self.pset.add_problem(self.problemB)
        self.pset.add_problem(self.problemC)
        ind_probA = self.pset.find_problem(self.problemA)
        ind_probB = self.pset.find_problem(self.problemB)
        ind_probC = self.pset.find_problem(self.problemC)
        self.assertEqual(self.pset.get_problem(ind_probA), self.problemA)
        self.assertEqual(self.pset.get_problem(ind_probB), self.problemB)
        self.assertEqual(self.pset.get_problem(ind_probC), self.problemC)

    def test_remove_problem(self):
        self.assertEqual(self.pset.remove_problem(self.problemA), -1)

        p = self.pset.get_problem(0)
        self.assertEqual(self.pset.remove_problem(p), 0)
        self.assertEqual(self.pset.find_problem(p), -1)

    def test_replace_problem(self):
        p = self.pset.get_problem(0)
        self.pset.replace_problem(0, self.problemA)
        self.assertEqual(self.pset.find_problem(p), -1)
        self.assertEqual(self.pset.find_problem(self.problemA), 0)

    def test_insert_problem(self):
        p = self.pset.get_problem(5)
        self.pset.insert_problem(5, self.problemA)
        self.assertEqual(self.pset.get_problem(5), self.problemA)
        self.assertEqual(self.pset.get_problem(6), p)

    def test_swap_problem(self):
        self.assertEqual(self.pset.swap_problem(-1, 1), -1)
        self.assertEqual(self.pset.swap_problem(0, 0), -1)
        self.assertEqual(self.pset.swap_problem(1, -1), -1)

        p0 = self.pset.get_problem(0)  #problem in position zero orginally
        p1 = self.pset.get_problem(1)  #problem in position one  orginally
        self.assertEqual(self.pset.swap_problem(0, 1), 0)
        self.assertEqual(self.pset.get_problem(0), p1)  #p1 should be in pos 0
        self.assertEqual(self.pset.get_problem(1), p0)  #p0 should be in pos 1

    def test_move_problem(self):
        #dst > org
        ind_org = 0
        ind_dst = 10
        prob_org = self.pset.get_problem(ind_org)
        prob_dst = self.pset.get_problem(ind_dst)
        self.assertEqual(self.pset.move_problem(ind_org, ind_dst), 0)
        self.assertEqual(self.pset.get_problem(ind_dst), prob_org)
        self.assertEqual(self.pset.get_problem(ind_dst - 1), prob_dst)

        #dst < org
        ind_org = 12
        ind_dst = 1
        prob_org = self.pset.get_problem(ind_org)
        prob_dst = self.pset.get_problem(ind_dst)
        self.assertEqual(self.pset.move_problem(ind_org, ind_dst), 0)
        self.assertEqual(self.pset.get_problem(ind_dst), prob_org)
        self.assertEqual(self.pset.get_problem(ind_dst + 1), prob_dst)

    def test_pop_problem(self):
        pset_length = self.pset.get_length()
        last_problem = self.pset.get_problem(pset_length - 1)
        self.pset.pop_problem()
        self.assertEqual(self.pset.find_problem(last_problem), -1)
        self.assertEqual(self.pset.get_length(), pset_length - 1)

    def test_copy(self):
        pset_copy = self.pset.copy()
        self.assertFalse(pset_copy == self.pset)
        self.assertEqual(pset_copy.as_string(), self.pset.as_string())

    def test_consolidate(self):
        p1 = ProblemSet("", self.problemA, self.problemB)
        p2 = ProblemSet("", self.problemB, self.problemC)
        p3 = ProblemSet("", self.problemC, self.problemA)
        test_string = p1.as_string().rstrip() + p2.as_string().rstrip(
        ) + p3.as_string()
        p1.consolidate(p2, p3)
        self.assertEqual(p1.as_string(), test_string)

    def test_check_index(self):
        test = ProblemSet("", self.problemA, self.problemB, self.problemC)
        self.assertFalse(test.check_index(-1))
        self.assertFalse(test.check_index(test.get_length()))
        self.assertTrue(test.check_index(0))
        self.assertTrue(test.check_index(test.get_length() - 1))

    def test_as_string(self):
        ps = ProblemSet("ProblemSet")
        ps.add_problem(self.problemA)
        ps.add_problem(self.problemB)
        ps.add_problem(self.problemC)
        comp_str = "ProblemSet" + "\n" + self.problemA.as_string() + "\n"
        comp_str += self.problemB.as_string() + "\n" + self.problemC.as_string(
        ) + "\n"
        self.assertEqual(ps.as_string(), comp_str)

    def test_save_load(self):
        self.pset.save("deleteme")
        load_set = ProblemSet()
        load_set.load("deleteme")
        self.assertEqual(self.pset.as_string(), load_set.as_string())

    def test_txt(self):
        self.pset.as_text_file("tester")
Exemplo n.º 7
0
 def test_save_load(self):
     self.pset.save("deleteme")
     load_set = ProblemSet()
     load_set.load("deleteme")
     self.assertEqual(self.pset.as_string(), load_set.as_string())
Exemplo n.º 8
0
 def test_check_index(self):
     test = ProblemSet("", self.problemA, self.problemB, self.problemC)
     self.assertFalse(test.check_index(-1))
     self.assertFalse(test.check_index(test.get_length()))
     self.assertTrue(test.check_index(0))
     self.assertTrue(test.check_index(test.get_length() - 1))
Exemplo n.º 9
0
 def test_consolidate(self):
     p1 = ProblemSet("", self.problemA, self.problemB)
     p2 = ProblemSet("", self.problemB, self.problemC)
     p3 = ProblemSet("", self.problemC, self.problemA)
     test_string = p1.as_string().rstrip() + p2.as_string().rstrip(
     ) + p3.as_string()
     p1.consolidate(p2, p3)
     self.assertEqual(p1.as_string(), test_string)
Exemplo n.º 10
0
def view_problem_set():
    filename = get_user_input("Filename where Problem Set is stored: ")
    ps = ProblemSet()
    ps.load(filename)
    print(ps.as_string())
Exemplo n.º 11
0
def modify_problem_set():
    filename = get_user_input("Filename where Problem Set is stored: ")
    ps = ProblemSet()
    ps.load(filename)
    saved = True

    while True:
        print(" 1.) View Problem Set")
        print(" 2.) Delete Problem")
        print(" 3.) Move Problem")
        print(" 4.) Add New Problem")
        print(" 5.) Insert New Problem")
        print(" 6.) Save Problem Set")
        #print(" 6.) Consolidate with Existing Problem Set")
        print("98.) Help")
        print("99.) Exit")
        choice = input("Enter your choice: ")
        if choice == '1':
            print(ps.as_string())

        elif choice == '2':
            while get_user_continue("Would you like to remove a problem?"):
                ps.remove_index(int(get_user_input("Problem Number: ")))
            saved = False

        elif choice == '3':
            while get_user_continue("Would you like to remove a problem?"):
                org = int(get_user_input("Origin Index: "))
                dst = int(get_user_input("Destination Index: "))
                ps.move_problem(org, dst)
            saved = False

        elif choice == '4':
            while get_user_continue("Would you like to add a problem?"):
                ps.add_problem(create_problem())
            saved = False

        elif choice == '5':
            while get_user_continue("Would you like to insert a problem?"):
                prob = create_problem()
                ind = int(
                    get_user_input("Where would like to insert this problem?"))
                ps.insert_problem(ind, prob)
            saved = False

        elif choice == "6":
            ps.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")