예제 #1
0
파일: checks.py 프로젝트: ljdawn/pygrader
def a1( dir ):
    file, dispfile, score_multiplier, output = get_start( dir, 1.0, "" )
    score = 1.0
    inp = "\n" * 10
    (ev, out, err) = check_utils.wrap_assignment( file, inp )
    matches = re.finditer( r"((?:\w+\.)?\w+)@((\w+\.)+\w+)", out )
    found_ncf = False
    found = []
    for m in matches:
        found.append( m.group() )
        if m.group(2) == 'ncf.edu':
            output += "{0} looks like an ncf email address\n".format( 
                m.group() )
            found_ncf = True
    if len(found) == 0:
        output += "No email address found\n"
        score = 0.0
    elif not found_ncf:
        output += "Looking for NCF email address, got: {0}\n".format(
            ", ".join( found ) )
        score -= 0.6
    if len(found) > 1:
        output += "Only 1 email wanted, not {0} ({1}).\n".format( 
            len(found), ", ".join( found ) )
        score -= 0.2
    return (score*score_multiplier, output)
예제 #2
0
파일: checks.py 프로젝트: ljdawn/pygrader
def a3( dir ):
    file, dispfile, score_multiplier, output = get_start( dir, 1.0, "" )
    score_multiplier, output = comments_message( file, dispfile,
                                                 score_multiplier, output,
                                                 penalty = 0.05 )

    max_score = (60+20)*30  #a few extra points for correct # lines, etc.
    score = max_score
    bf = open( 'checks/a3.txt', "r" )
    benchmark = map( lambda s: s.rstrip("\n"), bf.readlines() )
    bf.close()
    if file == None:
        return ( score_multiplier, output )
    (ev, out, err ) = check_utils.wrap_assignment( file, '' )
    #remove final newline, or it will add an extra empty str to lines
    lines = out.rstrip("\n").split("\n")
    if re.search( "@", lines[0] ):
        #move the email to the end:
        email = lines[0]
        lines = lines[1:]
        lines.append( email )
    if len(lines) != len(benchmark):
        output += "{desc} lines -- got {a} expecting {b}\n".format(
            desc = "Too many" if len(lines) > len(benchmark) else "Not enough",
            a = len(lines), b = len(benchmark) )
        output += "Comparing non-blank lines only: "
        score -= abs( len(lines) - len(benchmark) ) * 10 + 80
        def remove_blanks( lns ):
            return filter( lambda l: not re.match( '^\s*$', l ), lns )
        lines = remove_blanks( lines )
        benchmark = remove_blanks( benchmark )
    else:
        output += "Correct number of lines.\nComparing output: "
    def compare_lines( u, b ):
        longer = len(u) > len(b)
        matches = 0
        #print "len b: ", len(b)
        for i in range(len(b)):
            if len(u) <= i:
                break
            if b[i] == u[i]:
                matches += 1
        return (matches, longer)
    match_chars_total = 0
    for i in range(len(benchmark)):
        if len(lines) <= i:
            score -= 70
            #print "missing line: -70"
            #print score
            continue

        sl = lines[i]
        bl = benchmark[i]
        match_count, longer = compare_lines( sl, bl )
        if longer:
            score -= 10
        #print "good matches: ", match_count
        if match_count < 10:
            #allow some points back by comparing w/o whitespace:
            match2, longer = compare_lines( re.sub(r"\s", '', sl),
                                            re.sub(r"\s", '', bl) )
            match_count += int(float(match2)/3.0)
        match_chars_total += match_count
        #print "match count: ", match_count
        deduction = 60 - match_count
        #print "deduction: ",deduction
        score -= deduction if deduction > 0 else 0
        #print score
    output += "{0} characters match.\n".format( match_chars_total )
    return ((float(score)/float(max_score))*score_multiplier, output)
예제 #3
0
파일: checks.py 프로젝트: ljdawn/pygrader
    def run_assignment( a, b, c, prec, roots_only = False ):
        results = []
        def p_result( str ):
            results.append( str )
        if roots_only:
            score = 20
            max_score = 20
        else:
            score = 100
            max_score = 100

        words = map( lambda x: check_utils.randomword(8,12), range(6) )
        
        inp = "\n".join( map(str,[a, b, c, prec]) ) + "\n" + \
            "\n".join( words ) + "\n"*20 #extra lines in case it asks for it
        (ev, out, err) = check_utils.wrap_assignment( file, inp )
        root_matches = root_regx.finditer( out )
        root_strs = []
        if root_matches != None:
            for rmatch in root_matches:
                root_strs.append(rmatch.groups())
        #print "root strs: ", root_strs
        if not roots_only:
            #look for equation display:
            eqn_match = eqn_regx.search( out )
            if eqn_match == None:
                p_result( "quadratic not displayed" )
                score -= 10
            else:
                p_result( "quadratic: {0}".format( eqn_match.group() ) )

        if len(root_strs) == 0:
            p_result( "No roots generated" )
            score -= 20
        elif len(root_strs) > 2:
            p_result( "Too many roots ({0})".format( len(root_strs) ) )
            score -= 20
        elif len(root_strs) < 2:
            p_result( "Not enough roots" )
            score -= 20
        else:
            epsilon = 5*10**(-1*(prec - 1))
            for r in root_strs:
                x = complex( float(r[0]), float(r[1]) )
                val = a*x**2+b*x+c
                #val should be == 0
                if abs(val) > epsilon:
                    p_result( "Root {0} incorrect".format(x) )
                    score -= 10
                else:
                    p_result( "Root {0} correct".format(x) )
        
        
        if not roots_only:
            if len(root_strs) != 2:
                score -= 30
            else:
                root_nums = []
                ind_score = 0
                for r in root_strs[0:1]:
                    (ipart,rpart,ind) = r
                    root_nums.extend( [ipart,rpart] )
                    if ind != 'i':
                        if ind_score == 0:
                            p_result( "Root not displayed with 'i'" )
                        ind_score += 5
                        score -= ind_score
                prec_score = 0
                for n in root_nums:
                    m = prec_regx.search( n )
                    if m != None and len(m.groups(1)) > prec:
                        prec_score += 5
                if prec_score == 0:
                    p_result( "precision correct" )
                else:
                    p_result( "too many digits of precision" )
                score -= prec_score
            div_match = divider_regx.search( out )
            if div_match == None:
                p_result( "no divider" )
                score -= 10
            elif div_match.group() != "*" * (prec*4):
                p_result( "divider length is {0}, should be {1}".format(
                        len(div_match.group()), prec*4 ) )
                score -= 5
            else:
                p_result( "divider OK" )
            #look for words in madlib:
            words_found = 0
            for w in words:
                if re.search( w, out ):
                    words_found += 1
            if words_found < len(words):
                p_result( "Mad-Lib only uses {0} words".format(words_found) )
                score -= (len(words) - words_found) * 5
            else:
                p_result( "Mad-Lib correct" )
        return ( float(score)/float(max_score), results )