Permalink
Browse files

moved unit tests to tests/unit

  • Loading branch information...
evaleev committed Jul 3, 2018
1 parent 563163e commit d6c891fc6750daa6604fb41b96f6c9b26d7ac932
View
@@ -7,7 +7,7 @@ endif
-include $(TOPDIR)/src/lib/MakeVars
SUBDIRS = src
CHECKSUBDIRS = tests/eri tests/hartree-fock
CHECKSUBDIRS = tests/eri tests/unit tests/hartree-fock
CLEANSUBDIRS = $(SUBDIRS) $(CHECKSUBDIRS)
ALLSUBDIRS = $(CLEANSUBDIRS) doc $(CHECKSUBDIRS)
View
@@ -3,7 +3,6 @@ ifndef SRCDIR
SRCDIR=$(shell pwd)
endif
-include $(TOPDIR)/tests/MakeVars
-include $(TOPDIR)/src/lib/libint/MakeVars.features
# include headers the object include directory
CPPFLAGS += -I$(TOPDIR)/include
@@ -15,8 +14,6 @@ CPPFLAGS += -I$(SRCDIR)/$(TOPDIR)/src/bin/test_eri
CPPFLAGS += -I$(SRCDIR)/$(TOPDIR)/src/lib/libint
# include processed headers from the compiler directory
CPPFLAGS += -I$(TOPDIR)/src/bin/libint
# include the data directory path as a definition
CPPFLAGS += -DSRCDATADIR=\"$(SRCDIR)/$(TOPDIR)/lib/basis\"
COMPILER_LIB = $(TOPDIR)/src/bin/libint/libINT.a
COMPUTE_LIB = -lint2
@@ -27,88 +24,50 @@ DEPSUF = d
CXXDEPENDSUF = none
CXXDEPENDFLAGS = -M
TEST1 = test
CXXTEST1SRC = $(TEST1).cc
CXXTEST1OBJ = $(CXXTEST1SRC:%.cc=%.$(OBJSUF))
CXXTEST1DEP = $(CXXTEST1SRC:%.cc=%.$(DEPSUF))
TEST = test
CXXTESTSRC = $(TEST).cc
CXXTESTOBJ = $(CXXTESTSRC:%.cc=%.$(OBJSUF))
CXXTESTDEP = $(CXXTESTSRC:%.cc=%.$(DEPSUF))
TEST2 = test++
CXXTEST2SRC = $(TEST2).cc $(TEST2)-core.cc
CXXTEST2OBJ = $(CXXTEST2SRC:%.cc=%.$(OBJSUF))
CXXTEST2DEP = $(CXXTEST2SRC:%.cc=%.$(DEPSUF))
check:: check1 check2
check1:: $(TEST1)
./$(TEST1) 0 3 && ./$(TEST1) 1 2 && ./$(TEST1) 2 1
check:: $(TEST)
./$(TEST) 0 3 && ./$(TEST) 1 2 && ./$(TEST) 2 1
ifeq ($(CXX_COMPATIBLE_WITH_CXXGEN),yes)
$(TEST1): $(CXXTEST1OBJ) $(COMPILER_LIB) $(COMPUTE_LIB)
$(TEST): $(CXXTESTOBJ) $(COMPILER_LIB) $(COMPUTE_LIB)
$(LD) -o $@ $(LDFLAGS) $^ $(SYSLIBS)
else
$(TEST1):
$(TEST):
echo "Cannot test generated code! $(CXXGEN) is not compatible with $(CXXCOMP)"
@exit 0
endif
check2::
ifeq ($(CXXGEN_SUPPORTS_CPP11),yes)
ifeq ($(LIBINT_SUPPORTS_ONEBODY),yes)
ifeq ($(LIBINT_SUPPORTS_ERI),yes)
ifeq ($(LIBINT_HAS_EIGEN),yes)
ifeq ($(LIBINT_CONTRACTED_INTS),yes)
ifeq ($(LIBINT_SHELL_SET),1)
$(TEST2): $(CXXTEST2OBJ) $(COMPUTE_LIB)
$(CXX) -o $@ $(LDFLAGS) $^ $(SYSLIBS)
check2:: $(TEST2)
./$^
endif
endif
endif
endif
endif
endif
# Source files for timer and tester are to be compiled using CXXGEN
$(TEST1): CXX=$(CXXGEN)
$(TEST1): CXXFLAGS=$(CXXGENFLAGS)
$(TEST1): LD=$(CXXGEN)
$(TEST): CXX=$(CXXGEN)
$(TEST): CXXFLAGS=$(CXXGENFLAGS)
$(TEST): LD=$(CXXGEN)
clean::
-rm -rf $(TEST1) $(TEST2) *.o *.d
-rm -rf $(TEST) *.o *.d
distclean:: realclean
realclean:: clean
targetclean:: clean
depend:: $(CXXTEST1DEP) $(CXXTEST2DEP)
$(TOPDIR)/include/libint2/boost/preprocessor.hpp: $(SRCDIR)/$(TOPDIR)/external/boost.tar.gz
gunzip -c $(SRCDIR)/$(TOPDIR)/external/boost.tar.gz | tar -xf - -C $(TOPDIR)/include/libint2
depend:: $(CXXTEST1DEP) $(CXXTEST2DEP)
depend:: $(CXXTESTDEP)
ifneq ($(DODEPEND),no)
ifneq ($(CXXDEPENDSUF),none)
%.d:: %.cc $(TOPDIR)/include/libint2/boost/preprocessor.hpp
%.d: %.cc
$(CXXDEPEND) $(CXXDEPENDFLAGS) -c $(CPPFLAGS) $(CXXFLAGS) $< > /dev/null
sed 's/^$*.o/$*.$(OBJSUF) $*.d/g' < $(*F).$(CXXDEPENDSUF) > $(@F)
/bin/rm -f $(*F).$(CXXDEPENDSUF)
else
%.d:: %.cc $(TOPDIR)/include/libint2/boost/preprocessor.hpp
%.d: %.cc
$(CXXDEPEND) $(CXXDEPENDFLAGS) -c $(CPPFLAGS) $(CXXFLAGS) $< | sed 's/^$*.o/$*.$(OBJSUF) $*.d/g' > $(@F)
endif
-include $(CXXTEST1DEP)
-include $(CXXTEST2DEP)
else
%.cc:: $(TOPDIR)/include/libint2/boost/preprocessor.hpp
-include $(CXXTESTDEP)
endif
View
@@ -0,0 +1,90 @@
TOPDIR=../..
ifndef SRCDIR
SRCDIR=$(shell pwd)
endif
-include $(TOPDIR)/tests/MakeVars
-include $(TOPDIR)/src/lib/libint/MakeVars.features
# include headers the object include directory
CPPFLAGS += -I$(TOPDIR)/include
# include headers from the library directory
CPPFLAGS += -I$(SRCDIR)/$(TOPDIR)/src/lib/libint
# include the data directory path as a definition
CPPFLAGS += -DSRCDATADIR=\"$(SRCDIR)/$(TOPDIR)/lib/basis\"
COMPILER_LIB = $(TOPDIR)/src/bin/libint/libINT.a
COMPUTE_LIB = -lint2
vpath %.a $(TOPDIR)/lib:$(TOPDIR)/lib/.libs
OBJSUF = o
DEPSUF = d
CXXDEPENDSUF = none
CXXDEPENDFLAGS = -M
TEST1 = test
CXXTEST1SRC = $(TEST1).cc $(TEST1)-core.cc $(TEST1)-permute.cc
CXXTEST1OBJ = $(CXXTEST1SRC:%.cc=%.$(OBJSUF))
CXXTEST1DEP = $(CXXTEST1SRC:%.cc=%.$(DEPSUF))
check:: check2
check2::
ifeq ($(CXXGEN_SUPPORTS_CPP11),yes)
ifeq ($(LIBINT_SUPPORTS_ONEBODY),yes)
ifeq ($(LIBINT_SUPPORTS_ERI),yes)
ifeq ($(LIBINT_HAS_EIGEN),yes)
ifeq ($(LIBINT_CONTRACTED_INTS),yes)
ifeq ($(LIBINT_SHELL_SET),1)
$(TEST1): $(CXXTEST1OBJ) $(COMPUTE_LIB)
$(CXX) -o $@ $(LDFLAGS) $^ $(SYSLIBS)
check2:: $(TEST1)
./$^
endif
endif
endif
endif
endif
endif
# Source files for timer and tester are to be compiled using CXXGEN
$(TEST1): CXX=$(CXXGEN)
$(TEST1): CXXFLAGS=$(CXXGENFLAGS)
$(TEST1): LD=$(CXXGEN)
clean::
-rm -rf $(TEST1) *.o *.d
distclean:: realclean
realclean:: clean
targetclean:: clean
depend:: $(CXXTEST1DEP)
$(TOPDIR)/include/libint2/boost/preprocessor.hpp: $(SRCDIR)/$(TOPDIR)/external/boost.tar.gz
gunzip -c $(SRCDIR)/$(TOPDIR)/external/boost.tar.gz | tar -xf - -C $(TOPDIR)/include/libint2
depend:: $(CXXTEST1DEP)
ifneq ($(DODEPEND),no)
ifneq ($(CXXDEPENDSUF),none)
%.d:: %.cc $(TOPDIR)/include/libint2/boost/preprocessor.hpp
$(CXXDEPEND) $(CXXDEPENDFLAGS) -c $(CPPFLAGS) $(CXXFLAGS) $< > /dev/null
sed 's/^$*.o/$*.$(OBJSUF) $*.d/g' < $(*F).$(CXXDEPENDSUF) > $(@F)
/bin/rm -f $(*F).$(CXXDEPENDSUF)
else
%.d:: %.cc $(TOPDIR)/include/libint2/boost/preprocessor.hpp
$(CXXDEPEND) $(CXXDEPENDFLAGS) -c $(CPPFLAGS) $(CXXFLAGS) $< | sed 's/^$*.o/$*.$(OBJSUF) $*.d/g' > $(@F)
endif
-include $(CXXTEST1DEP)
else
%.cc:: $(TOPDIR)/include/libint2/boost/preprocessor.hpp
endif
File renamed without changes.
View
@@ -0,0 +1,32 @@
//
// Created by Eduard Valeyev on 7/3/18.
//
#ifndef LIBINT_FIXTURE_H
#define LIBINT_FIXTURE_H
#include <libint2.hpp>
using std::cout;
using std::cerr;
using std::endl;
using libint2::Atom;
using libint2::BasisSet;
using libint2::Shell;
using libint2::Engine;
using libint2::Operator;
using libint2::BraKet;
using libint2::CartesianShellNormalization;
namespace libint2 {
namespace unit {
static auto atoms = std::vector<Atom>{ {8, 0.,0.,0.}, {8, 0.,0.,2.}, {1, 0.,-1.,-1.}, {1, 0.,1.,3.}};
static auto obs = BasisSet("6-31g**", atoms);
static auto dfbs = BasisSet("aug-cc-pvdz", atoms);
}
}
#endif //LIBINT_FIXTURE_H
View
@@ -0,0 +1,63 @@
#include "catch.hpp"
#include "fixture.h"
TEST_CASE("Engine ctor", "[engine]") {
REQUIRE_NOTHROW(Engine{});
auto a = Engine{};
}
TEST_CASE("Engine::set", "[engine]") {
REQUIRE_THROWS_AS(Engine{}.set(Operator::overlap), Engine::using_default_initialized);
REQUIRE_THROWS_AS(Engine{}.set(BraKet::x_x), Engine::using_default_initialized);
REQUIRE_NOTHROW(Engine{}.set(CartesianShellNormalization::uniform));
REQUIRE_NOTHROW(Engine(Operator::overlap, 1, 0).set(CartesianShellNormalization::uniform).set_precision(1e-20).set(Operator::overlap).set(BraKet::x_x));
}
TEST_CASE("cartesian uniform normalization", "[engine]") {
if (!LIBINT2_SUPPORT_ONEBODY || LIBINT_CGSHELL_ORDERING != LIBINT_CGSHELL_ORDERING_STANDARD)
return;
const auto lmax = std::min(3,LIBINT2_MAX_AM_overlap);
auto engine = Engine(Operator::overlap, 1, lmax);
std::vector<Shell> obs{Shell{{1.0}, {{2, false, {1.0}}}, {{0.0, 0.0, 0.0}}},
Shell{{1.0}, {{3, false, {1.0}}}, {{0.0, 0.0, 0.0}}}};
engine.compute(obs[0], obs[0]);
REQUIRE(engine.results()[0][0] == Approx(1.));
REQUIRE(engine.results()[0][7] == Approx(1./3));
REQUIRE(engine.results()[0][14] == Approx(1./3));
REQUIRE(engine.results()[0][21] == Approx(1.));
REQUIRE(engine.results()[0][28] == Approx(1./3));
REQUIRE(engine.results()[0][35] == Approx(1.));
engine.set(CartesianShellNormalization::uniform).compute(obs[0], obs[0]);
REQUIRE(engine.results()[0][0] == Approx(1.));
REQUIRE(engine.results()[0][7] == Approx(1.));
REQUIRE(engine.results()[0][14] == Approx(1.));
REQUIRE(engine.results()[0][21] == Approx(1.));
REQUIRE(engine.results()[0][28] == Approx(1.));
REQUIRE(engine.results()[0][35] == Approx(1.));
if (lmax >= 3) {
engine.set(CartesianShellNormalization::standard).compute(obs[1], obs[1]);
REQUIRE(engine.results()[0][0] == Approx(1.));
REQUIRE(engine.results()[0][11] == Approx(1./5));
REQUIRE(engine.results()[0][22] == Approx(1./5));
REQUIRE(engine.results()[0][33] == Approx(1./5));
REQUIRE(engine.results()[0][44] == Approx(1./15));
REQUIRE(engine.results()[0][55] == Approx(1./5));
REQUIRE(engine.results()[0][66] == Approx(1.));
REQUIRE(engine.results()[0][77] == Approx(1./5));
REQUIRE(engine.results()[0][88] == Approx(1./5));
REQUIRE(engine.results()[0][99] == Approx(1.));
engine.set(CartesianShellNormalization::uniform).compute(obs[1], obs[1]);
REQUIRE(engine.results()[0][0] == Approx(1.));
REQUIRE(engine.results()[0][11] == Approx(1.));
REQUIRE(engine.results()[0][22] == Approx(1.));
REQUIRE(engine.results()[0][33] == Approx(1.));
REQUIRE(engine.results()[0][44] == Approx(1.));
REQUIRE(engine.results()[0][55] == Approx(1.));
REQUIRE(engine.results()[0][66] == Approx(1.));
REQUIRE(engine.results()[0][77] == Approx(1.));
REQUIRE(engine.results()[0][88] == Approx(1.));
REQUIRE(engine.results()[0][99] == Approx(1.));
}
}
Oops, something went wrong.

0 comments on commit d6c891f

Please sign in to comment.