#!/usr/bin/perl -w

# ATTENTION: test.part3 has been changed to COPY linked files instead of LINKING them

use strict;
use POSIX; # for floor

my $debug = 0;

my $CLASS  = "223";
my $HWK    = "4";
my $NAME   = "Blotto";        # Name of program
my $UNIT   = "Unit";
my $TEST   = "tIJ";           # Name of test file (IJ is replaced by number)
my $ANSWER = "tIJ.out";          # Name of answer file (IJ is replaced by number)
my $DATE   = "10/25/2019";        # Date script written
my $LANG   = "C";             # Language (C, Perl, ...)

# Blank-separated list of illegal files; wildcards permitted
my $hwkFiles = "";

my $PROGRAM = "./$NAME";        # Name of executable
my $UNIT_PROGRAM = "./$UNIT";

my %WHICH;                      # Allow individual tests on command line
@WHICH{@ARGV}++
   if (@ARGV);

$SIG{HUP} = $SIG{INT} = $SIG{QUIT}
   = $SIG{TERM} = \&cleanup;
my @UNLINK;                                     # Files to delete on signal
my $TMPDIR = "/tmp/TEST.$NAME.$$";              # Name of temporary directory
sub cleanup {
   unlink (@UNLINK);                            # Delete files
   if (-e $TMPDIR) {                            # Delete temporary directory
      system ("/bin/chmod -R +w $TMPDIR");
      system ("/bin/rm -rf $TMPDIR");
   }
   exit;
}

my $WallClock = 0;

$0 =~ s{^.*/}{};                                # Extract test type
my $TYPE = ($0 =~ m{^test\.}) ? "Public" : "Final";
print "\n$TYPE test script for $NAME ($DATE)\n\n";

my @SOURCE = ();
my @LINK = ();

&makeProgram
   unless ($LANG eq "Perl");

&limitCpuTime (60, 120);                         # Limit CPU-time per process
&limitWallClock (120);                          # Limit wall-clock per process
&limitFileSize (100000);                        # Limit size of files created
#&limitHeapSize (1000000);                       # Limit size of heap
&limitProcesses (1000);                         # Limit #processes

$|++;
print "\nEach test is either passed or failed; there is no partial credit.\n\n"
    . "To execute the test labelled IJ, type the command:\n"
    . "     /c/cs$CLASS/hw${HWK}/Tests/$TEST\n"
    . " or "
    . "     $PROGRAM < /c/cs$CLASS/hw${HWK}/Tests/$TEST\n"
    . "The answer expected is in /c/cs$CLASS/hw${HWK}/Tests/$ANSWER.\n\n";

my $total = 0;
my $subtotal = 0;
