def cp_run_and_diff (stdin_text, file_to_copy, file_correct, stdout_correct):
   os.chdir('..')
   subprocess.getoutput('rm %soutput.txt' % csid)
   os.system('cp %s %s/input.txt' % (file_to_copy, csid))
   os.chdir(csid)
   process = subprocess.Popen(['python3', fileToGrade], **pipes)
   stdout_output = str(process.communicate(bytes(stdin_text, 'UTF-8'))[0])[2:-1]
   print("%s %s" % ("Encrypting" if stdin_text == 'E' else "Decrypting", file_to_copy))
   try:
     differences = subprocess.getoutput('diff -w output.txt ../%s' % file_correct)
     if differences != '':
       print("Expected:")
       line = ""
       [print("\t|%s" % line.strip()) for line in open('../%s' % file_correct, 'r')]
       print("Actual:")
       line = ""
       [print("\t|%s" % line.strip()) for line in open('output.txt', 'r')]
     else:
       print("File outputs match")
   except:
     print("Program did not output to file.")
   subprocess.getoutput('rm output.txt')
   subprocess.getoutput('rm input.txt')
   stdout_output = '\n'.join([line if line.count(' ') != len(line) else '\n' for line in stdout_output.replace(r'\n', '\n').replace('decrpyt', 'decrypt').strip().split('\n')])
   print("STDOUT matches\n" if stdout_output == stdout_correct else "STDOUT does not match:\n%s\n" % stdout_output)
   return (differences == '', stdout_output == stdout_correct)
  def cp_run_and_diff (file_to_copy):
    nonlocal perfect_formatting
    os.chdir ('..')
    subprocess.getoutput('rm "%s/hidden.txt"' % csid)
    subprocess.getoutput('rm "%s/found.txt"' % csid)
    os.system('cp %s.txt "%s/hidden.txt"' % (file_to_copy, csid))
    os.chdir(csid)
    subprocess.getoutput('python3 %s' % fileToGrade)
    if file_to_copy != bonus_name:
      print ("Testing %s:" % file_to_copy)
    success = True
    try:
      with open ('found.txt', 'r') as actual, open ('../%s_found.txt' % file_to_copy, 'r') as expected:
        actual_lines = [x.strip() for x in list(actual) if len(x.strip()) != 0]
        actual_lines.sort()
        expected_lines = [x.strip() for x in list(expected) if len(x.strip()) != 0]
        expected_lines.sort()
        if (len(actual_lines) != len(expected_lines)):
          success = False
          if (file_to_copy == file_names[0]):
            perfect_formatting = False
        else:
          last_line = None
          for expected_line, actual_line in zip(expected_lines, actual_lines):
            if not success:
              break
            if file_to_copy == file_names[0] and last_line is not None:
              perfect_formatting = perfect_formatting and len(last_line) == len(actual_line)
            last_line = actual_line
            success = expected_line.split() == actual_line.split()
        if True or not success and file_to_copy != bonus_name:
          print ('  Expected:')
          for line in expected_lines:
            print ('    |%s' % line)
          print ('  Actual:')
          for line in actual_lines:
            print ('    |%s' % line)
          print()
        elif success:
          if file_to_copy == bonus_name:
            print ("Testing '%s':" % file_to_copy)
          print ('Program output matches exactly!\n')
    except:
      if file_to_copy != bonus_name:
        print ("Program did not output to file.\n")
      if (file_to_copy == file_names[0]):
        perfect_formatting = False
      return False

    subprocess.getoutput('rm hidden.txt')
    subprocess.getoutput('rm found.txt')
    return success
Exemplo n.º 3
0
def main(argv):
    directory = argv[1]
    for dirname, dirnames, filenames in os.walk(directory):
        os.chdir(dirname)
        for filename in filenames:
            if filename.endswith('.jar'):
                print filename
                jar = zipfile.ZipFile(filename, 'r')
                for info in jar.infolist():
                    if info.filename == 'META-INF/MANIFEST.MF':
                        data = jar.read(info.filename)
                        lines = data.splitlines()
                        for line in lines:
                            imp_version = line.find('Implementation-Version')
                            if imp_version != -1:
                                print line + '\n'
  def run_program_compare():
    os.chdir('..')
    os.system('cp %s %s/isbn.txt' % (input_file, csid))
    os.chdir(csid)
    command = 'python3 ' + fileToGrade
    os.system( command )
    wrongCases = testCases
    count = 1
    try:
      user_file = open(output_file, 'r')
      user_line = user_file.readline()
      std_file = open('../%s' % output_file, 'r')
      std_line = std_file.readline()
      
      while (std_line and user_line ):
        print ("test case", count)
        print ("Expected: ", std_line, end='')
        print ("Actual:   ", user_line)
        count += 1
        if std_line.lower().split() == user_line.lower().split():
          wrongCases -= 1
        elif std_line.lower().split()[1] in user_line.lower().split():
          wrongCases -= 0.5
        user_line = user_file.readline()
        std_line = std_file.readline()

      while(std_line):
          print ("test case", count)
          print ("Expected: ", std_line, end='')
          print ("Actual:   ")
          user_line = user_line.readline()
          count += 1
      while(user_line):
          wrongCases += 1
          print ("Expected: ", end='')
          print ("Actual:   ", user_line)
          user_line = user_line.readline()
    except:
      pass
    if wrongCases <= testCases: return wrongCases
    else: return testCases
