#!/usr/bin/perl -w
# Last update: 04.01.2003 (Jacek.Kobus@phys.uni.torun.pl)

# This script prints a list of available tests of the x2dhf program
# and performs a selected test or performs all the tests. It can also
# be used to stops the running test.

# In order to enlarge a list of available test add an entry to the
# hash table %tests and a corresponding procedure (its name consists
# of run_ and a keyword of the entry)

#$tests{"Be"} = "-1";
#$tests{"BF_a"} = "-1";
#$tests{"BF_b"} = "-1";
#$tests{"BF_c"} = "-1";
#$tests{"BeF"} = "-1";
#$tests{"BO"} = "-1";
#$tests{"C"} = "-1";
#$tests{"Cplus"} = "-1";
#$tests{"C2"} = "-1";
#$tests{"F2"} = "-1";
#$tests{"H2"} = "-1";
#$tests{"FH_finite_field"} = "-1";
#$tests{"Li2"} = "-1";
#$tests{"N2"} = "-1";
#$tests{"Th89_1s"} = "-1";
#$tests{"Th89_2s"} = "-1";
$tests{"GaF"} = "-1";

$debug="no";
$bg="&";

$i=0;
print ("\n Choose a test to be performed: \n");
foreach $k (sort keys %tests) {
    $i++;
    $tests{$k}=$i;
    printf "%10.lu % s %s \n",$tests{$k}," - ", $k;
}
$tests{"stop"} = "0";

printf  " %s \n", "      all  -  perform all tests";
$zero=0;
printf  "\n%10s %s \n\n", $zero, " -  stop a running program";



print "  ? "; 


while(<>) {
    chop;

    if ( $_ eq "all" ) {
	$bg="";
	print ("\n\n Running all the tests in the foreground: \n\n");
	foreach $k (sort keys %tests) {
	    if ($k ne "stop") {
		$subname="run_" . $k . "()"; 
		print ($k,":\n");
		eval $subname;
		print ("\n\n");
	    };
	};
	exit;
    };

    if ( $_ eq "0" ) {
	print  ("   touch ./bin/stop_x2dhf \n");
	system ("   touch ./bin/stop_x2dhf \n");
	exit;
    };
    foreach $k (sort keys %tests) {
	if ($tests{$k} eq $_) {
	    $subname="run_" . $k . "()"; 
	    print ("Running the test in the background: \n");
	    eval $subname;
	    exit;
	};
    };
    print "  ? "; 
    next;
};

sub run_Be {
    print ("   cp ./examples/be/be.data ./bin/ \n");
    print ("   cd ./bin; ./xhf be be-1 > be-test.output  $bg \n\n");
    
    if ($debug eq "no") {
	system ("cp ./examples/be/be.data ./bin/");
	system ("cd ./bin; ./xhf be be-1 > be-test.output $bg ");
    };

    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/be/be.output and  ./bin/be-test.output \n");
};

sub run_BeF {
    print ("   cp ./examples/be/bef.data ./bin/ \n");
    print ("   cd ./bin; ./xhf bef bef-1 > bef-test.output  $bg \n\n");
    
    if ($debug eq "no") {
	system ("cp ./examples/bef/bef.data ./bin/");
	system ("cd ./bin; ./xhf bef bef-1 > bef-test.output $bg ");
    };
    
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/be/bef.output and  ./bin/bef-test.output \n");
};

sub run_BF_a {
    print ("   cp ./examples/bf/bf_g94.data ./bin/ \n");
    print ("   cp ./examples/bf/bf_g94.out ./bin/gauss94.out \n");
    print ("   cp ./examples/bf/bf_g94.pun ./bin/gauss94.pun \n");
    print ("   cd ./bin; ./xhf bf_g94 bf_g94-1 > bf_g94-test.output  $bg \n\n");
    
    if ($debug eq "no") {
	system ("cp ./examples/bf/bf_g94.data ./bin/ \n");
	system ("cp ./examples/bf/bf_g94.out ./bin/gauss94.out \n");
	system ("cp ./examples/bf/bf_g94.pun ./bin/gauss94.pun \n");
	system ("cd ./bin; ./xhf bf_g94 bf_g94-1 > bf_g94-test.output $bg \n");
    };
    
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/bf/bf_g94.output and  ./bin/bf_g94-test.output \n");
};

