Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / make-grade
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my (@rubric) = read_text_file (shift);
7 my (@pass) = @ARGV;
8
9 my (@grade);
10
11 our ($possible_overall, $score_overall) = (0, 0);
12 our ($possible, $score) = (0, 0);
13 for my $i (0...$#rubric) {
14     local ($_) = $rubric[$i];
15     if (/^\S/ || /^\s*$/) {
16         end_section ();
17         push (@grade, $_);
18     } elsif (my ($value, $name, $desc) = /^\s+(\d+)\s+(\S+):\s+(.*)$/) {
19         $possible += $value;
20         my ($marker);
21         if (grep ($_ eq $name, @pass)) {
22             $score += $value;
23             $marker = ' ';
24         } else {
25             $marker = '-';
26             }
27         push (@grade, "  $marker$value $name: $desc");
28     } else {
29         die;
30     }
31 }
32 end_section ();
33
34 push (@grade, "", "TESTING TOTAL: $score_overall of $possible_overall points");
35
36 print map ("$_\n", @grade);
37
38 sub end_section {
39     return if !$possible;
40     push (@grade, "Subtotal: $score of $possible points");
41     $possible_overall += $possible;
42     $score_overall += $score;
43     $possible = $score = 0;
44 }
45
46 sub read_text_file {
47     my ($file_name) = @_;
48     open (FILE, '<', $file_name) or die "$file_name: open: $!\n";
49     my (@content) = <FILE>;
50     chomp (@content);
51     close (FILE);
52     return @content;
53 }