def assign2( csid , writeToFile) :
  fileToGrade = ""
  late = 0
  linesWrong = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = " "
  manualComments = ""

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file")
        os.chdir("..")
        return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  if not fileToGrade == "" and late < 3:
    answers = []
    for creditCardNumber in inputArray:
      process = subprocess.Popen(['python3', fileToGrade], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
      out = process.communicate(bytes(creditCardNumber, 'UTF-8'))[0]
      answers.append(str(out)[2:-1])
     
    perfectCount = 0
    closeCount = 0 
    answerCount = 0
    wrongCount = 0
    for correctAnswer in correct.splitlines():
      if correctAnswer in answers[answerCount]:  #Does not contain the correct formatted answer
        print('Correct answer for #', answerCount+1)
        perfectCount += 1
      else:
        if correctAnswer.lower()[0:5] in answers[answerCount].lower() and not "in" + correctAnswer.lower()[0:5] in answers[answerCount].lower(): #We can change to to account for invalid or not
          print ("Correct answer for #", answerCount+1," but incorrect formatting")
          print ("\t", correctAnswer[0:1],"-",answers[answerCount])
          closeCount += 1
        else:
          print("Wrong answer")
          wrongCount += 1
      answerCount += 1
    print("Perfect:", str(perfectCount) + "/8")
    print("Close:", str(closeCount) + "/8")
    print("Wrong:", str(wrongCount) + "/8")
    if(0 >= closeCount >= 4):
    	grade = 70 - (4 * wrongCount) 
    	comments += " Output did not match instructors, "
    elif(closeCount >= 4):
    	grade = 60 - (4 * wrongCount)
    	comments += " Output did not match instructors, "

      #TODO take of 5 points if they're closeCount is 0 to 4 and take off 10 if closeCount is greater than 4
      #TODO take off 4 * wrongCount points as well
      #TODO fix the else below to output the correct comments
     
  else:
    #print('Their output:')
    #print(out)
    #print('Correct output:')
    #print(correct)
    #print('logo has ' + str(len(lines)) +' lines, not 19')
    #don't dock points for lateness or wrong filename here
    gradeInput = input("Grade out of 70 (no style, hit enter if 65): ")
    if gradeInput == '' :
      grade = 65
    else :
      grade = int(gradeInput)
    manualComments = input("Comments: ")

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header( (y or enter)  /  n)? ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Comments (Enter a number out of 30 to represent their grade, hit enter for 30): ")
  comments += input ("General Comments?:  ")
  if not style.isdigit() :
    style = 30
  else :
    style = int(style)
  
  #writing grade time!
  if late == 3 :
    if writeToFile: outputFile.write('0\t 3 days late')
  else :
    if late == 2 :
      comments = "2 days late, "
      grade -= 20
    elif late == 1 :
      comments = "1 day late, "
      grade -= 10
    
    if wrongFileName :
      comments += " wrong filename, "
      grade -= 10
    if not header :
      comments += " no/malformed header, "
      grade -= 10

    if linesWrong > 0 and linesWrong < 3 : 
      comments += "improperly formed superman logo, "
      grade -= 5
    elif linesWrong > 3 :
      comments += "nonsensical superman logo, "
      grade -= 5
    if writeToFile: outputFile.write(str(grade+style) + "\t"+comments.rstrip(', ') + manualComments)
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign12(csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  # run student's isbn.py and compare their output with standard output
  def run_program_compare():
    os.chdir('..')
    os.system('cp %s %s/isbn.txt' % (input_file, csid))
    os.chdir(csid)
    command = 'python3 ' + fileToGrade
    os.system( command )
    wrongCases = testCases
    count = 1
    try:
      user_file = open(output_file, 'r')
      user_line = user_file.readline()
      std_file = open('../%s' % output_file, 'r')
      std_line = std_file.readline()
      
      while (std_line and user_line ):
        print ("test case", count)
        print ("Expected: ", std_line, end='')
        print ("Actual:   ", user_line)
        count += 1
        if std_line.lower().split() == user_line.lower().split():
          wrongCases -= 1
        elif std_line.lower().split()[1] in user_line.lower().split():
          wrongCases -= 0.5
        user_line = user_file.readline()
        std_line = std_file.readline()

      while(std_line):
          print ("test case", count)
          print ("Expected: ", std_line, end='')
          print ("Actual:   ")
          user_line = user_line.readline()
          count += 1
      while(user_line):
          wrongCases += 1
          print ("Expected: ", end='')
          print ("Actual:   ", user_line)
          user_line = user_line.readline()
    except:
      pass
    if wrongCases <= testCases: return wrongCases
    else: return testCases

  if late != -1:
    wrongTests = run_program_compare()
    print ("correct: ", testCases - wrongTests)
    print ("wrong:   ", wrongTests)
    if wrongTests == 0:
      print("Excellent! passed all tests")
      comments.append("passed all tests")
    else:
      grade = grade - (30/testCases) * wrongTests
      c = str(wrongTests) + " are wrong"
      comments.append(c)

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header and comments? (y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3 - 7 days late (-30)")
      grade -= 30
    elif late == 2 :
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1 :
      comments.append("1 day late (-10)")
      grade -= 10
    
    if wrongFileName :
      comments.append("wrong filename (-10)")
      grade -= 10
    if not header :
      comments.append("missing comments or malformed header (-10)")
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign05(csid, writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  6 players - 10 pts each
  1 dealer - 10 pts
  '''

  inputText = [6]
  outputList = []
  formatted = False
  crashList = []

  if not (fileToGrade == '' and late != -1):
    for numPlayers in inputText:
      try:
        process = subprocess.Popen(['python3', fileToGrade], **pipes)
        out = process.communicate(bytes(str(numPlayers), 'UTF-8'))[0]
        


        outputGame = str(out)[2:-1].split('\\n')
        


        crashed = False

        for o in outputGame:
          if o.find('Traceback') > -1:
            crashed = True
            break
        crashList.append(crashed)

        if not crashed:
          # check output format of all 11 tests
          if (outputGame[0].find('Enter number of players: ') < 0) or (outputGame[0].find('Enter the number of players: ') < 0):
            formatted = True

        outputList.append(list(filter(None, outputGame)))
        
      except KeyboardInterrupt:
        print(' passed ^C')

  grade = 0

  # # run tests
  # for count in range(len(outputList)):
  #   output = outputList[count]
  #   numPlayers = inputText[count]
  #   hands = []
  #   if not crashList[count]:
  #     for test in output:
  #       hand = []
  #       for token in test.split():
  #         if isCard(token):
  #           hand.append(card(token))
  #       if len(hand) == 5:
  #         hands.append(hand)
  #     if len(hands) != numPlayers:
  #       comments.append('failed test ' + str(count + 1) + ' (-5) - Wrong Number of Hands')
  #       print('Failed Test ' + str(count + 1) + ':')
  #       print('\tWrong Number of Hands')
  #     else:
  #       values = []
  #       failed = False

  #       if not hasDuplicate:
  #         hasDuplicate, hand = checkDuplicate(hands)
  #         if hasDuplicate:
  #             hasDuplicateList.append(hand)

  #       for i in range(len(hands)):
  #         hand = hands[i]
  #         sortedHand1 = sorted(hand, reverse=True)
  #         h1, sortedHand2 = is10(sortedHand1)
  #         h2, sortedHand3 = isStraight(sortedHand1)

  #         if isSorted:
  #           isSorted = sameHand(hand, sortedHand1) or sameHand(hand, sortedHand2) or sameHand(hand, sortedHand3)
  #           if not isSorted:
  #             isSortedList.append(printHand(hand))

  #         if not failed:
  #           indType = numPlayers
  #           while (indType < len(output)) and (output[indType].find('1:') < 0):
  #             indType += 1

  #           j = indType + i
  #           line = output[j].rstrip() if j < len(output) else ''
  #           pos = line.find(str(i + 1))

  #           if pos >= 0:
  #             for p in range(pos, len(line)):
  #               if 'a' <= line[p].lower() <= 'z':
  #                 pos = p
  #                 break
  #             line = line[pos:].lower()

  #             v = -1
  #             if line in mapping:
  #               v = mapping[line]

  #             if (v == -1) or ((v != h1) and (v != h2)):
  #               comm = 'Hand = ' + printHand(hand) + '; Output = ' + line
  #               comments.append('failed test ' + str(count + 1) + ' (-5) ' + comm)
  #               print('Failed Test ' + str(count + 1) + ':')
  #               print('\tHand: ' + printHand(hand))
  #               print('\tType: ' + line)
  #               failed = True
  #               break

  #             if not failed:
  #               if v == h1:
  #                 values.append(computeScore(h1, sortedHand2))
  #               else:
  #                 values.append(computeScore(h2, sortedHand3))

  #           else:
  #             comments.append('failed test ' + str(count + 1) + ' (-5) - Unable to Find Type')
  #             print('Failed Test ' + str(count + 1) + ':')
  #             print('\tHand: ' + printHand(hand))
  #             print('\tType: ' + line)
  #             failed = True
  #             break

  #       if not failed:
  #         if len(values) != 0:
  #           maxScore = max(values)

  #           winners = [i + 1 for i in range(len(values)) if values[i] == maxScore][::-1]

  #           if len(winners) == 1:
  #             if output[-1].find(str(winners[0])) < 0:
  #               strList = map(lambda x: printHand(x), hands)
  #               comm = 'Hands = [' + ', '.join(strList) + ']; Winner = ' + str(winners[0]) + '; Output = ' + output[-1]
  #               comments.append('failed test ' + str(count + 1) + ' (-5) ' + comm)
  #               print('Failed Test ' + str(count + 1) + ':')
  #               print('\tCorrect: ' + str(winners[0]))
  #               print('\tOutput: ' + output[-1])
  #               failed = True

  #           else:
  #             pos = -1
  #             for w in winners:
  #               if output[pos].find(str(w)) < 0:
  #                 strList = map(lambda x: printHand(x), hands)
  #                 comm = 'Hands = [' + ', '.join(strList) + ']; Winner = ' + str(w) + '; Output = ' + output[pos]
  #                 comments.append('failed test ' + str(count + 1) + ' (-5) ' + comm)
  #                 print('Failed Test ' + str(count + 1) + ':')
  #                 print('\tCorrect: ' + str(w))
  #                 print('\tOutput: ' + output[pos])
  #                 failed = True
  #                 break

  #       if not failed:
  #         grade += 5

  # if formatted:
  #   grade += 5
  # else:
  #   comments.append('wrong output format (-5)')

  # if isSorted:
  #   grade += 5
  # else:
  #   comm = '[' + ', '.join(isSortedList) + ']'
  #   comments.append('spotted incorrectly sorted hand (-5) ' + comm)

  # if not hasDuplicate:
  #   grade += 5
  # else:
  #   comm = 'Hands = [' + ', '.join(hasDuplicateList) + ']'
  #   comments.append('spotted duplicate cards (-5) ' + comm)

  # if grade == 70:
  #   print('Perfection =D')
  # else:
  #   print('Grade: ' + str(grade)+'/70')


  #checking for header and style
  input("Hit Enter to cat first 20 lines (header)")
  print(subprocess.getoutput('head -20 ' + fileToGrade))
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else :
    header = False
  input("Hit Enter to cat whole file (style/comments)")
  print(subprocess.getoutput('cat ' + fileToGrade))
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3-7 days late (-30)")
      grade -= 30
    elif late == 2:
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1:
      comments.append("1 day late (-10)")
      grade -= 10

    if wrongFileName or not header:
      grade -= 5
      if wrongFileName and header:
        comments.append("wrong filename (-5)")
      elif header and not wrongFileName:
        comments.append("malformed header (-5)")
      else:
        comments.append("wrong filename and malformed header (-5)")

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign1( csid ) :
  fileToGrade = ""
  late = 0
  linesWrong = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = ""
  manualComments = ""

  os.chdir(csid)
  outputFile.write(csid + "\t")
  files = os.listdir('.')

  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      outputFile.write("0\tno file")
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  if not fileToGrade == "" and late < 3:
    out = subprocess.getoutput('python3 ' + fileToGrade)
    lines = out.split('\n')
    if len(lines) == 19 :
      if re.match('\s*', lines[0]) is None :
        linesWrong += 1
      if re.match('         \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\s*', lines[1]) is None :
        linesWrong += 1
      if re.match('        \*\*\*\$\$\$\$\$\$\$\$\$\$\$\$\$\$\*\*\s*', lines[2]) is None :
        linesWrong += 1
      if re.match('       \*\* \$\$         \$\$ \$ \*\*\s*', lines[3]) is None :
        linesWrong += 1
      if re.match('      \*\* \$\$           \$\$\$  \*\*\s*', lines[4]) is None :
        linesWrong += 1
      if re.match('     \*\* \$\$\$                 \*\*\s*', lines[5]) is None :
        linesWrong += 1
      if re.match('      \*\$\$\$\$\$\$\$\$\$           \*\*\s*', lines[6]) is None :
        linesWrong += 1
      if re.match('       \*\$\$\$\$\$\$\$\$\$\$\$\$\$\$    \*\*\s*', lines[7]) is None :
        linesWrong += 1
      if re.match('        \*\*\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\*\*\s*', lines[8]) is None :
        linesWrong += 1
      if re.match('         \*\*      \$\$\$\$\$\$\$\*\*\s*', lines[9]) is None :
        linesWrong += 1
      if re.match('          \*\*         \$\$\*\*\s*', lines[10]) is None :
        linesWrong += 1
      if re.match('           \*\*\$\$\$    \$\$\*\*\s*', lines[11]) is None :
        linesWrong += 1
      if re.match('            \*\$\$\$\$\$\$\$\$\*\*\s*', lines[12]) is None :
        linesWrong += 1
      if re.match('             \*\*     \*\*\s*', lines[13]) is None :
        linesWrong += 1
      if re.match('              \*\*   \*\*\s*', lines[14]) is None :
        linesWrong += 1
      if re.match('               \*\* \*\*\s*', lines[15]) is None :
        linesWrong += 1
      if re.match('                \*\*\*\s*', lines[16]) is None :
        linesWrong += 1
      if re.match('                 \*\s*', lines[17]) is None :
        linesWrong += 1
      if re.match('\s*', lines[18]) is None :
        linesWrong += 1
    else :
      print('Their output:')
      print(out)
      print('Correct output:')
      print(correct)
      print('logo has ' + str(len(lines)) +' lines, not 19')
      #don't dock points for lateness or wrong filename here
      gradeInput = input("Grade out of 70 (no style, hit enter if 65): ")
      if gradeInput == '' :
        grade = 65
      else :
        grade = int(gradeInput)
      manualComments = input("Comments: ")

    #checking for header and style
    #os.system('vim ' + fileToGrade)
    print(subprocess.getoutput('cat ' + fileToGrade))
    headerInput = input("Header(y or enter/n)? ")
    if headerInput == 'y' or headerInput == '' :
      header = True
    else :
      header = False
    style = input("Style/Comments (out of 30, hit enter for 30): ")
    if not style.isdigit() :
      style = 30
    else :
      style = int(style)
    
    #writing grade time!
    if late == 3 :
      outputFile.write('0\t 3 days late')
    else :
      if late == 2 :
        comments = "2 days late, "
        grade -= 20
      elif late == 1 :
        comments = "1 day late, "
        grade -= 10
      
      if wrongFileName :
        comments += "wrong filename, "
        grade -= 10
      if not header :
        comments += "no/malformed header, "
        grade -= 10

      if linesWrong > 0 and linesWrong < 3 : 
        comments += "improperly formed superman logo, "
        grade -= 5
      elif linesWrong > 3 :
        comments += "nonsensical superman logo, "
        grade -= 5
      outputFile.write(str(grade+style) + "\t"+comments.rstrip(', ') + manualComments)
      
  outputFile.write('\n')
  os.chdir("..")
def assign11(csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  tests 1-6 are 3 points
  7 and 8 are for multiple subsequences and are 4 points
  test 9 is to make sure they don't output singleton matches and is 3 points
  '''
  if late != -1:
    answers = []
    count = 0
    for strand1,strand2 in zip(inputLines[0::2],inputLines[1::2]):
      count += 1
      try:
        process = subprocess.Popen(['python3', fileToGrade], **pipes)
        out = process.communicate(bytes(strand1+'\n'+strand2+'\n', 'UTF-8'))[0]
        answers.append(str(out)[2:-1].replace('\\n','\n').strip())
      except KeyboardInterrupt:
        print(" on test" +str(count))

    correct_formatting = True
    extra_credit = True
    num_3_points_tests_failed = 0
    num_4_points_tests_failed = 0

    # gradin' normal tests 
    correct = ""
    count = 0
    for normal_out,extra_credit_out,out in zip(correctLines[0::2],correctLines[1::2],answers[:10]):
      printed = False
      correct_formatting = True
      count += 1
      normal_out = normal_out.replace('\\n','\n')
      print("\n=====Test "+str(count)+"=====")
      extra_credit_out = extra_credit_out.replace('\\n','\n')
      # there was some ambiguity on if the no sequence found text had a period or not
      out = out.replace('.','')
      if extra_credit and out != extra_credit_out:
        extra_credit = False
      if not extra_credit and correct_formatting and out != normal_out :
        print("\tIncorrect Formatting -5")
        print("\t=====Correct=====\n"+normal_out+"\n\t=====Output=====\n"+out)
        if input("Hit enter to accept deduction, or type n: ") == "":
          printed = True
          correct_formatting = False

      #check correctness
      #if there's a perfect match no need to fuzzy match
      if not correct_formatting:
        failed = False
        splitted = set(out.split(':')[-1].split('\n')[1:])
        correct_splitted = normal_out.split('\n')
        if count <= 6:
          if splitted != set(correct_splitted[-1:]):
            num_3_points_tests_failed += 1
            failed = True
            points = "3"
        elif count == 7:
          if splitted != set(correct_splitted[-2:]):
            num_4_points_tests_failed += 1
            failed = True
            points = "4"
        elif count == 8:
          if splitted != set(correct_splitted[-3:]):
            num_4_points_tests_failed += 1
            failed = True
            points = "4"
        elif count == 9:
          if splitted != set(correct_splitted[-1:]):
            num_3_points_tests_failed += 1
            failed = True
            points = "3"
        if failed:
          if not printed:
            print("\t=====Correct=====\n"+normal_out+"\n\t=====Output=====\n"+out)
          print("\tFailed Test -"+points)
        else:
          print("\tPassed")
      else:
        print("\tPassed")

    #calculating grade time
    total_off = 0
    total_off -= num_3_points_tests_failed * 3
    total_off -= num_4_points_tests_failed * 4
    print()
    feedback = "3 point tests passed: "+str(7-num_3_points_tests_failed)+"/7 so " + str(num_3_points_tests_failed*-3)
    comments.append(feedback)
    print(feedback)
    feedback = "4 point tests passed: "+str(2-num_4_points_tests_failed)+"/2 so " + str(num_4_points_tests_failed*-4)
    comments.append(feedback)
    print(feedback)

    if not correct_formatting:
      total_off -= 5
      feedback = "Incorrect formatting: -5"
      comments.append(feedback)
      print(feedback)
    if extra_credit:
      total_off +=3
      feedback = "Extra credit formatting: +3"
      comments.append(feedback)
      print(feedback)
    grade += total_off
    print("Grade: "+str(grade)+"/70")
  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header and comments? (y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3 - 7 days late (-30)")
      grade -= 30
    elif late == 2 :
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1 :
      comments.append("1 day late (-10)")
      grade -= 10
    
    if wrongFileName :
      comments.append("wrong filename (-10)")
      grade -= 10
    if not header :
      comments.append("missing comments or malformed header (-10)")
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign15(csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  20 points for correctness
  -5 if there's not 1 number past the decimal point
  '''
  if late != -1:
    #copy over input file
    os.system('cp ../Census_2009.txt .')
    try:
      process = subprocess.Popen(['python3', fileToGrade], **pipes)
      out = process.communicate(bytes('', 'UTF-8'))[0]
      answerList = str(out)[2:-1].replace('\\t',' ').strip().split('\\n')
    except KeyboardInterrupt:
      print(" on test" +str(count))

    correct_formatting = True
    correct_output = True

    f = open('../correct.txt', 'r')
    correctList = f.read()
    f.close()

    correct = []
    for x in correctList.split('\n'):
      correct.append(x.split(' '))
    answer = []
    for x in answerList:
      if x.strip(): #empty string is false
        answer.append(x.split())

    #check correctness
    if len(correct) == len(answer):
      count = 0
      for right,theirs in zip(correct,answer):
        count+=1
        if count == 1:
          continue
        for rightElem, theirsElem in zip(right,theirs):
          if rightElem != theirsElem and (rightElem not in theirsElem and theirsElem not in rightElem):
            try:
              rightFloat = eval(rightElem)
              theirsFloat = eval(theirsElem)
            except Exception:
              rightFloat = ""
              theirsFloat = ""
            #SOOOOO MUCH COPY PASTA!!!! DON'T EVEN CAR IT WORKS!!!
            #YES CAR!!!!
            if type(rightFloat) == type(0.0) and type(theirsFloat) == type(0.0):
              if rightFloat == round(theirsFloat,1):
                correct_formatting = False
                print('Mismatch!')
                print('===Correct===')
                print(rightElem)
                print('===Theirs===')
                print(theirsElem)
              else:                
                print('Mismatch!')
                print('===Correct===')
                print(rightElem)
                print('===Theirs===')
                print(theirsElem)
                correct_output = False
            else:                
              print('Mismatch!')
              print('===Correct===')
              print(rightElem)
              print('===Theirs===')
              print(theirsElem)
              correct_output = False
    else:
      correct_output = False
      print("Lengths didn't match up?!?")
      print('===Correct===')
      for x in correct:
        print(x)
      print('===Theirs===')
      for x in answer:
        print(x)

    if not correct_output:
      print('===Correct===')
      for x in correct:
        print(x)
      print('===Theirs===')
      for x in answer:
        print(x)


    #calculating grade time
    total_off = 0
    if not correct_output:
      total_off -=20
      #Yup, kc.
      feedbakc = "Failed: -20 =("
      comments.append(feedbakc)
      print(feedbakc)
    if not correct_formatting:
      total_off -= 5
      feedback = "Incorrect formatting: -5"
      comments.append(feedback)
      print(feedback)
    grade += total_off
    if total_off == 0:
      print("<('.')^ Perfect ^('.')>")
    print("Grade: "+str(grade)+"/70")

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header and comments? (y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3 - 7 days late (-30)")
      grade -= 30
    elif late == 2 :
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1 :
      comments.append("1 day late (-10)")
      grade -= 10
    
    if wrongFileName :
      comments.append("wrong filename (-10)")
      grade -= 10
    if not header :
      comments.append("missing comments or malformed header (-10)")
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign10(csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True


  # copies ../FILE_TO_COPY to ./ and runs the program in ./
  # diffs output.txt with FILE_CORRECT
  # returns tuple (file output matches, stdout output matches)
  def cp_run_and_diff (stdin_text, file_to_copy, file_correct, stdout_correct):
    os.chdir('..')
    subprocess.getoutput('rm %soutput.txt' % csid)
    os.system('cp %s %s/input.txt' % (file_to_copy, csid))
    os.chdir(csid)
    process = subprocess.Popen(['python3', fileToGrade], **pipes)
    stdout_output = str(process.communicate(bytes(stdin_text, 'UTF-8'))[0])[2:-1]
    print("%s %s" % ("Encrypting" if stdin_text == 'E' else "Decrypting", file_to_copy))
    try:
      differences = subprocess.getoutput('diff -w output.txt ../%s' % file_correct)
      if differences != '':
        print("Expected:")
        line = ""
        [print("\t|%s" % line.strip()) for line in open('../%s' % file_correct, 'r')]
        print("Actual:")
        line = ""
        [print("\t|%s" % line.strip()) for line in open('output.txt', 'r')]
      else:
        print("File outputs match")
    except:
      print("Program did not output to file.")
    subprocess.getoutput('rm output.txt')
    subprocess.getoutput('rm input.txt')
    stdout_output = '\n'.join([line if line.count(' ') != len(line) else '\n' for line in stdout_output.replace(r'\n', '\n').replace('decrpyt', 'decrypt').strip().split('\n')])
    print("STDOUT matches\n" if stdout_output == stdout_correct else "STDOUT does not match:\n%s\n" % stdout_output)
    return (differences == '', stdout_output == stdout_correct)

  if late != -1:
    # encrypting (3 tests; worth 4 points each; max 15)
    encrypt_tests = []
    # decrypting (3 tests: worth 4 points each; max 15)
    decrypt_tests = []
    # program formatting (1 test: worth 5 points)
    format_test = True
    correct_format = 'Do you want to encrypt or decrypt? (E / D): \nOutput written to output.txt'

    for decrypted, encrypted in zip (files_to_encrypt, files_to_decrypt):
      (correctness, format_test1) = cp_run_and_diff ('E', decrypted, encrypted, correct_format)
      encrypt_tests.append(correctness)
      (correctness, format_test2) = cp_run_and_diff ('D', encrypted, decrypted, correct_format)
      decrypt_tests.append(correctness)
      format_test = format_test and format_test1 and format_test2

    
      
    if all(encrypt_tests) and all(decrypt_tests) and format_test:
      print("Perfect! ^_^")
      comments.append("passed all tests")
    elif not (any(encrypt_tests) or any(decrypt_tests) or format_test):
      print("Failed every test... ='(")
      comments.append("failed all tests (-30)")
      grade -= 30
    else:
      first_fail = True

      def print_fail (string):
        nonlocal first_fail
        if first_fail:
          first_fail = False
          print(string)

      functionality_fail = "Tests failed (5 points each):"
      num_off = 0
      if not encrypt_tests[0]:
        print_fail (functionality_fail)
        print("\tEncrypt even length")
        comments.append("failed encrypt even (-5)")
        num_off += 5
      if not encrypt_tests[1]:
        print_fail (functionality_fail)
        print("\tEncrypt odd length")
        comments.append("failed encrypt odd (-5)")
        num_off += 5
      if not encrypt_tests[2]:
        print_fail (functionality_fail)
        print("\tEncrypt multiple lines")
        comments.append("failed encrypt multi (-5)")
        num_off += 5
      if not decrypt_tests[0]:
        print_fail (functionality_fail)
        print("\tDecrypt even length")
        comments.append("failed decrypt even (-5)")
        num_off += 5
      if not decrypt_tests[1]:
        print_fail (functionality_fail)
        print("\tDecrypt odd length")
        comments.append("failed decrypt odd (-5)")
        num_off += 5
      if not decrypt_tests[2]:
        print_fail (functionality_fail)
        print("\tDecrypt multiple lines")
        comments.append("failed decrypt multi (-5)")
        num_off += 5
      if not format_test:
        print_fail (functionality_fail)
        print("\tSTDOUT Formatting")
        comments.append("incorrect formatting (-5)")
        num_off += 5
      grade -= num_off
      print("Total off: (-%d)" % num_off)

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header and comments? (y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3 - 7 days late (-30)")
      grade -= 30
    elif late == 2 :
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1 :
      comments.append("1 day late (-10)")
      grade -= 10
    
    if wrongFileName :
      comments.append("wrong filename (-10)")
      grade -= 10
    if not header :
      comments.append("missing comments or malformed header (-10)")
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign09(csid, writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  30: for 3 x 3 squares
    15: unique squares
    15: correct number for squares
  40: for the rest
    10: magic square of size 7
    10: magic square of size 9
    10: reprompts user for bad input, and 3x3 square
    10: formatting
  '''
  grade = 70

  #Test these squares
  inputText = ['7','9','2\n3']
  inputNums = [7,9,3]
  output = []
  formatting = True
  if not (fileToGrade == '' and late != -1):
    #grab output
    for text in inputText:
      try:
        process = subprocess.Popen(['python3', fileToGrade], **pipes)
        out = process.communicate(bytes(text, 'UTF-8'))[0]
        output.append(str(out)[2:-1].split('\\n'))
      except KeyboardInterrupt:
        print(' passed ^C on input',text)

    #test output
    checkedPermutations = False
    for (out,test) in zip(output,inputNums):
      out = [x.rstrip() for x in out]
      out = list(filter(None,out))

      filtered = []
      for line in out:
        #people spelt square wrong...
        if 'square' not in line and 'odd' not in line and 'magic' not in line:
          filtered.append(line)
      if len(filtered) != test + (3*8):
        print()

      square = [filtered[y] for y in range(test)]
      if formatting and not checkFormatting(square):
        formatting = False
        grade -= 10
        comment = "incorrectly formatted square (-10)"
        print(comment)
        for row in square:
          print('\t' + str(row))
        comments.append(comment)
      if not checkMagicSquare(square):
        grade -= 10
        comment = "%dx%d magic square isn't well formed (-10)"%(test,test)
        if test == 3:
          comment += ', might not have reprompted for input when given an even number'
        print(comment)
        for row in square:
          print('\t' + str(row))
        comments.append(comment)

      if not checkedPermutations: #only check permutations once
        checkedPermutations = True
        permutations = []
        trimmed = filtered[test:]
        for x in range(0,len(trimmed),3):
          square = []
          square.append(trimmed[x])
          if x + 1 < len(trimmed):
            square.append(trimmed[x+1])
          if x + 2 < len(trimmed):
            square.append(trimmed[x+2])
          permutations.append(square)
        if len(permutations) != 8:
          grade -= 15
          comment = 'outputted %d 3x3 squares instead of 8 (-15)'%len(permutations)
          print(comment)
          comments.append(comment)
        if not checkPermutations(permutations):
          grade -= 15
          comment = 'incorrect set of unique 3x3 squares (-15)'
          print(comment)
          comments.append(comment)

      if len(filtered) != test + (3*8):
        s = 'more' if len(filtered) > test + (3*8) else 'less'
        print('!!!\nparsed output contains %s lines than expected'%s)
        print('dumping raw output for test %dx%d'%(test,test))
        for line in out:
          print(line)
        off = input('Points off (enter is 0 too): ')
        off = off.strip()
        if off.isdigit():
          comment = input('Comment: ')
          comments.append(comment)
          grade -= int(off)

  if grade == 70:
    print("<('.')^ Perfection ^('.')>")      
  else:
    print("Grade: %d/70"%grade)      

  #checking for header and style
  input("Hit Enter to cat first 20 lines (header)")
  print(subprocess.getoutput('head -20 ' + fileToGrade))
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else :
    header = False
  input("Hit Enter to cat whole file (style/comments)")
  print(subprocess.getoutput('cat ' + fileToGrade))
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3-7 days late (-30)")
      grade -= 30
    elif late == 2:
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1:
      comments.append("1 day late (-10)")
      grade -= 10

    if wrongFileName or not header:
      grade -= 5
      if wrongFileName and header:
        comments.append("wrong filename (-5)")
      elif header and not wrongFileName:
        comments.append("malformed header (-5)")
      else:
        comments.append("wrong filename and malformed header (-5)")

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign15(csid, writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 0
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  5 files, 2 cases (toposort/mst, djikstras)
  10 cases total
  7 points per case
  '''

  if not (fileToGrade == '' and late != -1):
    correctFormatting = True
    count = 0
    for run in range(1,6):
      try:
        print("\n=====File %d====="%run)
        testFile = 'graph%d.txt'%run
        correctFile = '../correct%d.txt'%run
        os.system('cp ../'+ testFile +' graph.txt')
        out = subprocess.getoutput('python3 ' + fileToGrade).split('\n')
        points,c = getPoints(run,out)
        grade += points
        comments += c
        print(str(points) + '/14')
        if c != []:
          print('\n'.join(c))

      except KeyboardInterrupt:
        print(' passed on run',run)
  
  grade = 0 if grade < 0 else grade
  if grade == 70:
    print('Perfection =D')
  else:
    print('Grade: ' + str(grade)+'/70')

  #checking for header and style
  input("Hit Enter to cat first 20 lines (header)")
  print(subprocess.getoutput('head -20 ' + fileToGrade))
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else :
    header = False
  input("Hit Enter to cat whole file (style/comments)")
  print(subprocess.getoutput('cat ' + fileToGrade))
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late in [-1,2,3]:
    if writeToFile: outputFile.write('0\t More than 1 day late\n')
    if writeToFile: outputFile.write('\n')
    os.chdir("..")
    print('Late more than 1 day')
    return
  elif late == 1:
    comments.append("1 day late (-10)")
    grade -= 10
    print('1 day late (-10)')

  if wrongFileName or not header:
    grade -= 5
    if wrongFileName and header:
      comments.append("wrong filename (-5)")
    elif header and not wrongFileName:
      comments.append("malformed header (-5)")
    else:
      comments.append("wrong filename and malformed header (-5)")

  if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign14(csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  5 total test cases
  2 normal test each 5 points
    all 1's
    alternating 1 -1
  3 others
  test that it handles n correctly, 5 points
  test if inputting weird guesses is handled correctly, 5 points
  test that it handles 7 no's correctly, 5 points

  general formatting 5 points
  total of 30 points
  '''
  initialPrompt = "Guessing Game\n\nThink of a number between 1 and 100 inclusive.\nAnd I will guess what it is in 7 tries or less.\n\nAre you ready? (y/n): "
  prompt = "Enter 1 if my guess was high, -1 if low, and 0 if correct: "
  goodResponse = "Thank you for playing the Guessing Game."
  badResponse = "Either you guessed a number out of range or you had an incorrect entry."

  testCases = [
    'y\n1\n1\n1\n1\n1\n0',
    'y\n1\n-1\n1\n-1\n1\n-1\n0',
    'n\n',
    'y\nBAD INPUT\nBAD INPUT\n0\n',
    'y\n1\n-1\n1\n-1\n1\n-1\n1'
  ]
  correctOutput = [
    initialPrompt + '\nGuess  1 :  The number you thought was 50\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  2 :  The number you thought was 25\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  3 :  The number you thought was 12\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  4 :  The number you thought was 6\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  5 :  The number you thought was 3\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  6 :  The number you thought was 1\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \n'+ goodResponse,
    initialPrompt + '\nGuess  1 :  The number you thought was 50\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  2 :  The number you thought was 25\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  3 :  The number you thought was 37\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  4 :  The number you thought was 31\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  5 :  The number you thought was 34\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  6 :  The number you thought was 32\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  7 :  The number you thought was 33\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \n'+goodResponse,
    initialPrompt + '\nBye',
    initialPrompt + '\nGuess  1 :  The number you thought was 50\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nEnter 1 if my guess was high, -1 if low, and 0 if correct: \n' + goodResponse,
    initialPrompt + '\nGuess  1 :  The number you thought was 50\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  2 :  The number you thought was 25\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  3 :  The number you thought was 37\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  4 :  The number you thought was 31\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  5 :  The number you thought was 34\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  6 :  The number you thought was 32\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  7 :  The number you thought was 33\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \n'+badResponse
  ]
  if late != -1:
    answers = []
    count = 0
    for test in testCases:
      count += 1
      try:
        process = subprocess.Popen(['python3', fileToGrade], **pipes)
        out = process.communicate(bytes(test, 'UTF-8'))[0]
        answers.append(str(out)[2:-1].replace('\\n','\n').strip())
      except KeyboardInterrupt:
        print(" on test" +str(count))

    correct_formatting = True

    # gradin' normal tests 
    correct = ""
    count = 0
    numFailed = 0
    for correct,out in zip(correctOutput,answers):
      printed = False
      count += 1
      print("=====Test "+str(count)+"=====")
      #check formatting
      if out != correct and correct_formatting:
        print("\tIncorrect Formatting -5")
        print("\t=====Correct=====\n\t"+'\n\t'.join(correct.split('\n'))+"\n\t=====Output=====\n\t"+'\n\t'.join(out.split('\n')))
        printed = True
        correct_formatting = False

      #check correctness
      #if there's a perfect match no need to fuzzy match
      if not correct_formatting:
        failed = False
        theirNums = [int(s) for s in out.split() if s.isdigit()]
        ourNums = [int(s) for s in correct.split() if s.isdigit()]

        if count == 3:
          if "bye" not in out.lower(): 
            failed = True
        elif count == 5:
          if badResponse.lower()[:-1] not in out.lower(): 
            failed = True
        elif set(theirNums) != set(ourNums):
          failed = True

        if failed:
          comments.append("Failed test " + str(count) + " (-5)")
          numFailed += 1
          if not printed:
            print("\tFailed test "+str(count) + ": -5")
            print("\t=====Correct=====\n\t"+'\n\t'.join(correct.split('\n'))+"\n\t=====Output=====\n\t"+'\n\t'.join(out.split('\n')))
        else:
          print("\tPassed")
      else:
        print("\tPassed")

    #take off for test that we had to ^C
    if len(answers) < 5:
      numFailed += 5 - len(answers)

    #calculating grade time
    total_off = (numFailed * -5)
    print()
    print("Failed " + str(numFailed))

    if not correct_formatting:
      total_off -= 5
      feedback = "Incorrect formatting: -5"
      comments.append(feedback)
      print(feedback)
    grade += total_off
    print("Grade: "+str(grade)+"/70")

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header and comments? (y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3 - 7 days late (-30)")
      grade -= 30
    elif late == 2 :
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1 :
      comments.append("1 day late (-10)")
      grade -= 10
    
    if wrongFileName :
      comments.append("wrong filename (-10)")
      grade -= 10
    if not header :
      comments.append("missing comments or malformed header (-10)")
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
Exemplo n.º 15
0
# Open a File
file = open(file="text.txt", mode='wb', buffering=1)
print("Name of the title: ", file.name)
print("Closed or not: ", file.closed)
print("Opening mode: ", file.mode)
file.write(
    bytes("I am not a psychopath, I am a high functioning sociopath.\n",
          "UTF-8"))
file.close()

file = open(file="text.txt", mode="r", buffering=1)
print("Position: ",
      file.tell())  # Tell the position of the current seeking point.
data = file.read()  # Read all bytes
file.close()
print("The read data is: ", data)
print("Closed or not: ", file.closed)

# Use the OS path library.
os.rename("text.txt", "newText.txt")  # Rename the file name.
os.remove("newText.txt")  # Remove the file with this file name.
os.mkdir("folder", mode=0o777)
os.chdir("folder")
# Changes the current directory with this.
os.mkdir("test")  # Makes folder in folder with name test.

print("The current dir: ", os.getcwd())  # Prints the current directory path.
os.rmdir("folder")
# Removes the directory.
def assign01(csid, writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  53 points
  2 24 point runs
  substution encode/decode is 10 points
  vigenere encode/decode is 14 points
  5 for formatting
  '''

  fillerText = ['Substitution Cipher','Enter Plain Text to be Encoded: Encoded Text: ','Enter Encoded Text to be Decoded: Decoded Plain Text: ','Vigenere Cipher','Enter Plain Text to be Encoded: Enter Pass Phrase (no spaces allowed): Encoded Text: ','Enter Encoded Text to be Decoded: Enter Pass Phrase (no spaces allowed): Decoded Plain Text: ']
  inputText = []
  outputText = []
  outputText.append(['dsvvb kbnvw','hello world','zilwg aocdh','hello world'])
  outputText.append(['dqc emlp!!!','hai   guyz','qfh','!!tri  cky!!'])
  inputText.append(['hello world', 'dsvvb kbnvw','hello world','seal','zilwg aocdh','seal'])
  inputText.append(['HAI GUYZ!!!', 'dqc   emlp','xyz','thisisapassphrase','!!tri  cky!!','aaaaaazzzzzz'])

  if not (fileToGrade == '' and late != -1):
    correctFormatting = True
    count = 0
    for (inText,outText) in zip(inputText,outputText):
      try:
        process = subprocess.Popen(['python3',fileToGrade], **pipes)
        out = process.communicate(bytes('\n'.join(inText), 'UTF-8'))[0]
        answers = list(filter(None, str(out)[2:-1].split('\\n')))
      except KeyboardInterrupt:
        print(' passed ^C')

      #there's probably a way to loop through this jazz but meh
      correctAnswers = []
      correctAnswers.append(fillerText[0])
      correctAnswers.append(fillerText[1] + outText[0])
      correctAnswers.append(fillerText[2] + outText[1])
      correctAnswers.append(fillerText[3])
      correctAnswers.append(fillerText[4] + outText[2])
      correctAnswers.append(fillerText[5] + outText[3])
      modCount = count % 6

      for (theirs, ours) in zip(answers,correctAnswers):
        if correctFormatting:
          if theirs.strip() != ours.strip():
            correctFormatting = False
            grade -= 5
            comments.append('Incorrect Formatting (-5) yours:' + theirs +' ours:'+ours)
            print('\tIncorrect Formatting')
            print('\tTheirs\n\t'+theirs)
            print('\tOurs\n\t'+ours)
          else:
            print('Passed Test ' + str(count + 1))
        if not correctFormatting and modCount != 0 and modCount != 3:
          t = theirs.split(':')[-1].strip() 
          o = ours.split(':')[-1].strip()
          if t != o: 
            comments.append('Failed Test '+ str(count+1))
            print('X '+comments[-1])
            print('\tTheirs\n\t'+theirs)
            print('\tOurs\n\t'+ours)
            if modCount == 1 or modCount == 2:
              grade -= 5
            else:
              grade -= 7
          else:
            print('Passed Test ' + str(count+1))
        count += 1
        modCount += 1
  if grade == 70:
    print('Perfection =D')
  else:
    print('Grade: ' + str(grade)+'/70')

  #checking for header and style
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else:
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 2 days late')
    print('Late more than 2 days!')
  else:
    if late == 2:
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1:
      comments.append("1 day late (-10)")
      grade -= 10

    if wrongFileName or not header:
      grade -= 5
      if wrongFileName:
        comments.append("wrong filename (-5)")
      elif header:
        comments.append("malformed header (-5)")
      else:
        comments.append("wrong filename and malformed header (-5)")

  if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
Exemplo n.º 17
0
def assign13(csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True


  # copies ../FILE_TO_COPY.txt to ./hidden.txt and runs the program in ./
  # diffs ./found.txt with ../FILE_TO_COPY_found.txt
  perfect_formatting = True
  def cp_run_and_diff (file_to_copy):
    nonlocal perfect_formatting
    os.chdir ('..')
    subprocess.getoutput('rm "%s/hidden.txt"' % csid)
    subprocess.getoutput('rm "%s/found.txt"' % csid)
    os.system('cp %s.txt "%s/hidden.txt"' % (file_to_copy, csid))
    os.chdir(csid)
    subprocess.getoutput('python3 %s' % fileToGrade)
    if file_to_copy != bonus_name:
      print ("Testing %s:" % file_to_copy)
    success = True
    try:
      with open ('found.txt', 'r') as actual, open ('../%s_found.txt' % file_to_copy, 'r') as expected:
        actual_lines = [x.strip() for x in list(actual) if len(x.strip()) != 0]
        actual_lines.sort()
        expected_lines = [x.strip() for x in list(expected) if len(x.strip()) != 0]
        expected_lines.sort()
        if (len(actual_lines) != len(expected_lines)):
          success = False
          if (file_to_copy == file_names[0]):
            perfect_formatting = False
        else:
          last_line = None
          for expected_line, actual_line in zip(expected_lines, actual_lines):
            if not success:
              break
            if file_to_copy == file_names[0] and last_line is not None:
              perfect_formatting = perfect_formatting and len(last_line) == len(actual_line)
            last_line = actual_line
            success = expected_line.split() == actual_line.split()
        if True or not success and file_to_copy != bonus_name:
          print ('  Expected:')
          for line in expected_lines:
            print ('    |%s' % line)
          print ('  Actual:')
          for line in actual_lines:
            print ('    |%s' % line)
          print()
        elif success:
          if file_to_copy == bonus_name:
            print ("Testing '%s':" % file_to_copy)
          print ('Program output matches exactly!\n')
    except:
      if file_to_copy != bonus_name:
        print ("Program did not output to file.\n")
      if (file_to_copy == file_names[0]):
        perfect_formatting = False
      return False

    subprocess.getoutput('rm hidden.txt')
    subprocess.getoutput('rm found.txt')
    return success

  if late != -1:
    test_results = []
    for test in file_names:
      test_results.append (cp_run_and_diff (test))
    test_results.append (cp_run_and_diff (bonus_name))
    
    if test_results[-1]:
      print("Bonus: Diagonal searching implemented correctly! (+10)\n")
      comments.append("passed diagonal bonus (+10)")
      grade += 10
    if perfect_formatting and any(test_results[:-2]):
      print("Bonus: formatting is perfect! (+5)\n")
      comments.append("passed formatting bonus (+5)")
      grade += 5
    if all(test_results[:-1]):
      print("Perfect! ^_^")
      comments.append("passed all tests")
    elif not any(test_results[:-1]):
      print("Failed every test... ='(")
      comments.append("failed all tests (-30)")
      grade -= 30
    else:
      first_fail = True
      def print_fail (string):
        nonlocal first_fail
        if first_fail:
          first_fail = False
          print(string)

      functionality_fail = "Tests failed (6 points each):"
      num_off = 0
      for i in range (len(test_results) - 1):
        if not test_results[i]:
          print_fail (functionality_fail)
          print("\t%s" % file_names[i])
          comments.append("failed %s (-6)" % file_names[i])
          num_off += 6
      grade -= num_off
      print("Total off: (-%d)" % num_off)

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header and comments? (y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3 - 7 days late (-30)")
      grade -= 30
    elif late == 2 :
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1 :
      comments.append("1 day late (-10)")
      grade -= 10
    
    if wrongFileName :
      comments.append("wrong filename (-10)")
      grade -= 10
    if not header :
      comments.append("missing comments or malformed header (-10)")
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
Exemplo n.º 18
0
def assign6( csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = " "

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  if not fileToGrade == "" and late != -1:
    out = "XXInterrputed sprobs will be set to 13X"
    process = subprocess.Popen(['python3', fileToGrade], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    try:
      out = process.communicate(bytes('50000', 'UTF-8'))[0]
    except KeyboardInterrupt:
      pass
    #yup this next line of code is a little funky but yeah... it works and I'm lazy --Devin
    perfect = True
    wrong = False
    answer = (str(out)[2:-1]).replace('\\n','\n').rstrip().split('\n')
    try:
      switch = int(re.findall("\D+\d+\.(\d+)",answer[-2])[0])
      noSwitch = int(re.findall("\D+\d+\.(\d+)",answer[-1])[0])
    except IndexError:
      wrong = True
      perfect = False
      switch = 1337
      noSwitch = 1337
    #penalize for not rounding
    if switch > 99 or noSwitch > 99:
      perfect = False
      switch = round(int(str(switch)[:3]), -1) // 10
      noSwitch = round(int(str(noSwitch)[:3]), -1) // 10
    if perfect and switch + noSwitch == 100 and ( 66 <= switch <= 68) and (32 <= noSwitch <= 34):
      pass
      print("Perfect (feels nice to be nice =D)")
    elif not wrong and switch + noSwitch == 100 and (( 66 <= switch <= 68) or (32 <= noSwitch <= 34)):
      grade -= 10
      print("Close")
      print(answer[-2:])
      print("Prob when switching: " + str(switch) + " Prob when not switching: " +str(noSwitch))
      comments += "Somewhat wrong output!"
    else:
      grade -= 30
      print("Wrong")
      print(answer[-2:])
      print("Prob when switching: " + str(switch) + " Prob when not switching: " +str(noSwitch))
      comments += "Wrong output!"
  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header( (y or enter)  /  n)? ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Comments (Enter a number out of 30 to represent their grade, hit enter for 30): ")
  comments += input ("General Comments?:  ")
  if not style.isdigit() :
    style = 30
  else :
    style = int(style)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments = "3 - 7 days late, "
      grade -= 30
    elif late == 2 :
      comments = "2 days late, "
      grade -= 20
    elif late == 1 :
      comments = "1 day late, "
      grade -= 10
    
    if wrongFileName :
      comments += " wrong filename, "
      grade -= 10
    if not header :
      comments += " no/malformed header, "
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t"+comments.rstrip(', '))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
Exemplo n.º 19
0
def assign4( csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = " "

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  if not fileToGrade == "" and late < 3:
    answers = []
    for x in range(0,len(inputArray),3):
      process = subprocess.Popen(['python3', fileToGrade], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
      out = process.communicate(bytes(inputArray[x] + '\n' + inputArray[x+1] + '\n' + inputArray[x+2], 'UTF-8'))[0]
      answers.append(str(out)[2:-1])
     
    perfectCount = 0
    closeCount = 0 
    answerCount = 0
    wrongCount = 0
    for correctAnswer in correct.splitlines():
      if correctAnswer in answers[answerCount]:  #Does not contain the correct formatted answer
        print('Correct answer for #', answerCount+1)
        perfectCount += 1
      else:
        correctSplitted = correctAnswer.split()
        if  correctSplitted[-1][:-1].lower() in answers[answerCount].lower() :
          print ("Correct answer for #", answerCount+1," but incorrect formatting")
          print ("\t", correctAnswer," vs. ",answers[answerCount])
          closeCount += 1
        else:
          print("Wrong answer")
          print ("\t", correctAnswer," vs. ",answers[answerCount])
          wrongCount += 1
      answerCount += 1
    print("Perfect:", str(perfectCount) + "/10")
    print("Close:", str(closeCount) + "/10")
    print("Wrong:", str(wrongCount) + "/10")
    if wrongCount != 0 or closeCount != 0:
        grade -= (2 * wrongCount) 
        grade -= (1 * closeCount)
        comments += " Output did not match instructors, "


  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header( (y or enter)  /  n)? ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Comments (Enter a number out of 30 to represent their grade, hit enter for 30): ")
  comments += input ("General Comments?:  ")
  if not style.isdigit() :
    style = 30
  else :
    style = int(style)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
  else :
    if late == 3:
      comments = "3 - 7 days late, "
      grade -= 30
    elif late == 2 :
      comments = "2 days late, "
      grade -= 20
    elif late == 1 :
      comments = "1 day late, "
      grade -= 10
    
    if wrongFileName :
      comments += " wrong filename, "
      grade -= 10
    if not header :
      comments += " no/malformed header, "
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t"+comments.rstrip(', '))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign07(csid, writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  7 test cases (10 pts each) = 70 pts
  '''
  grade = 0
  inFiles = ['test1.in', 'test2.in', 'test3.in', 'test4.in', 'test5.in', 'test6.in', 'test7.in']
  outFiles = ['test1.out', 'test2.out', 'test3.out', 'test4.out', 'test5.out', 'test6.out', 'test7.out']

  for idx in range(len(inFiles)):
    print('Test ' + str(idx + 1) + ':')

    os.system('cp ../' + inFiles[idx] + ' Boxes.txt')
    os.system('cp ../' + inFiles[idx] + ' boxes.txt')
    # output = subprocess.getoutput('python3 ' + fileToGrade).split('\n\n')
    signal, output = execute(['python3', fileToGrade], 15)
    output = output.split('\n\n')
    correct = open('../' + outFiles[idx]).read().split('\n\n')

    subsets = set()
    correctSubsets = set()

    if signal != -1:
      for out in output:
        boxes = set()
        for line in out.split('\n'):
          box = set()
          for d in re.sub('[^\d]', ' ', line).split(' '):
            if d.isdigit():
              box.add(int(d))
          if len(box) == 3:
            boxes.add(frozenset(box))
        if len(boxes) > 0:
          subsets.add(frozenset(boxes))

      for cor in correct:
        boxes = set()
        for line in cor.split('\n'):
          box = set()
          for d in re.sub('[^\d]', ' ', line).split(' '):
            if d.isdigit():
              box.add(int(d))
          if len(box) == 3:
            boxes.add(frozenset(box))
        if len(boxes) > 0:
          correctSubsets.add(frozenset(boxes))

      if (subsets == correctSubsets):
        print('\tPassed')
        grade += 10
      else:
        print('\tFailed (-10)')
        comments.append('Failed Test ' + str(idx + 1))
    else:
      print('\tTimed Out (-10)')
      comments.append('Failed Test ' + str(idx + 1) + ' (Timed Out)')

  if grade == 70:
    print('Perfection =D')
  else:
    print('Grade: ' + str(grade) + '/70')

  #checking for header and style
  input("Hit Enter to cat first 20 lines (header)")
  print(subprocess.getoutput('head -20 ' + fileToGrade))
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else :
    header = False
  input("Hit Enter to cat whole file (style/comments)")
  print(subprocess.getoutput('cat ' + fileToGrade))
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3-7 days late (-30)")
      grade -= 30
    elif late == 2:
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1:
      comments.append("1 day late (-10)")
      grade -= 10

    if wrongFileName or not header:
      grade -= 5
      if wrongFileName and header:
        comments.append("wrong filename (-5)")
      elif not header and not wrongFileName:
        comments.append("malformed header (-5)")
      else:
        comments.append("wrong filename and malformed header (-5)")

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign12(csid, writeToFile,editor):
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []
  
  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  70 + 10
  
  15 - Sparse add()
  15 - Sparse mult()
  10 - Sparse getRow()
  10 - Sparse getCol()
  20 - Sparse str()
    10 - formatting
    10 - including 0's
  setElement broken = -10

  +10 - Sparse str() extra credit
  '''
  grade = 70

  #Test these squares
  formatting = True
  if not (fileToGrade == '' and late != -1):
    #grab output
    output = []
    for run in range(1,4):
      try:
        print("\n=====File %d===== (Ours then Theirs)"%run)
        testFile = 'matrix%d.txt'%run
        outFile = 'out%d.txt'%run
        correctFile = '../correct%d.txt'%run
        os.system('cp ../'+ testFile +' matrix.txt')
        output.append(subprocess.getoutput('python3 ' + fileToGrade + '> ' + outFile).splitlines())

        #modifying output
        f = open(outFile,'r')
        lines = f.readlines()
        f.close()
        f = open(outFile,'w')
        lines = [x.rstrip() for x in lines]
        lines = list(filter(None,lines))
        f.write('\n'.join(lines))
        f.close()

        os.system('diff -yB ' + correctFile +' '+outFile)
        print('\n'+'='*35)
      except KeyboardInterrupt:
        print(' passed on run',run)

      off = input('points off: ')
      while off != '':
        grade -= int(off)
        print('Current Grade: %d'%grade)
        comment = input('comments? ')
        if comment != '':
          comments.append(comment + ' (-%s)'%off)
        off = input('points off: ')
    print()

  if grade >= 70:
    print("<('.')^ Perfection ^('.')>")      
    print("Grade: %d/70"%grade)      
  else:
    print("Grade: %d/70"%grade)      

  #checking for header and style
  input("Hit Enter to cat first 20 lines (header)")
  print(subprocess.getoutput('head -20 ' + fileToGrade))
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else:
    header = False
  input("Hit Enter to cat whole file (style/comments)")
  if editor != '':
    os.system(editor +' '+ fileToGrade)
  else:
    print(subprocess.getoutput('cat ' + fileToGrade))
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").strip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3-7 days late (-30)")
      grade -= 30
    elif late == 2:
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1:
      comments.append("1 day late (-10)")
      grade -= 10

    if wrongFileName or not header:
      grade -= 5
      if wrongFileName and header:
        comments.append("wrong filename (-5)")
      elif header and not wrongFileName:
        comments.append("malformed header (-5)")
      else:
        comments.append("wrong filename and malformed header (-5)")

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign06(csid, writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  5 handles wrong input
  5 handles non existant names
  60 options 1 - 6
  (5 off for wrong ordering, 10 for wrong names, 5 for wrong name singular)
  -5 formatting
  -10 for no try except
  -15 for no while loop
  -20 for not reading from web
  '''
  inputList = ['1','test','1','Devin','2','Daniel','3','1950','4','5','6','A']
  ignore = ['The names are in alphabetical']
  if not (fileToGrade == '' and late != -1):
    try:
      process = subprocess.Popen(['python3',fileToGrade], **pipes)
      out = process.communicate(bytes('\n'.join(inputList), 'UTF-8'))[0]
      answers = str(out)[2:-1].replace(':','\\n').split('\\n')
      answers = list(filter(None, [line.strip() for line in answers]))

      os.chdir('..')
      process = subprocess.Popen(['python3','BabyNames.py'], **pipes)
      correctOut = process.communicate(bytes('\n'.join(inputList), 'UTF-8'))[0]
      correctAnswers = str(correctOut)[2:-1].replace(':','\\n').split('\\n')
      correctAnswers = list(filter(None, [line.strip() for line in correctAnswers]))

      os.chdir(csid)
    except KeyboardInterrupt:
      print(' passed ^C')

    temp = []
    for a in answers:
      if a not in ignore:
        temp.append(a)
      else:
        print('ignoring: ' + a)
    answers = temp
    input('done ignoring, continue?')

    perfect = True
    for (theirs,ours) in zip(answers,correctAnswers):
      if theirs.replace(' display','') != ours.replace(' display',''):
        print('\t!!!Mismatch\n'+theirs+'\n'+ours)
        perfect = False
      elif not perfect:
        print(theirs+'\n'+ours)

    print()
    if len(answers) != len(correctAnswers):
      print(len(answers),'!=',len(correctAnswers))
      for x in range(len(correctAnswers) - len(answers)):
        print(correctAnswers[len(correctAnswers)-x -1])

  if not perfect:
    grade = input('Enter a grade out of 70: ')
    if grade == '':
      grade = 70
    else:
      grade = int(grade)
  if grade == 70:
    print('Perfection =D')
  else:
    print('Grade: ' + str(grade)+'/70')

  # style time!
  input("Hit Enter to cat whole file (style/comments)")
  print(subprocess.getoutput('cat ' + fileToGrade))

  #looking for try except block
  usedTry, usedExcept,tryExceptPoints = False, False,0
  f = open(fileToGrade, 'r')
  for line in f:
    if 'try:' in line:
      usedTry = True
    if 'except' in line:
      usedExcept = True
    if usedTry and usedExcept:
      break
  f.close()
  if not (usedTry and usedExcept):
    noTryExcept = input("!!!\ncouldn't find try except block\nhit enter to take of 10 points: ")
    if noTryExcept == "":
      tryExceptPoints = 10
      comments.append('no try except block (-10)')
  #-10 for no header
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else :
    header = False

  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  style -= tryExceptPoints
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3-7 days late (-30)")
      grade -= 30
    elif late == 2:
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1:
      comments.append("1 day late (-10)")
      grade -= 10

    if wrongFileName or not header:
      grade -= 5
      if wrongFileName and header:
        comments.append("wrong filename (-5)")
      elif not header and not wrongFileName:
        comments.append("malformed header (-5)")
      else:
        comments.append("wrong filename and malformed header (-5)")

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
Exemplo n.º 23
0
 def setUp(self):
     #chdir to test dir so that relative resource files are resolved
     # even when test is run from an other directory
     self.previous_workdir=os.getcwd();
     os.chdir(os.path.dirname(__file__))
Exemplo n.º 24
0
def assign14(csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  5 total test cases
  2 normal test each 5 points
    all 1's
    alternating 1 -1
  3 others
  test that it handles n correctly, 5 points
  test if inputting weird guesses is handled correctly, 5 points
  test that it handles 7 no's correctly, 5 points

  general formatting 5 points
  total of 30 points
  '''
  initialPrompt = "Guessing Game\n\nThink of a number between 1 and 100 inclusive.\nAnd I will guess what it is in 7 tries or less.\n\nAre you ready? (y/n): "
  prompt = "Enter 1 if my guess was high, -1 if low, and 0 if correct: "
  goodResponse = "Thank you for playing the Guessing Game."
  badResponse = "Either you guessed a number out of range or you had an incorrect entry."

  testCases = [
    'y\n1\n1\n1\n1\n1\n0',
    'y\n1\n-1\n1\n-1\n1\n-1\n0',
    'n\n',
    'y\nBAD INPUT\nBAD INPUT\n0\n',
    'y\n1\n-1\n1\n-1\n1\n-1\n1'
  ]
  testDescription = [
    'Thinking of 1',
    'Thinking of 33',
    "User doesn't want to play",
    'Entering something other than 1, -1, or 0',
    'More than 7 guesses should fail'
  ]
  correctOutput = [
    initialPrompt + '\nGuess  1 :  The number you thought was 50\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  2 :  The number you thought was 25\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  3 :  The number you thought was 12\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  4 :  The number you thought was 6\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  5 :  The number you thought was 3\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  6 :  The number you thought was 1\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \n'+ goodResponse,
    initialPrompt + '\nGuess  1 :  The number you thought was 50\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  2 :  The number you thought was 25\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  3 :  The number you thought was 37\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  4 :  The number you thought was 31\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  5 :  The number you thought was 34\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  6 :  The number you thought was 32\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  7 :  The number you thought was 33\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \n'+goodResponse,
    initialPrompt + '\nBye',
    initialPrompt + '\nGuess  1 :  The number you thought was 50\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nEnter 1 if my guess was high, -1 if low, and 0 if correct: \n' + goodResponse,
    initialPrompt + '\nGuess  1 :  The number you thought was 50\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  2 :  The number you thought was 25\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  3 :  The number you thought was 37\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  4 :  The number you thought was 31\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  5 :  The number you thought was 34\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  6 :  The number you thought was 32\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \nGuess  7 :  The number you thought was 33\nEnter 1 if my guess was high, -1 if low, and 0 if correct: \n'+badResponse
  ]

  if late != -1:
    answers = []
    for i, test in enumerate(testCases):
      try:
        process = subprocess.Popen(['python3', fileToGrade], **pipes)
        out = process.communicate(bytes(test, 'UTF-8'))[0]
        answers.append(str(out)[2:-1].replace('\\n','\n').strip())
      except KeyboardInterrupt:
        print(" on test" +str(i+1))

    # Check formatting using the first test case.
    correct_formatting = True
    answer_lines = answers[0].replace('  ', ' ').split('\n')
    correct_lines = correctOutput[0].replace('  ', ' ').split('\n')
    if len(answer_lines) != len(correct_lines):
      formatting_mistake = "Output has the wrong number of lines."
      correct_formatting = False
    elif "Guessing Game" not in answer_lines[0]:
      formatting_mistake = "First line in output is incorrect."
      correct_formatting = False
    elif "Think of a number between 1 and 100 inclusive." not in answer_lines[2] or \
         "And I will guess what it is in 7 tries or less." not in answer_lines[3]:
      formatting_mistake = "Game intro is missing or incorrect."
      correct_formatting = False
    elif "Are you ready? (y/n):" not in answer_lines[5]:
      formatting_mistake = "Did not ask if user was ready."
      correct_formatting = False
    elif "Guess 1" not in answer_lines[6] or \
         "Guess 2" not in answer_lines[8] or \
         "Guess 3" not in answer_lines[10]:
      formatting_mistake = "Didn't list guess numbers correctly."
      correct_formatting = False
    elif "Enter 1 if my guess was high, -1 if low, and 0 if correct:" not in answer_lines[7] or \
         "Enter 1 if my guess was high, -1 if low, and 0 if correct:" not in answer_lines[9] or \
         "Enter 1 if my guess was high, -1 if low, and 0 if correct:" not in answer_lines[11]:
      formatting_mistake = "Didn't promp user to enter 0, -1, or 1 correctly."
      correct_formatting = False
    elif "Thank you for playing the Guessing Game." not in answer_lines[-1]:
      formatting_mistake = "Did not correctly thank the user for playing."
      correct_formatting = False
    
    if not correct_formatting:
      print("\tIncorrect Formatting (-5)")
      print("\t=====Correct=====\n\t"+'\n\t'.join(correct_lines)+"\n\t=====Output=====\n\t"+'\n\t'.join(answer_lines))

    # gradin' normal tests
    numFailed = 0
    for i,(correct,out) in enumerate(zip(correctOutput,answers)):
      print("=====Test "+str(i+1)+"=====")
      # check correctness
      failed = False
      # Get numbers following the intro to the game.
      theirNums = [int(s) for s in out[out.find('Are you ready')+1:].split() if s.isdigit()]
      ourNums = [int(s) for s in correct[correct.find('Are you ready')+1:].split() if s.isdigit()]

      if i == 2:
        if "bye" not in out.lower(): 
          failed = True
      elif i == 3:
        if out.count("Enter 1 if my guess was high, -1 if low, and 0 if correct:") != 3:
          failed = True
      elif i == 4:
        if badResponse.lower()[:-1] not in out.lower(): 
          failed = True
      elif theirNums != ourNums:
        failed = True

      if failed:
        comments.append("Failed test " + str(i+1) + ": " +
                        testDescription[i] + " (-5)")
        numFailed += 1
        print("\tFailed test "+str(i+1) + ": -5")
        print("\t=====Correct=====\n\t"+'\n\t'.join(correct.split('\n'))+"\n\t=====Output=====\n\t"+'\n\t'.join(out.split('\n')))
      else:
        print("\tPassed")

    #take off for test that we had to ^C
    if len(answers) < 5:
      numFailed += 5 - len(answers)

    #calculating grade time
    total_off = (numFailed * -5)
    print()
    print("Failed " + str(numFailed))

    if not correct_formatting:
      total_off -= 5
      feedback = "Incorrect formatting: " + formatting_mistake + " (-5)"
      comments.append(feedback)
      print(feedback)
    grade += total_off
    print("Grade: "+str(grade)+"/70")

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header and comments? (y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3 - 7 days late (-30)")
      grade -= 30
    elif late == 2 :
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1 :
      comments.append("1 day late (-10)")
      grade -= 10
    
    if wrongFileName :
      comments.append("wrong filename (-10)")
      grade -= 10
    if not header :
      comments.append("missing comments or malformed header (-10)")
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
Exemplo n.º 25
0
 def tearDown(self):
     os.chdir(self.previous_workdir)
Exemplo n.º 26
0
def assign8( csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  if not fileToGrade == "" and late != -1:
    correct_format_left = True
    correct_format_mid = True
    correct_format_right = True
    correct_format_other = True
    valid_output = True
    calculated_values = []

    # perfect match
    first_line = "Computation of PI using Random Numbers"
    last_line = "Difference = Calculated PI - math.pi"
    # Columns must line up, the calculated pi must have 6 decimal places, and
    # there must be a +/- in front of the difference. However, column spacing
    # can be off by +/- 1.
    regex_perfect = "^num = 100[0 ]{5}  [ ]{0,2}Calculated PI = \d\.\d{6}  [ ]{0,2}Difference = [+-]\d(?:\.\d{6}|e[+-]\d{5})$"
    regex_left = "100[\d\s]{5}"
    regex_mid = "=\s*[\d\.]{8}"
    regex_right = "[+-e\d\.]{9}$"

    # grab pi and difference
    regex_grab = "[+-]?\d*\.?\d+(?:[eE][+-]\d+)?"

    for run_num in range(averageNumRuns):
      process = subprocess.Popen(['python3', fileToGrade], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
      try:
        out = process.communicate(bytes('50000', 'UTF-8'))[0]
      except KeyboardInterrupt:
        out = "\n\n\n\n"
      answer = list(line.strip() for line in str(out)[2:-1].replace('\\n', '\n').replace('\\t', '\t').strip().split('\n'))
      print('\n'.join(answer))

      # grab the difference
      try:
        raw_grabbed = list(filter(lambda match: len(match) > 0, [re.findall(regex_grab, line) for line in answer]))
        grabbed_pi = [float(pi) for (_, pi, _) in raw_grabbed]
        grabbed_diff = [float(diff) for (_, _, diff) in raw_grabbed]
        calculated_values.append(grabbed_diff)
      except:
        pass

      # perfect matching
      correct_format_other = correct_format_other and answer[0] == first_line and answer[-1] == last_line and len(answer) is 10
      try:
        perfect_matches = list(filter(lambda match: match is not None, [re.search(regex_perfect, line) for line in answer]))
        correct_format_other = correct_format_other and len(perfect_matches) is 6
      except:
        correct_format_other = False
      try:
        left_matches = list(filter(lambda match: match is not None, [re.search(regex_left, line) for line in answer]))
        correct_format_left = correct_format_left and len(left_matches) is 6
      except:
        correct_format_left = False
      try:
        mid_matches = list(filter(lambda match: match is not None, [re.search(regex_mid, line) for line in answer]))
        correct_format_mid = correct_format_mid and len(mid_matches) is 6
      except:
        correct_format_mid = False
      try:
        right_matches = list(filter(lambda match: match is not None, [re.search(regex_right, line) for line in answer]))
        correct_format_right = correct_format_right and len(right_matches) is 6
      except:
        correct_format_right = False

      # 0. verify decreasing error as n increases
      # 1. verify avg_diff + avg_pi is very close to math.pi
      # 2. verify avg_pi is within 0.5 of math.pi
      try:
        averages = list(map(lambda tup: sum(tup) / len(tup), zip(*[[math.fabs(x) for x in run] for run in calculated_values])))
        average_pi = [math.fabs(x) for x in grabbed_pi]
        average_pi = sum(average_pi) / len(average_pi)
        print("This Run: %s" % ', '.join(['%.6f' % math.fabs(x) for x in grabbed_diff]))
        print("All Runs: %s\n" % ', '.join(map(lambda i: '%.6f' % i, averages)))
        valid_output = valid_output and all([(math.fabs(calc - math.pi - diff) < 0.0001) for calc, diff in zip(grabbed_pi, grabbed_diff)])
        valid_output = valid_output and math.fabs(math.pi - average_pi) < 0.5
      except:
        valid_output = False

      # stops if either the current run or the average runs pass condition 0
      if all(x >= y for x,y in zip(averages, averages[1:])) or all(math.fabs(x) >= math.fabs(y) for x,y in zip(grabbed_diff, grabbed_diff[1:])):
        break

    if correct_format_left and correct_format_mid and correct_format_right and correct_format_other and valid_output:
      print("Perfect! ^_^")
    elif not (correct_format_left or correct_format_mid or correct_format_right or correct_format_other or valid_output):
      print("non-working code. ='(")
      comments.append("non-working code (-25)")
      grade -= 25
    else:
      if not correct_format_left:
        manual_override = input("Is num left justified? (y / (n or enter)): ")
        if manual_override != 'y':
          comments.append("num not left justified (-5)")
          grade -= 5
      if not correct_format_mid:
        manual_override = input("Does pi have 6 decimals and no sign in front? (y / (n or enter)): ")
        if manual_override != 'y':
          comments.append("pi not expressed to six decimals or with sign (-5)")
          grade -= 5
      if not correct_format_right:
        manual_override = input("Does diff have 6 decimals and a sign in front? (y / (n or enter)): ")
        if manual_override != 'y':
          comments.append("diff not expressed to six decimals or without sign (-5)")
          grade -= 5
      if not correct_format_other:
        manual_override = input("Is there spacing or other general misformatting " +
                                "not yet covered? This includes the case where " +
                                "they forgot to have the opening and ending lines. " +
                                "((y or enter) / n): ")
        if manual_override != 'n':
          explanation = input("Care to elaborate? ")
          if explanation == "": explanation = "spacing or other general misformatting in output"
          comments.append(explanation + " (-5)")
          grade -= 5
      if not valid_output:
        print("calculations are wrong (-5)")
        comments.append("diff is wrong sign or just wrong (-5)")
        grade -= 5

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header and comments? (y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").strip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "code style looks fine"
  if not style.isdigit() or style == 30:
    style = 30
    gen_comments += " (-0)"
  else :
    style = int(style)
    gen_comments += " (%+d)" % (style - 30)
  comments.append("%s" % gen_comments)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3 - 7 days late (-30)")
      grade -= 30
    elif late == 2 :
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1 :
      comments.append("1 day late (-10)")
      grade -= 10
    
    if wrongFileName :
      comments.append("wrong filename (-10)")
      grade -= 10
    if not header :
      comments.append("missing comments or malformed header (-10)")
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign01(csid, writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  tests 1-5: 10 pts ea
  tests 6-9: 5 pts ea
  '''
  if not (fileToGrade == '' and late != -1):
    os.system('cp ../nim.txt .')
    outputLines = subprocess.getoutput('python3 ' + fileToGrade).splitlines()

    minLen = min(len(outputLines), len(correctLines))
    grade = 0
    index = 0
    testsFailed = []
    for i in range(minLen):
      if i < 5 and outputLines[i] == correctLines[i]:
        grade += 10
      elif i < 9 and outputLines[i] == correctLines[i]:
        grade += 5
      elif i == 4 and outputLines[i] == 'Remove 1 counters from Heap 1':
        grade += 10
      else:
        print('Failed Test',i)
        print('\tTheir Output')
        print('\t' + outputLines[i])
        print('\tCorrect Output')
        print('\t' + correctLines[i])
        testsFailed.append(i)

    if len(testsFailed) != 0:
      comments.append("Failed tests " + ' '.join(str(x) for x in testsFailed))
    else:
      print('Passed all tests =D')

  #checking for header and style
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else :
    header = False
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 2 days late')
    print('Late more than 2 days!')
  else :
    if late == 2:
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1:
      comments.append("1 day late (-10)")
      grade -= 10

    if wrongFileName:
      comments.append("wrong filename (-10)")
      grade -= 10

    if not header:
      comments.append("missing comments or malformed header (-5)")
      grade -= 5

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
def assign14(csid, writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = []

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile:
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  '''
  75 points (caps at 70)
  10 7 pt runs
  5 for formatting
  '''

  #fillerText = ['Substitution Cipher','Enter Plain Text to be Encoded: Encoded Text: ','Enter Encoded Text to be Decoded: Decoded Plain Text: ','Vigenere Cipher','Enter Plain Text to be Encoded: Enter Pass Phrase (no spaces allowed): Encoded Text: ','Enter Encoded Text to be Decoded: Enter Pass Phrase (no spaces allowed): Decoded Plain Text: ']
  fillerText = ['Enter encryption key: ', 'Enter string to be encrypted: Encrypted string: ', 'Enter string to be decrypted: Decrypted string: ']
  inputText = []
  outputText = []

  #TODO: Modify this text: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1========================

  outputText.append(['*!<!<!>!<<!*!<','meet me'])
  outputText.append(['<!<<!<><>><<<!<><>><<<!<><>>!<<<!>>!<><>>!<>>!<><>><<<!<<<>>','civic racecar'])
  outputText.append(['<><>><<!<<!<<!*!<<<!<><>><<!<<','meet me'])
  outputText.append(['>>!>>>!>>>!<!*!>>>>>>>>>>>>><','no cd'])
  outputText.append(['<<<><<!<><>><<<!<><!<<<>!<<!<<<!<><>><!<<<!<<<><!<><>>!<<<><','ttt   '])

  inputText.append(['meet me', 'meet me','*!<!<!>!<<!*!<'])
  inputText.append(['the quick brown fox jumps over the lazy dog', 'Hello World','<<<>!<><!>><!<><!<<<>!<<<!<>>!<<<><<!<<<>!<<!<<<>!<<<><<!<>>'])
  inputText.append(['the quick brown fox jumps over the lazy dog', 'meet me','<><>><<!<<!<<!*!<<<!<><>><<!<<'])
  inputText.append(['abcdefghijklm zyxwvutsrqpno', 'CDd ay','>>>>>>>>>>>>><<<<<<<<<<<!>>>>>>>>>>>>><<<<<<<<<<<>!<!>>!>>>'])
  inputText.append(['the quick brown fox jumps over the lazy dog', 'Alice N BOB','*!*!*!<<<!<<<!<<<'])

  if not (fileToGrade == '' and late != -1):
    correctFormatting = True
    count = 0
    for (inText,outText) in zip(inputText,outputText):
      try:
        process = subprocess.Popen(['python3',fileToGrade], **pipes)
        out = process.communicate(bytes('\n'.join(inText), 'UTF-8'))[0]
        answers = list(filter(None, str(out)[2:-1].split('\\n')))
      except KeyboardInterrupt:
        print(' passed ^C')

      #there's probably a way to loop through this jazz but meh
      correctAnswers = []
      correctAnswers.append(fillerText[0])
      correctAnswers.append(fillerText[1] + outText[0])
      correctAnswers.append(fillerText[2] + outText[1])

      for (theirs, ours) in zip(answers,correctAnswers):
        if correctFormatting:
          if theirs.strip() != ours.strip():
            correctFormatting = False
            grade -= 5
            comments.append('Incorrect Formatting (-5) YOURS:' + theirs +' OURS:'+ours)
            print('\tIncorrect Formatting')
            print('\tTheirs\n\t'+theirs)
            print('\tOurs\n\t'+ours)
          else:
            print('Passed Test ' + str(count + 1))
        if not correctFormatting:
          t = theirs.split(':')[-1].strip() 
          o = ours.split(':')[-1].strip()
          if t != o: 
            comments.append('  || Failed Test '+ str(count+1))
            comments.append(': ' + inText[(count%3)] + ' with key: ' + inText[0])
            comments.append(' YOURS:' + theirs +' OURS:'+ours)
            print('Failed Test '+ str(count+1))
            print(inText[(count%3)] + ' with key: ' + inText[0])
            print('\tTheirs\n\t'+theirs)
            print('\tOurs\n\t'+ours)
            grade -= 7
          else:
            print('Passed Test ' + str(count+1))
        count += 1
  if grade == 70:
    print('Perfection =D')
  elif grade < 0:
    grade = 0
    print('Grade: ' + str(grade)+'/70')
  else:
    print('Grade: ' + str(grade)+'/70')

  #checking for header and style
  input("Hit Enter to cat first 20 lines (header)")
  print(subprocess.getoutput('head -20 ' + fileToGrade))
  headerInput = input("Header(y/n, hit enter for y): ")
  if headerInput == 'y' or headerInput == '':
    header = True
  else :
    header = False
  input("Hit Enter to cat whole file (style/comments)")
  print(subprocess.getoutput('cat ' + fileToGrade))
  style = input("Style/Other (Out of 30, hit enter for 30): ")
  gen_comments = input("General Comments?: ").rstrip().lstrip()
  gen_comments = gen_comments if len(gen_comments) is not 0 else "style"
  if not style.isdigit():
    style = 30
  else :
    style = int(style)
  if (gen_comments != "style" or style != 30):
    gen_comments += " (%+d)" % (style - 30)
    comments.append("%s" % gen_comments)

  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
    print('Late more than 7 days!')
  else :
    if late == 3:
      comments.append("3-7 days late (-30)")
      grade -= 30
    elif late == 2:
      comments.append("2 days late (-20)")
      grade -= 20
    elif late == 1:
      comments.append("1 day late (-10)")
      grade -= 10

    if wrongFileName or not header:
      grade -= 5
      if wrongFileName and header:
        comments.append("wrong filename (-5)")
      elif header and not wrongFileName:
        comments.append("malformed header (-5)")
      else:
        comments.append("wrong filename and malformed header (-5)")

    if writeToFile: outputFile.write(str(grade+style) + "\t" + ', '.join(comments))

  if writeToFile: outputFile.write('\n')
  os.chdir("..")
Exemplo n.º 29
0
def assign6( csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = " "

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
      os.chdir("..")
      return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  if not fileToGrade == "" and late != -1:
    answers = []
    for x in range(len(inputArray)):
      process = subprocess.Popen(['python3', fileToGrade], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
      try:
        out = process.communicate(bytes('\n'.join(inputArray[x].split()) + '\n', 'UTF-8'))[0]
      except KeyboardInterrupt:
        pass
      answers.append(str(out)[2:-1])

    count = 0
    perfectCount = 0
    closeCount = 0 
    wrongCount = 0
    for answer, cor in zip(answers,correct):
      cor = cor.split()
      #extracting relevant data form the students output
      nums = re.findall("\D+(\d+)\D+(\d+)", answer)
      if len(nums) != 1:
        wrongCount += 1
        continue
      elif len(nums[0]) != 2:
        wrongCount += 1
        continue
      longNum = int(nums[0][0])
      cycleLength = int(nums[0][1])

      #perfect check
      if count >= 6: #negative testing time! 
        perfect = "Enter starting number of the range: \nEnter ending number of the range: \n" * 6 +"The number " + str(cor[0]) + " has the longest cycle length of " + str(cor[1]+".")
      else:
        perfect = "Enter starting number of the range: \nEnter ending number of the range: \nThe number " + str(cor[0]) + " has the longest cycle length of " + str(cor[1]+".")

      if perfect == answer.replace('\\n','\n').rstrip('\n'):
        print('Perfect answer for #', count + 1)
        perfectCount +=1
      elif longNum == int(cor[0]) and cycleLength == int(cor[1]):
        print('Close answer for #', count + 1)
        print(perfect+"\n\tvs.\n\t"+answer.replace('\\n','\n\t'))
        closeCount += 1
      else:
        print('Wrong answer for #', count + 1)
        print(perfect+"\n\tvs.\n\t"+answer.replace('\\n','\n\t'))
        wrongCount += 1
      count += 1

    print("Perfect:", str(perfectCount) + "/10")
    print("Close:", str(closeCount) + "/10")
    print("Wrong:", str(wrongCount) + "/10")
    if wrongCount != 0 or closeCount != 0:
        grade -= (3 * wrongCount) 
        grade -= (1 * closeCount)
        comments += " Output did not match instructors P: "+str(perfectCount)+" C: "+str(closeCount)+" W: "+str(wrongCount)+ ", "


  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header( (y or enter)  /  n)? ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Comments (Enter a number out of 30 to represent their grade, hit enter for 30): ")
  comments += input ("General Comments?:  ")
  if not style.isdigit() :
    style = 30
  else :
    style = int(style)
  
  #writing grade time!
  if late == -1:
    if writeToFile: outputFile.write('0\t More than 7 days late')
  else :
    if late == 3:
      comments = "3 - 7 days late, "
      grade -= 30
    elif late == 2 :
      comments = "2 days late, "
      grade -= 20
    elif late == 1 :
      comments = "1 day late, "
      grade -= 10
    
    if wrongFileName :
      comments += " wrong filename, "
      grade -= 10
    if not header :
      comments += " no/malformed header, "
      grade -= 10

    if writeToFile: outputFile.write(str(grade+style) + "\t"+comments.rstrip(', '))
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")
Exemplo n.º 30
0
# 关闭打开的文件
fo.close()

fo = open(pathfile, "r+");

strRead = fo.read(30);
print (strRead)

strReada = fo.read();
print (strReada);

fo.close();
#remove()方法删除文件,需要提供要删除的文件名作为参数。
os.remove("foo1.txt");
#rename()方法需要两个参数,当前的文件名和新文件名。
os.renames("foo.txt", "foo1.txt");

#可以使用os模块的mkdir()方法在当前目录下创建新的目录们。你需要提供一个包含了要创建的目录名称的参数
os.mkdir("test");
#可以用chdir()方法来改变当前的目录。chdir()方法需要的一个参数是你想设成当前目录的目录名称。
os.chdir("test")
#getcwd()方法显示当前的工作目录。
# 给出当前的目录
print  (os.getcwd());


#os.removedirs("")


Exemplo n.º 31
0
def assign2( csid , writeToFile) :
  fileToGrade = ""
  late = 0
  grade = 70
  style = 30
  wrongFileName = False
  header = True
  comments = " "
  manualComments = ""

  os.chdir(csid)
  if writeToFile: outputFile.write(csid + "\t")
  files = os.listdir('.')

  #filename checking
  for f in files :
    splitted = subprocess.getoutput('ls -l ' + f).split()
    if f == filename :
      fileToGrade = filename
      late = isLate(splitted)
      break
    elif f == filename.lower() :
      fileToGrade = filename.lower()
      late = isLate(splitted)
      wrongFileName = True
      break

  #really odd filename
  if fileToGrade == "" :
    print(subprocess.getoutput('ls -l'))
    fileToGrade = input("Which file should I grade? ")
    if fileToGrade == "" :
      if writeToFile: 
        outputFile.write("0\tno file\n")
        os.chdir("..")
        return
    else :
      splitted = subprocess.getoutput('ls -l ' + fileToGrade.replace(' ','\ ')).split()
      late = isLate(splitted)
      wrongFileName = True

  #grading time!
  if not fileToGrade == "" and late < 3:
    answers = []
    for creditCardNumber in inputArray:
      process = subprocess.Popen(['python3', fileToGrade], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
      out = process.communicate(bytes(creditCardNumber, 'UTF-8'))[0]
      answers.append(str(out)[2:-1])
     
    perfectCount = 0
    closeCount = 0
    wrongCount = 0
    VISA_answers = [0, 1, 2, 3]
    MasterCard_answers = [4, 5]
    correct_VISA_count = 0
    correct_MasterCard_count = 0
    # Used to ensure the inverse of the right answer is not also in the output.
    inverse = {'Valid credit card number': 'Invalid credit card number',
               'Invalid credit card number': 'Valid credit card number'}
    correct_answers = correct.splitlines()
    for answerCount, correctAnswer in enumerate(correct_answers):
      answer = answers[answerCount]
      # Contains the correct formatted answer.
      if correctAnswer in answer and not inverse[correctAnswer] in answer:  
        print('Correct answer for #', answerCount+1)
        perfectCount += 1
        # If the card number is a VISA, check if they did extra credit.
        if answerCount in VISA_answers and '\\nVISA\\n' in answer:
            correct_VISA_count += 1
        # If the card number is a MasterCard, check if they did extra credit.
        if answerCount in MasterCard_answers and '\\nMasterCard\\n' in answer:
            correct_MasterCard_count += 1
      # Contains right answer, but not correctly formatted.
      elif correctAnswer.lower()[0:5] in answer.lower() and not inverse[correctAnswer].lower()[0:5] in answer.lower():
        print ("Correct answer for #", answerCount+1," but incorrect formatting")
        print ("\t", correctAnswer[0:1],"-",answer)
        closeCount += 1
      else:
        print("Wrong answer for #", answerCount+1)
        wrongCount += 1
    print("Perfect:", str(perfectCount) + "/" + str(len(correct_answers)))
    print("Close:", str(closeCount) + "/" + str(len(correct_answers)))
    print("Wrong:", str(wrongCount) + "/" + str(len(correct_answers)))
    print("Correct VISA:", str(correct_VISA_count) + "/" + str(len(VISA_answers)))
    print("Correct MasterCard:", str(correct_MasterCard_count) + "/" + str(len(MasterCard_answers)))
    grade = 70 - (5 * wrongCount) 
    if(1 <= closeCount <= 4):
      grade -= 5
      comments += " Output did not match instructor's, "
    elif(closeCount > 4):
      grade -= 10
      comments += " Output did not match instructor's, "
    # Add points for extra credit - 5 if all correct, 3 if some.
    if correct_VISA_count == len(VISA_answers) and correct_MasterCard_count == len(MasterCard_answers):
      grade += 5
    elif correct_VISA_count > 0 or correct_MasterCard_count > 0:
      grade += 3


  #TODO fix the else below to output the correct comments   
  else:
    #print('Their output:')
    #print(out)
    #print('Correct output:')
    #print(correct)
    #print('logo has ' + str(len(lines)) +' lines, not 19')
    #don't dock points for lateness or wrong filename here
    gradeInput = input("Grade out of 70 (no style, hit enter if 65): ")
    if gradeInput == '' :
      grade = 65
    else :
      grade = int(gradeInput)
    manualComments = input("Comments: ")

  #checking for header and style
  #os.system('vim ' + fileToGrade)
  input("Hit Enter to cat")
  print(subprocess.getoutput('cat ' + fileToGrade))
  headerInput = input("Header( (y or enter)  /  n)? ")
  if headerInput == 'y' or headerInput == '' :
    header = True
  else :
    header = False
  style = input("Style/Comments (Enter a number out of 30 to represent their grade, hit enter for 30): ")
  comments += input ("General Comments?:  ")
  if not style.isdigit() :
    style = 30
  else :
    style = int(style)
  
  #writing grade time!
  if late == 3 :
    if writeToFile: outputFile.write('0\t 3 days late')
  else :
    if late == 2 :
      comments = "2 days late, "
      grade -= 20
    elif late == 1 :
      comments = "1 day late, "
      grade -= 10
    
    if wrongFileName :
      comments += " wrong filename, "
      grade -= 10
    if not header :
      comments += " no/malformed header, "
      grade -= 10
    if writeToFile: outputFile.write(str(grade+style) + "\t"+comments.rstrip(', ') + manualComments)
      
  if writeToFile: outputFile.write('\n')
  os.chdir("..")