sub run_BF_b {
    print ("   cp ./examples/bf/bf_g94l.data ./bin/ \n");
    print ("   cp ./examples/bf/bf_g94la.out ./bin/gauss94l.out \n");
    print ("   cd ./bin; ./xhf bf_g94l bf_g94l-1 > bf_g94la-test.output  $bg \n\n");
    
    if ($debug eq "no") {
	system ("cp ./examples/bf/bf_g94l.data ./bin/ \n");
	system ("cp ./examples/bf/bf_g94la.out ./bin/gauss94l.out \n");
	system ("cd ./bin; ./xhf bf_g94l bf_g94l-1 > bf_g94la-test.output $bg  \n");
    };
    
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/bf/bf_g94la.output and  ./bin/bf_g94la-test.output \n");
};

sub run_BF_c {
    print ("   cp ./examples/bf/bf_g94l.data ./bin/ \n");
    print ("   cp ./examples/bf/bf_g94lb.out ./bin/gauss94l.out \n");
    print ("   cd ./bin; ./xhf bf_g94l bf_g94l-1 > bf_g94lb-test.output  $bg \n\n");
    
    if ($debug eq "no") {
	system ("cp ./examples/bf/bf_g94l.data ./bin/ \n");
	system ("cp ./examples/bf/bf_g94lb.out ./bin/gauss94l.out \n");
	system ("cd ./bin; ./xhf bf_g94l bf_g94l-1 > bf_g94lb-test.output $bg  \n");
    };

    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/bf/bf_g94lb.output and  ./bin/bf_g94lb-test.output \n");
};

sub run_BO {
    print ("   cp ./examples/bo/bo.data ./bin/ \n");
    print ("   cp ./examples/bo/bo.out ./bin/gauss94.out \n");
    print ("   cp ./examples/bo/bo.pun ./bin/gauss94.pun \n");
    print ("   cd ./bin; ./xhf bo bo-1 > bo-test.output  $bg \n\n");
    
    if ($debug eq "no") {
        system ("cp ./examples/bo/bo.data ./bin/ \n");
        system ("cp ./examples/bo/bo.out ./bin/gauss94.out \n");
        system ("cp ./examples/bo/bo.pun ./bin/gauss94.pun \n");
        system ("cd ./bin; ./xhf bo bo-1 > bo-test.output $bg  \n");
    };
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/bo/bo.output and  ./bin/bo-test.output \n");
};

sub run_C {
    print ("   cp ./examples/c/c.data ./bin/ \n");
    print ("   cd ./bin; ./xhf c c-1 > c-test.output  $bg \n\n");
    
    if ($debug eq "no") {
        system ("cp ./examples/c/c.data ./bin/ \n");
        system ("cd ./bin; ./xhf c c-1 > c-test.output $bg  \n");
    };
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/c/c.output and  ./bin/c-test.output \n");
};

sub run_Cplus {
    print ("   cp ./examples/c/cplus.data ./bin/ \n");
    print ("   cd ./bin; ./xhf cplus cplus-1 > cplus-test.output  $bg \n\n");
    
    if ($debug eq "no") {
	system ("cp ./examples/c/cplus.data ./bin/ \n");
        system ("cd ./bin; ./xhf cplus cplus-1 > cplus-test.output $bg  \n");
    };
      
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/c/cplus.output and  ./bin/cplus-test.output \n");
};

sub run_C2 {
    print ("   cp ./examples/c2/c2a.data ./bin/ \n");
    print ("   cd ./bin; ./xhf c2a c2a-1 > c2a-test.output  $bg \n\n");
    print ("   cp ./examples/c2/c2.out ./bin/gauss94.out \n");
    print ("   cp ./examples/c2/c2.pun ./bin/gauss94.pun \n");

    if ($debug eq "no") {
        system ("cp ./examples/c2/c2a.data ./bin/ \n");
        system ("cd ./bin; ./xhf c2a c2a-1 > c2a-test.output $bg  \n");
        system ("   cp ./examples/c2/c2.out ./bin/gauss94.out \n");
        system ("   cp ./examples/c2/c2.pun ./bin/gauss94.pun \n");
    };
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/c2/c2a.output and  ./bin/c2a-test.output \n");
    print ("and run the rest of the tests (see c2b.data and c2c.data) \n");
};

sub run_F2 {
    print ("   cp ./examples/f2/f2.data ./bin/ \n");
    print ("   cp ./examples/f2/f2.out ./bin/gauss94.out \n");
    print ("   cp ./examples/f2/f2.pun ./bin/gauss94.pun \n");
    print ("   cd ./bin; ./xhf f2 f2-1 > f2-test.output  $bg \n\n");
    
    if ($debug eq "no") {
	system ("cp ./examples/f2/f2.data ./bin/ \n");
        system ("cp ./examples/f2/f2.out ./bin/gauss94.out \n");
        system ("cp ./examples/f2/f2.pun ./bin/gauss94.pun \n");
        system ("cd ./bin; ./xhf f2 f2-1 > f2-test.output $bg  \n");
    };
    
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/f2/f2.output and  ./bin/f2-test.output \n");
};

