Added a test

This commit is contained in:
Harry Moffat
2009-03-25 00:17:06 +00:00
parent b60613c166
commit 47cc9986d4
5 changed files with 800 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
Makefile
csvCode.txt
diff_test.out
output.txt
outputa.txt
pUtest
redirect.txt

View File

@@ -0,0 +1,122 @@
#!/bin/sh
############################################################################
#
# Makefile to compile and link a C++ application to
# Cantera.
#
#############################################################################
# addition to suffixes
.SUFFIXES : .d
# the name of the executable program to be created
PROG_NAME = pUtest
# the object files to be linked together. List those generated from Fortran
# and from C/C++ separately
OBJS = pUtest.o
# additional flags to be passed to the linker. If your program
# requires other external libraries, put them here
LINK_OPTIONS = @EXTRA_LINK@
#############################################################################
# Check to see whether we are in the msvc++ environment
os_is_win = @OS_IS_WIN@
# Fortran libraries
ifeq (@build_with_f2c@, 0)
FORT_LIBS = @FLIBS@
else
FORT_LIBS =
endif
# the C++ compiler
CXX = @CXX@
# C++ compile flags
CXX_FLAGS = @CXXFLAGS@
# Ending C++ linking libraries
LCXX_END_LIBS = @LCXX_END_LIBS@
# the directory where the Cantera libraries are located
CANTERA_LIBDIR=@buildlib@
# required Cantera libraries
CANTERA_LIBS = @LOCAL_LIBS@ -lctcxx
# Cantera library Dependencies
CANTERA_LIB_DEPS = @LOCAL_LIBS_DEP@
ifeq (@build_lapack@, 1)
CANTERA_LAPACK_DEPS = $(CANTERA_LIBDIR)/libctblas.a \
$(CANTERA_LIBDIR)/libctlapack.a
endif
# the directory where Cantera include files may be found.
CANTERA_INCDIR=@ctroot@/build/include/cantera
# flags passed to the C++ compiler/linker for the linking step
LCXX_FLAGS = -L$(CANTERA_LIBDIR) @LOCAL_LIB_DIRS@ @CXXFLAGS@
# How to compile C++ source files to object files
.@CXX_EXT@.@OBJ_EXT@: Interface.h
$(CXX) -c $< -I$(CANTERA_INCDIR) @CXX_INCLUDES@ $(CXX_FLAGS)
# How to compile the dependency file
.cpp.d:
@CXX_DEPENDS@ -I$(CANTERA_INCDIR) $(CXX_FLAGS) $*.cpp > $*.d
# List of dependency files to be created
DEPENDS=$(OBJS:.o=.d)
# Program Name
PROGRAM = $(PROG_NAME)$(EXE_EXT)
# all rule makes a single program
all: $(PROGRAM)
# Rule to make the program
$(PROGRAM): $(OBJS) $(CANTERA_LIB_DEPS) $(CANTERA_LAPACK_DEPS)
$(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(LINK_OPTIONS) \
$(CANTERA_LIBS) @LIBS@ $(FORT_LIBS) \
$(LCXX_END_LIBS)
# Add an additional target for stability:
$(OBJS): $(CANTERA_LIBDIR)/libctbase.a $(CANTERA_LIBDIR)/libthermo.a
# depends target
depends:
$(RM) *.d .depends
@MAKE@ .depends
.depends: $(DEPENDS)
cat *.d > .depends
# Do the test -> For the windows vc++ environment, we have to skip checking on
# whether the program is uptodate, because we don't utilize make
# in that environment to build programs.
test:
ifeq ($(os_is_win), 1)
else
@ @MAKE@ -s $(PROGRAM)
endif
@ ./runtest
# clean target -> clean up
clean:
$(RM) $(OBJS) $(PROGRAM) $(DEPENDS) .depends
../../bin/rm_cvsignore
(if test -d SunWS_cache ; then \
$(RM) -rf SunWS_cache ; \
fi )
ifeq ($(wildcard .depends), .depends)
include .depends
endif

View File

@@ -0,0 +1,71 @@
good: dg = 1.2000000000000e-01 eq 0.12
error dg = -1.0400000000000e+15 ne -1.03e+15
good: dg = 1.0345000000000e-270 eq 1.0345e-270
good: dg = 1.0300000000000e-15 eq 1.03e-15
good: dg = 1.0345000000000e-15 eq 1.0345e-15
good: dg = 1.0000000000000e-15 eq 1e-15
good: dg = -1.0000000000000e-15 eq -1e-15
good: dg = -1.0300000000000e-15 eq -1.03e-15
good: dg = -1.0345000000000e-15 eq -1.0345e-15
good: dg = -1.0345000000000e-15 eq -1.0345e-15
good: dg = 1.0345000000000e+15 eq 1.0345e+15
good: dg = -1.0345000000000e+15 eq -1.0345e+15
good: dg = -1.0000000000000e+15 eq -1e+15
good: dg = -1.0000000000000e-02 eq -0.01
good: dg = 1.2000000000000e+00 eq 1.2
good: dg = 1.2000000000000e+01 eq 12
error dg = 1.0000000000000e+00 ne 0.99
good: dg = 1.1200000000000e+00 eq 1.12
good: dg = 1.0000000000000e-15 eq 1e-15
good: dg = 1.1000000000000e-15 eq 1.1e-15
good: dg = 0.0000000000000e+00 eq 0
good: dg = 1.1200000000000e+08 eq 1.12e+08
1.1000E-14 -- should be 1.1000E-14
1.0000E-14 -- should be 1.0000E-14
" 0.0000E+00" -- should be " 0.0000E+00"
" 1.1235E-14" -- should be 1.1235E-14
" 1.12E-14" -- should be " 1.12E-14"
"1.12E-14" -- should be "1.12E-14"
1.12E-04 -- should be 1.12E-14
1.1E-109 -- should be 1.1E-109
1.123E-19 -- should be 1.123E-19
-1.100E-19 -- should be -1.00E-19
-1.1000E-19 -- should be -1.1000E-19
-1.13E-19 -- should be -1.13E-19
-1.130E-19 -- should be -1.130E-19
"-1.130E-19" -- should be "-1.130E-19"
good: dg = 1.2000000000000e-01 eq 0.12
error dg = -1.0400000000000e+15 ne -1.03e+15
good: dg = 1.0345000000000e-270 eq 1.0345e-270
good: dg = 1.0300000000000e-15 eq 1.03e-15
good: dg = 1.0345000000000e-15 eq 1.0345e-15
good: dg = 1.0000000000000e-15 eq 1e-15
good: dg = -1.0000000000000e-15 eq -1e-15
good: dg = -1.0300000000000e-15 eq -1.03e-15
good: dg = -1.0345000000000e-15 eq -1.0345e-15
good: dg = -1.0345000000000e-15 eq -1.0345e-15
good: dg = 1.0345000000000e+15 eq 1.0345e+15
good: dg = -1.0345000000000e+15 eq -1.0345e+15
good: dg = -1.0000000000000e+15 eq -1e+15
good: dg = -1.0000000000000e-02 eq -0.01
good: dg = 1.2000000000000e+00 eq 1.2
good: dg = 1.2000000000000e+01 eq 12
error dg = 1.0000000000000e+00 ne 0.99
good: dg = 1.1200000000000e+00 eq 1.12
good: dg = 1.0000000000000e-15 eq 1e-15
good: dg = 1.1000000000000e-15 eq 1.1e-15
good: dg = 0.0000000000000e+00 eq 0
good: dg = 1.1200000000000e+08 eq 1.12e+08
1.1000E-14 -- should be 1.1000E-14
1.0000E-14 -- should be 1.0000E-14
" 0.0000E+00" -- should be " 0.0000E+00"
" 1.1235E-14" -- should be 1.1235E-14
" 1.12E-14" -- should be " 1.12E-14"
"1.12E-14" -- should be "1.12E-14"
1.12E-04 -- should be 1.12E-14
1.1E-109 -- should be 1.1E-109
1.123E-19 -- should be 1.123E-19
-1.100E-19 -- should be -1.00E-19
-1.1000E-19 -- should be -1.1000E-19
-1.13E-19 -- should be -1.13E-19
-1.130E-19 -- should be -1.130E-19

View File

@@ -0,0 +1,566 @@
/*
* $Id$
*/
#include <iostream>
#include <fstream>
#include <cmath>
#include <sstream>
#include "Cantera.h"
#include "kernel/PrintCtrl.h"
#include "kernel/LogPrintCtrl.h"
using namespace Cantera;
using namespace std;
bool dnequl(const double a, const double b, int isig) {
double atol = fabs(a) + fabs(b);
double asig = pow(10.0, -isig);
if (asig > 1.0E-6) {
asig = 1.0E-6;
}
double c = fabs(a - b);
if (c > atol * asig) {
return true;
}
return false;
}
void doCheck(const double a, const double b, int isig) {
if (dnequl(a, b, isig)) {
printf("error dg = %20.13e ne %g \n", a, b);
} else {
printf("good: dg = %20.13e eq %g \n", a, b);
}
}
void doLogger() {
LogPrintCtrl ppc;
ostream ffs(cout.rdbuf());
double d, dg;
int nsig, p, w, wMax, wMin;
int Ncrop10;
d = 0.12345;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 0.12, nsig);
d = -1.0375E15;
nsig = 3;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.03E15, nsig);
d = 1.0345E-270;
nsig = 5;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.0345E-270, nsig);
d = 1.0345E-15;
nsig = 3;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.03E-15, nsig);
d = 1.0345E-15;
nsig = 5;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.0345E-15, nsig);
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.0E-15, nsig);
d = -1.0345E-15;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0E-15, nsig);
d = -1.0345E-15;
nsig = 3;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.03E-15, nsig);
d = -1.0345E-15;
nsig = 5;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0345E-15, nsig);
d = -1.0345E-15;
nsig = 7;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0345E-15, nsig);
d = 1.0345E15;
nsig = 7;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.0345E15, nsig);
d = -1.0345E15;
nsig = 7;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0345E15, nsig);
d = -1.0305E15;
nsig = 1;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0E15, nsig);
d = -10.E-3;
nsig = 4;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -10E-3, nsig);
d = 1.2345;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.2, nsig);
d = 12.345;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 12., nsig);
d = 0.9999;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 0.99, nsig);
d = 1.1234;
nsig = 3;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.12, nsig);
Ncrop10 = -15;
d = 1.1234E-15;
dg = ppc.cropAbs10(d, Ncrop10);
doCheck(dg, 1.0E-15, nsig);
Ncrop10 = -16;
d = 1.1234E-15;
dg = ppc.cropAbs10(d, Ncrop10);
doCheck(dg, 1.1E-15, nsig);
Ncrop10 = -14;
d = 1.1234E-15;
dg = ppc.cropAbs10(d, Ncrop10);
doCheck(dg, 0.0, nsig);
Ncrop10 = 6;
d = 1.1234E8;
dg = ppc.cropAbs10(d, Ncrop10);
doCheck(dg, 1.12E8, nsig);
ppc.setNdec(-15);
d = 1.1234E-14;
p = 5;
w = 20;
ppc.pr_de_c10(d, p, w);
ffs << " -- should be 1.1000E-14" << endl;
ppc.setNdec(-14);
d = 1.1234E-14;
p = 5;
w = 20;
ppc.pr_de_c10(d, p, w);
ffs << " -- should be 1.0000E-14" << endl;
ppc.setNdec(-13);
d = 1.1234E-14;
p = 5;
wMin = 20;
ffs << "\"";
ppc.pr_de_c10(d, p, wMin);
ffs << "\" -- should be \" 0.0000E+00\" " << endl;
ppc.setNdec(-20);
d = 1.1234567E-14;
p = 5;
w = 20;
ffs << "\"";
ppc.pr_de_c10(d, p, w);
ffs << "\" -- should be 1.1235E-14" << endl;
ppc.setNdec(-20);
d = 1.1234567E-14;
p = 3;
w = 17;
ffs << "\"";
ppc.pr_de_c10(d, p, w);
ffs << "\" -- should be \" 1.12E-14\"" << endl;
ppc.setNdec(-20);
d = 1.1234567E-14;
p = 5;
wMin = 3;
wMax = 8;
ffs << "\"";
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << "\" -- should be \"1.12E-14\" " << endl;
ppc.setNdec(-20);
d = 1.1234567E-4;
p = 5;
wMin = 3;
wMax = 8;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be 1.12E-14 " << endl;
ppc.setNdec(-120);
d = 1.1234567E-109;
p = 5;
wMin = 3;
wMax = 8;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be 1.1E-109 " << endl;
ppc.setNdec(-120);
d = 1.1234567E-19;
p = 5;
wMin = 3;
wMax = 9;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be 1.123E-19 " << endl;
ppc.setNdec(-20);
d = -1.1234567E-19;
p = 5;
wMin = 3;
wMax = 10;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be -1.00E-19 " << endl;
ppc.setNdec(-20);
d = -1.1234567E-19;
p = 5;
wMin = 3;
wMax = 11;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be -1.1000E-19 " << endl;
ppc.setNdec(-25);
d = -1.1274567E-19;
p = 3;
wMin = 3;
wMax = 10;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be -1.13E-19 " << endl;
ppc.setNdec(-25);
d = -1.127401E-19;
double dd = ppc.cropSigDigits(d, 3);
p = 4;
wMin = 3;
wMax = 10;
ppc.pr_de_c10(dd, p, wMin, wMax);
ffs << " -- should be -1.130E-19 " << endl;
return;
}
int main() {
// How to connect to a file:
// ofstream fff("redirect.txt");
// ostream ffs(fff.rdbuf());
// How to connect to a string:
// std::ostringstream os;
// ostream ffss(os.rdbuf());
ostream ffs(cout.rdbuf());
PrintCtrl ppc(ffs);
double d, dg;
int nsig, p, w, wMax, wMin;
int Ncrop10;
d = 0.12345;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 0.12, nsig);
d = -1.0375E15;
nsig = 3;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.03E15, nsig);
d = 1.0345E-270;
nsig = 5;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.0345E-270, nsig);
d = 1.0345E-15;
nsig = 3;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.03E-15, nsig);
d = 1.0345E-15;
nsig = 5;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.0345E-15, nsig);
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.0E-15, nsig);
d = -1.0345E-15;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0E-15, nsig);
d = -1.0345E-15;
nsig = 3;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.03E-15, nsig);
d = -1.0345E-15;
nsig = 5;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0345E-15, nsig);
d = -1.0345E-15;
nsig = 7;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0345E-15, nsig);
d = 1.0345E15;
nsig = 7;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.0345E15, nsig);
d = -1.0345E15;
nsig = 7;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0345E15, nsig);
d = -1.0305E15;
nsig = 1;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -1.0E15, nsig);
d = -10.E-3;
nsig = 4;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, -10E-3, nsig);
d = 1.2345;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.2, nsig);
d = 12.345;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 12., nsig);
d = 0.9999;
nsig = 2;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 0.99, nsig);
d = 1.1234;
nsig = 3;
dg = ppc.cropSigDigits(d, nsig);
doCheck(dg, 1.12, nsig);
Ncrop10 = -15;
d = 1.1234E-15;
dg = ppc.cropAbs10(d, Ncrop10);
doCheck(dg, 1.0E-15, nsig);
Ncrop10 = -16;
d = 1.1234E-15;
dg = ppc.cropAbs10(d, Ncrop10);
doCheck(dg, 1.1E-15, nsig);
Ncrop10 = -14;
d = 1.1234E-15;
dg = ppc.cropAbs10(d, Ncrop10);
doCheck(dg, 0.0, nsig);
Ncrop10 = 6;
d = 1.1234E8;
dg = ppc.cropAbs10(d, Ncrop10);
doCheck(dg, 1.12E8, nsig);
ppc.setNdec(-15);
d = 1.1234E-14;
p = 5;
w = 20;
ppc.pr_de_c10(d, p, w);
ffs << " -- should be 1.1000E-14" << endl;
ppc.setNdec(-14);
d = 1.1234E-14;
p = 5;
w = 20;
ppc.pr_de_c10(d, p, w);
ffs << " -- should be 1.0000E-14" << endl;
ppc.setNdec(-13);
d = 1.1234E-14;
p = 5;
wMin = 20;
ffs << "\"";
ppc.pr_de_c10(d, p, wMin);
ffs << "\" -- should be \" 0.0000E+00\" " << endl;
ppc.setNdec(-20);
d = 1.1234567E-14;
p = 5;
w = 20;
ffs << "\"";
ppc.pr_de_c10(d, p, w);
ffs << "\" -- should be 1.1235E-14" << endl;
ppc.setNdec(-20);
d = 1.1234567E-14;
p = 3;
w = 17;
ffs << "\"";
ppc.pr_de_c10(d, p, w);
ffs << "\" -- should be \" 1.12E-14\"" << endl;
ppc.setNdec(-20);
d = 1.1234567E-14;
p = 5;
wMin = 3;
wMax = 8;
ffs << "\"";
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << "\" -- should be \"1.12E-14\" " << endl;
ppc.setNdec(-20);
d = 1.1234567E-4;
p = 5;
wMin = 3;
wMax = 8;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be 1.12E-14 " << endl;
ppc.setNdec(-120);
d = 1.1234567E-109;
p = 5;
wMin = 3;
wMax = 8;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be 1.1E-109 " << endl;
ppc.setNdec(-120);
d = 1.1234567E-19;
p = 5;
wMin = 3;
wMax = 9;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be 1.123E-19 " << endl;
ppc.setNdec(-20);
d = -1.1234567E-19;
p = 5;
wMin = 3;
wMax = 10;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be -1.00E-19 " << endl;
ppc.setNdec(-20);
d = -1.1234567E-19;
p = 5;
wMin = 3;
wMax = 11;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be -1.1000E-19 " << endl;
ppc.setNdec(-25);
d = -1.1274567E-19;
p = 3;
wMin = 3;
wMax = 10;
ppc.pr_de_c10(d, p, wMin, wMax);
ffs << " -- should be -1.13E-19 " << endl;
ppc.setNdec(-25);
d = -1.127401E-19;
double dd = ppc.cropSigDigits(d, 3);
p = 4;
wMin = 3;
wMax = 10;
ppc.pr_de_c10(dd, p, wMin, wMax);
ffs << " -- should be -1.130E-19 " << endl;
// Example of attaching to a stringstream and then outputting
// from the string.
std::ostringstream os;
ostream ffss(os.rdbuf());
PrintCtrl ppss(ffss);
ppss.setNdec(-25);
d = -1.127401E-19;
dd = ppss.cropSigDigits(d, 3);
p = 4;
wMin = 3;
wMax = 10;
ppss.pr_de_c10(dd, p, wMin, wMax);
ffs << "\"";
ffs << os.str();
ffs << "\" -- should be \"-1.130E-19\" " << endl;
doLogger();
}

View File

@@ -0,0 +1,34 @@
#!/bin/sh
#
#
temp_success="1"
/bin/rm -f output.txt outputa.txt
tname="printUtilUnitTest"
#################################################################
#
#################################################################
CANTERA_DATA=${CANTERA_DATA:=../../data/inputs}; export CANTERA_DATA
CANTERA_BIN=${CANTERA_BIN:=../../bin}
./pUtest > output.txt
retnStat=$?
if [ $retnStat != "0" ]
then
temp_success="0"
echo "$tname ($tname test) returned with bad status, $retnStat, check output"
fi
../../bin/exp3to2.sh output.txt > outputa.txt
diff -w outputa.txt output_blessed.txt > diff_test.out
retnStat=$?
if [ $retnStat = "0" ]
then
echo "successful diff comparison on $tname test"
else
echo "unsuccessful diff comparison on $tname test"
echo "FAILED" > csvCode.txt
temp_success="0"
fi