sub run_H2 {
    print ("   cp ./examples/h2/h2.data ./bin/ \n");
    print ("   cd ./bin; ./xhf h2 h2-1 > h2-test.output  $bg \n\n");

    if ($debug eq "no") {
        system ("cp ./examples/h2/h2.data ./bin/ \n");
        system ("cd ./bin; ./xhf h2 h2-1 > h2-test.output $bg  \n");
    };
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/h2/h2.output and  ./bin/h2-test.output \n");
};

sub run_FH_finite_field {
    print ("   cp ./examples/hf/fh*.data ./bin/ \n");
    print ("   cp ./examples/fh/Run_FH ./bin/ \n");
    print ("   cp ./perl_scripts/fh/Run_elprop ./bin/ \n");
    print ("   cp ./perl_scripts/fh/elprop.pl ./bin/ \n");
    print ("   cd ./bin; ./Run_FH   $bg \n\n");

    if ($debug eq "no") {
        system ("   cp ./examples/fh/fh*.data ./bin/ \n");
        system ("   cp ./examples/fh/Run_FH ./bin/ \n");
        system ("   cp ./perl_scripts/fh/Run_elprop ./bin/ \n");
        system ("   cp ./perl_scripts/fh/elprop.pl ./bin/ \n");
        system ("   cd ./bin; ./Run_FH  $bg  \n");
    };

    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/fh/fh.output and  ./bin/fh-test.output \n");
};


sub run_GaF {
    print ("   cp ./examples/gaf/gaf.data ./bin/ \n");
    print ("   cd ./bin; ./xhf gaf gaf-1 > gaf-test.output  $bg \n\n");
    
    if ($debug eq "no") {
	system ("cp ./examples/gaf/gaf.data ./bin/ \n");
	system ("cd ./bin; ./xhf gaf gaf-1 > gaf-test.output $bg  \n");
    };
    
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/gaf/gaf.output and  ./bin/gaf-test.output \n");
};

sub run_Li2 {
    print ("   cp ./examples/li2/li2.data ./bin/ \n");
    print ("   cp ./examples/li2/li2.out ./bin/gauss94.out \n");
    print ("   cp ./examples/li2/li2.pun ./bin/gauss94.pun \n");
    print ("   cd ./bin; ./xhf li2 li2-1 > li2-test.output  $bg \n\n");

    if ($debug eq "no") {
	system ("cp ./examples/li2/li2.data ./bin/ \n");
	system ("cp ./examples/li2/li2.out ./bin/gauss94.out \n");
        system ("cp ./examples/li2/li2.pun ./bin/gauss94.pun \n");
        system ("cd ./bin; ./xhf li2 li2-1 > li2-test.output $bg  \n");
    };

    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/li2/li2.output and  ./bin/li2-test.output \n");
};

sub run_N2 {
    print ("   cp ./examples/n2/n2.data ./bin/ \n");
    print ("   cd ./bin; ./xhf n2 n2-1 > n2-test.output  $bg \n\n");
    
    if ($debug eq "no") {
        system ("cp ./examples/n2/n2.data ./bin/ \n");
        system ("cd ./bin; ./xhf n2 n2-1 > n2-test.output $bg  \n");
    };
      
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/n2/n2.output and  ./bin/n2-test.output \n");
};

sub run_Th89_1s {
    print ("   cp ./examples/th89/th89_1s.data ./bin/ \n");
    print ("   cd ./bin; ./xhf/th89_1s th89_1s th89_1s-1 > th89_1s-test.output  $bg \n\n");
    
    if ($debug eq "no") {
        system ("cp ./examples/th89/th89_1s.data ./bin/ \n");
        system ("cd ./bin; ./xhf th89_1s th89_1s-1 > th89_1s-test.output $bg  \n");
    };
    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/th89/th89_1s.output and  ./bin/th89_1s-test.output \n");
};

sub run_Th89_2s {
    print ("   cp ./examples/th89/th89_2s.data ./bin/ \n");
    print ("   cd ./bin; ./xhf th89_2s th89_2s-1 > th89_2s-test.output $bg \n\n");

    
    if ($debug eq "no") {
	system ("cp ./examples/th89/th89_2s.data ./bin/ \n");
        system ("cd ./bin; ./xhf th89_2s th89_1s-1 th89_2s > th89_2s-test.output $bg");
    };

    print ("   The test is underway. When it complets compare \n");
    print ("   ./examples/th89/th89_2s.output and  ./bin/th89_2s-test.output \n");
};



