[mathicgb] 220/393: Made MonoMonoid a template on options for what the representation stores and updated tests to test all those representations. Internally the new template parameters don't actually do anything yet.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:05 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.

commit 174d8b4836ca55fad12763278204350eb69de2b4
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Wed Apr 3 18:35:04 2013 +0200

    Made MonoMonoid a template on options for what the representation stores and updated tests to test all those representations. Internally the new template parameters don't actually do anything yet.
---
 build/vs12/mathicgb-test/mathicgb-test.vcxproj     |   1 +
 .../mathicgb-test/mathicgb-test.vcxproj.filters    |   3 +
 src/mathicgb/MonoMonoid.hpp                        |  50 +++-
 src/test/MonoMonoid.cpp                            | 326 ++++++++++-----------
 src/test/monoidPict.in                             |  29 ++
 src/test/monoidPict.seed                           |   9 +
 src/test/pict.in                                   |   2 +-
 7 files changed, 240 insertions(+), 180 deletions(-)

diff --git a/build/vs12/mathicgb-test/mathicgb-test.vcxproj b/build/vs12/mathicgb-test/mathicgb-test.vcxproj
index 3289285..16043a2 100755
--- a/build/vs12/mathicgb-test/mathicgb-test.vcxproj
+++ b/build/vs12/mathicgb-test/mathicgb-test.vcxproj
@@ -403,6 +403,7 @@
     <ClCompile Include="..\..\..\src\test\gtestInclude.cpp" />
     <ClCompile Include="..\..\..\src\test\ideals.cpp" />
     <ClCompile Include="..\..\..\src\test\mathicgb.cpp" />
+    <ClCompile Include="..\..\..\src\test\MonoMonoid.cpp" />
     <ClCompile Include="..\..\..\src\test\poly-test.cpp" />
     <ClCompile Include="..\..\..\src\test\PrimeField.cpp" />
     <ClCompile Include="..\..\..\src\test\QuadMatrixBuilder.cpp" />
diff --git a/build/vs12/mathicgb-test/mathicgb-test.vcxproj.filters b/build/vs12/mathicgb-test/mathicgb-test.vcxproj.filters
index d84330d..c4938ce 100755
--- a/build/vs12/mathicgb-test/mathicgb-test.vcxproj.filters
+++ b/build/vs12/mathicgb-test/mathicgb-test.vcxproj.filters
@@ -51,6 +51,9 @@
     <ClCompile Include="..\..\..\src\test\PrimeField.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\src\test\MonoMonoid.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\src\test\ideals.hpp">
diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index bee8dd4..fa5b501 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -12,11 +12,20 @@
 #include <mathic.h>
 
 /// Implements the monoid of (monic) monomials with integer
-/// non-negative exponents. T must be an unsigned integer type that is
+/// non-negative exponents. Exponent must be an unsigned integer type that is
 /// used to store each exponent of a monomial.
 ///
 /// TODO: support grading and comparison.
-template<class E>
+template<
+  class Exponent,
+  bool hasComponent = true,
+  bool storeHash = true,
+  bool storeOrder = true
+>
+class MonoMonoid;
+
+
+template<class E, bool HC, bool SH, bool SO>
 class MonoMonoid {
 public:
   static_assert(std::numeric_limits<E>::is_signed, "");
@@ -31,6 +40,20 @@ public:
   /// The type of each exponent of a monomial.
   typedef E Exponent;
 
+  /// Is true if the monomials come from a module.
+  static const bool hasComponent;
+
+  /// Is true if the hash value is stored rather than computed at each 
+  /// hash request. This imposes extra computation when updating a monomial,
+  /// but for most operations that overhead is much less than the time for
+  /// computing a hash value from scratch.
+  static const bool storeHash;
+
+  /// Is true if data to compare monomials is stored rather than computed
+  /// at each comparison. As storeHash, there is overhead for this, but it
+  /// is not much for most operations.
+  static const bool storeOrder;
+
   /// Type used to indicate the component of a module monomial. For example,
   /// the component of xe_3 is 3.
   typedef typename std::make_unsigned<E>::type Component;
@@ -543,7 +566,7 @@ public:
     //setOrderData(lcmAB);
     //setHash(lcmAB);
 
-    MATHICGB_ASSERT(debugValid(lcmAB));
+    //MATHICGB_ASSERT(debugValid(lcmAB));
   }
 
   /// Parses a monomial out of a string. Valid examples: 1 abc a2bc
@@ -973,7 +996,7 @@ private:
       rawPtr(mono)[orderIndexBegin()] += oldExponent - newExponent;
     else {
       MATHICGB_ASSERT(mGrading.size() == varCount());
-      rawPtr(mono)[orderIndexBegin()] +=
+      rawPtr(mono)[orderIndexBegin()] -=
         mGrading[var] * (oldExponent - newExponent);
     }
     MATHICGB_ASSERT(debugOrderValid(mono));
@@ -1103,8 +1126,8 @@ namespace MonoMonoidHelper {
   struct unchar<unsigned char> {typedef unsigned short type;};
 }
 
-template<class E>
-void MonoMonoid<E>::parseM2(std::istream& in, MonoRef mono) const {
+template<class E, bool HC, bool SH, bool SO>
+void MonoMonoid<E, HC, SH, SO>::parseM2(std::istream& in, MonoRef mono) const {
   using MonoMonoidHelper::unchar;
   // todo: signal error on exponent overflow
 
@@ -1141,7 +1164,7 @@ void MonoMonoid<E>::parseM2(std::istream& in, MonoRef mono) const {
     if (isdigit(in.peek())) {
       typename unchar<Exponent>::type e;
       in >> e;
-      exponent = e;
+      exponent = static_cast<Exponent>(e);
     } else
       exponent = 1;
     sawSome = true;
@@ -1155,7 +1178,7 @@ void MonoMonoid<E>::parseM2(std::istream& in, MonoRef mono) const {
     }
     typename unchar<Exponent>::type e;
     in >> e;
-    access(mono, componentIndex()) = e;
+    access(mono, componentIndex()) = static_cast<Exponent>(e);
     if (in.peek() != '>') {
       mathic::reportError("Component < was not matched by >.");
       return;
@@ -1168,8 +1191,11 @@ void MonoMonoid<E>::parseM2(std::istream& in, MonoRef mono) const {
   MATHICGB_ASSERT(debugValid(mono));
 }
 
-template<class E>
-void MonoMonoid<E>::printM2(ConstMonoRef mono, std::ostream& out) const {
+template<class E, bool HC, bool SH, bool SO>
+void MonoMonoid<E, HC, SH, SO>::printM2(
+  ConstMonoRef mono,
+  std::ostream& out
+) const {
   using MonoMonoidHelper::unchar;
   const auto letterCount = 'z' - 'a' + 1;
 
@@ -1179,9 +1205,9 @@ void MonoMonoid<E>::printM2(ConstMonoRef mono, std::ostream& out) const {
       continue;
     char letter;
     if (var < letterCount)
-      letter = 'a' + var;
+      letter = 'a' + static_cast<char>(var);
     else if (var < 2 * letterCount)
-      letter = 'A' + (var - letterCount);
+      letter = 'A' + (static_cast<char>(var) - letterCount);
     else {
       mathic::reportError("Too few letters in alphabet to print variable.");
       return;
diff --git a/src/test/MonoMonoid.cpp b/src/test/MonoMonoid.cpp
index 96051bb..b81bfb4 100755
--- a/src/test/MonoMonoid.cpp
+++ b/src/test/MonoMonoid.cpp
@@ -4,11 +4,32 @@
 #include <gtest/gtest.h>
 #include <sstream>
 
+
+// Do all-pairs testing -- see monoidPict.in. Especially see that file before
+// editing this list of types.
+typedef ::testing::Types<
+  MonoMonoid<int32,1,1,1>,
+  MonoMonoid<int32,0,1,1>,
+  MonoMonoid<int32,0,0,1>,
+  MonoMonoid<int32,0,0,0>,
+  MonoMonoid<int16,1,1,1>,
+  MonoMonoid<int16,0,1,1>,
+  MonoMonoid<int16,0,0,1>,
+  MonoMonoid<int16,0,0,0>,
+  MonoMonoid<int8,1,0,1>,
+  MonoMonoid<int8,0,1,0>,
+  MonoMonoid<int32,1,1,0>
+> MonoidTypes;
+
+template <typename T>
+class Monoid : public ::testing::Test {};
+TYPED_TEST_CASE(Monoid, MonoidTypes);
+
 // expect(i,j) encodes a matrix with interesting bit patterns that
 // are supposed to be likely to surface errors in how monomials are
 // stored inside a vector.
 uint32 expect(size_t mono, size_t var, size_t varCount) {
-  const auto unique = var + varCount * mono + 1;
+  const auto unique = (static_cast<uint32>(var + varCount * mono + 1) % 127);
 
   while (true) {
     // 000
@@ -57,18 +78,19 @@ uint32 expect(size_t mono, size_t var, size_t varCount) {
   }
 };
 
-TEST(MonoMonoid, VarCount) {
-  ASSERT_EQ(0, MonoMonoid<int8>(0).varCount());
-  ASSERT_EQ(1000 * 1000, MonoMonoid<int8>(1000 * 1000).varCount());
-  ASSERT_EQ(1, MonoMonoid<int16>(1).varCount());
-  ASSERT_EQ(2, MonoMonoid<int32>(2).varCount());
-  ASSERT_EQ(12, MonoMonoid<int64>(12).varCount());
+TYPED_TEST(Monoid, VarCount) {
+  typedef TypeParam Monoid;
+  ASSERT_EQ(0, Monoid(0).varCount());
+  ASSERT_EQ(1000 * 1000, Monoid(1000 * 1000).varCount());
+  ASSERT_EQ(1, Monoid(1).varCount());
+  ASSERT_EQ(2, Monoid(2).varCount());
+  ASSERT_EQ(12, Monoid(12).varCount());
 }
 
-TEST(MonoMonoid, MonoVector) {
-  typedef MonoMonoid<int32> Monoid;
-  typedef Monoid::VarIndex VarIndex;
-  typedef Monoid::MonoVector MonoVector;
+TYPED_TEST(Monoid, MonoVector) {
+  typedef TypeParam Monoid;
+  typedef typename Monoid::VarIndex VarIndex;
+  typedef typename Monoid::MonoVector MonoVector;
 
   Monoid monoid(13);
   MonoVector v(monoid);
@@ -108,8 +130,7 @@ TEST(MonoMonoid, MonoVector) {
   auto it = v.begin();
   ASSERT_EQ(it, v.cbegin());
   for (size_t i = 0; i < count; ++i, ++it) {
-    MonoVector::const_iterator tmp;
-    ASSERT_TRUE(it != tmp);
+    typename MonoVector::const_iterator tmp;
     tmp = it;
     ASSERT_EQ(tmp, it);
     ASSERT_TRUE(v.end() != it);
@@ -170,14 +191,14 @@ TEST(MonoMonoid, MonoVector) {
   ASSERT_TRUE(v.empty());
 }
 
-TEST(MonoMonoid, MonoPool) {
-  typedef MonoMonoid<int32> Monoid;
-  typedef Monoid::VarIndex VarIndex;
-  typedef Monoid::Mono Mono;
+TYPED_TEST(Monoid, MonoPool) {
+  typedef TypeParam Monoid;
+  typedef typename Monoid::VarIndex VarIndex;
+  typedef typename Monoid::Mono Mono;
 
   for (int q = 0; q < 2; ++q) {
     Monoid monoid(13);
-    Monoid::MonoPool pool(monoid);
+    typename Monoid::MonoPool pool(monoid);
     const auto varCount = monoid.varCount();
 
     const auto count = 1000;
@@ -243,86 +264,79 @@ namespace {
   }
 }
 
-namespace {
-  template<class E>
-  void parsePrintM2Helper() {
-    MonoMonoid<E> m(100);
-    const char* str = "1 a z A Z ab a2 a2b ab2 a20b30 1<1> a<2> a2<3> ab<11>\n";
-    auto v2 = parseVector(m, str);
-    std::ostringstream v2Out;
-    v2.printM2(v2Out);
-    ASSERT_EQ(str, v2Out.str());
-
-    decltype(v2) v(m);
-    v.push_back(); // 1
-
-    v.push_back(); // a
-    m.setExponent(0, 1, v.back());
+TYPED_TEST(Monoid, ParsePrintM2) {
+  typedef TypeParam Monoid;
+  Monoid m(100);
+  const char* str = "1 a z A Z ab a2 a2b ab2 a20b30 1<1> a<2> a2<3> ab<11>\n";
+  auto v2 = parseVector(m, str);
+  std::ostringstream v2Out;
+  v2.printM2(v2Out);
+  ASSERT_EQ(str, v2Out.str());
+
+  decltype(v2) v(m);
+  v.push_back(); // 1
+
+  v.push_back(); // a
+  m.setExponent(0, 1, v.back());
  
-    v.push_back(); // z
-    m.setExponent(25, 1, v.back());
+  v.push_back(); // z
+  m.setExponent(25, 1, v.back());
 
-    v.push_back(); // A
-    m.setExponent(26, 1, v.back());
+  v.push_back(); // A
+  m.setExponent(26, 1, v.back());
 
-    v.push_back(); // Z
-    m.setExponent(51, 1, v.back());
+  v.push_back(); // Z
+  m.setExponent(51, 1, v.back());
 
-    v.push_back(); // ab
-    m.setExponent(0, 1, v.back());
-    m.setExponent(1, 1, v.back());
+  v.push_back(); // ab
+  m.setExponent(0, 1, v.back());
+  m.setExponent(1, 1, v.back());
 
-    v.push_back(); // a2
-    m.setExponent(0, 2, v.back());
+  v.push_back(); // a2
+  m.setExponent(0, 2, v.back());
 
-    v.push_back(); // a2b
-    m.setExponent(0, 2, v.back());
-    m.setExponent(1, 1, v.back());
+  v.push_back(); // a2b
+  m.setExponent(0, 2, v.back());
+  m.setExponent(1, 1, v.back());
 
-    v.push_back(); // ab2
-    m.setExponent(0, 1, v.back());
-    m.setExponent(1, 2, v.back());
+  v.push_back(); // ab2
+  m.setExponent(0, 1, v.back());
+  m.setExponent(1, 2, v.back());
 
-    v.push_back(); // a20b30
-    m.setExponent(0, 20, v.back());
-    m.setExponent(1, 30, v.back());
+  v.push_back(); // a20b30
+  m.setExponent(0, 20, v.back());
+  m.setExponent(1, 30, v.back());
 
-    v.push_back(); // 1<1>
-    m.setComponent(1, v.back());
+  v.push_back(); // 1<1>
+  m.setComponent(1, v.back());
 
-    v.push_back(); // a<2>
-    m.setComponent(2, v.back());
-    m.setExponent(0, 1, v.back());
+  v.push_back(); // a<2>
+  m.setComponent(2, v.back());
+  m.setExponent(0, 1, v.back());
 
-    v.push_back(); // a2<3>
-    m.setComponent(3, v.back());
-    m.setExponent(0, 2, v.back());
+  v.push_back(); // a2<3>
+  m.setComponent(3, v.back());
+  m.setExponent(0, 2, v.back());
 
-    v.push_back(); // ab<11>
-    m.setComponent(11, v.back());
-    m.setExponent(0, 1, v.back());
-    m.setExponent(1, 1, v.back());
+  v.push_back(); // ab<11>
+  m.setComponent(11, v.back());
+  m.setExponent(0, 1, v.back());
+  m.setExponent(1, 1, v.back());
 
-    std::ostringstream vOut;
-    v.printM2(vOut);
-    ASSERT_EQ(str, vOut.str());
+  std::ostringstream vOut;
+  v.printM2(vOut);
+  ASSERT_EQ(str, vOut.str());
   
-    ASSERT_EQ(v, v2);
-  }
+  ASSERT_EQ(v, v2);
 }
 
-TEST(MonoMonoid, ParsePrintM2) {
-  parsePrintM2Helper<int32>();
-  parsePrintM2Helper<int16>();
-  parsePrintM2Helper<int8>();
-}
 
-TEST(MonoMonoid, MultiplyDivide) {
-  typedef MonoMonoid<int32> Monoid;
+TYPED_TEST(Monoid, MultiplyDivide) {
+  typedef TypeParam Monoid;
   Monoid m(49);
-  Monoid::MonoPool pool(m);
+  typename Monoid::MonoPool pool(m);
   auto mono = pool.alloc();
-  auto check = [&](const char* str) {
+  auto check = [&](const char* str) -> void {
     auto v = parseVector(m, str);
     MATHICGB_ASSERT(v.size() == 3);
     const auto& a = v.front();
@@ -427,13 +441,13 @@ TEST(MonoMonoid, MultiplyDivide) {
   check("abcdefghiV<7> ab2c3d4e5f6g7h8i9V11 a2b3c4d5e6f7g8h9i10V12<7>");
 }
 
-TEST(MonoMonoid, LcmColon) {
-  typedef MonoMonoid<int32> Monoid;
+TYPED_TEST(Monoid, LcmColon) {
+  typedef TypeParam Monoid;
   Monoid m(49);
-  Monoid::MonoPool pool(m);
+  typename Monoid::MonoPool pool(m);
   auto mono = pool.alloc();
   auto mono2 = pool.alloc();
-  auto check = [&](const char* str) {
+  auto check = [&](const char* str) -> void {
     auto v = parseVector(m, str);
     MATHICGB_ASSERT(v.size() == 3);
     const auto& a = v.front();
@@ -485,8 +499,8 @@ TEST(MonoMonoid, LcmColon) {
   check("a6b7c8d9efghiV ab2c3d4e5f6g7h8i9V11 a6b7c8d9e5f6g7h8i9V11");
 }
 
-TEST(MonoMonoid, Order) {
-  typedef MonoMonoid<int32> Monoid;
+TYPED_TEST(Monoid, Order) {
+  typedef TypeParam Monoid;
   Monoid m(52);
   auto v = parseVector(m, "1 Z A z c b a c2 bc ac b2 ab a2 c3 abc b3 a3");
 
@@ -505,13 +519,13 @@ TEST(MonoMonoid, Order) {
   }
 }
 
-TEST(MonoMonoid, RelativelyPrime) {
-  typedef MonoMonoid<int32> Monoid;
+TYPED_TEST(Monoid, RelativelyPrime) {
+  typedef TypeParam Monoid;
   Monoid m(49);
-  Monoid::MonoPool pool(m);
+  typename Monoid::MonoPool pool(m);
   auto mono = pool.alloc();
   auto mono2 = pool.alloc();
-  auto check = [&](const char* str, bool relativelyPrime) {
+  auto check = [&](const char* str, bool relativelyPrime) -> void {
     auto v = parseVector(m, str);
     MATHICGB_ASSERT(v.size() == 2);
     ASSERT_EQ(relativelyPrime, m.relativelyPrime(v.front(), v.back()));
@@ -526,89 +540,67 @@ TEST(MonoMonoid, RelativelyPrime) {
   check("fgh abcdef", false);
 }
 
-TEST(MonoMonoid, SetExponents) {
-  typedef MonoMonoid<int32> Monoid;
+TYPED_TEST(Monoid, SetExponents) {
+  typedef TypeParam Monoid;
   Monoid m(5);
   auto v = parseVector(m, "a1b2c3d4e5");
-  int32 exponents[] = {1, 2, 3, 4, 5};
+  typename Monoid::Exponent exponents[] = {1, 2, 3, 4, 5};
   v.push_back();
   m.setExponents(exponents, v.back());
   ASSERT_TRUE(m.equal(v.front(), v.back()));  
 }
 
-TEST(MonoMonoid, HasAmpleCapacity) {
-  // non-total-degree grading, last char is c
-  std::vector<int8> v8;
-  v8.push_back(1);
-  v8.push_back(10);
-  v8.push_back(1);
-  MonoMonoid<int8> m8(v8);
-
-  // total degree grading, last char is d.
-  MonoMonoid<int16> m16(4);
-
-  // non-total-degree grading, last char is e
-  std::vector<int32> v32;
-  v32.push_back(1);
-  v32.push_back(10);
-  v32.push_back(1);
-  v32.push_back(1);
-  v32.push_back(1);
-  MonoMonoid<int32> m32(v32);
-
-  // total degree grading, last char is n
-  MonoMonoid<int32> m32t(14);
-
-
-  // pure power, first variable
-  auto f8 = parseVector(m8, "a63 a64");
-  ASSERT_TRUE(m8.hasAmpleCapacity(f8.front()));
-  ASSERT_FALSE(m8.hasAmpleCapacity(f8.back()));
-
-  auto f16 = parseVector(m16, "a16383 a16384");
-  ASSERT_TRUE(m16.hasAmpleCapacity(f16.front()));
-  ASSERT_FALSE(m16.hasAmpleCapacity(f16.back()));
-
-  auto f32 = parseVector(m32, "a1073741823 a1073741824");
-  ASSERT_TRUE(m32.hasAmpleCapacity(f32.front()));
-  ASSERT_FALSE(m32.hasAmpleCapacity(f32.back()));
-
-  auto f32t = parseVector(m32t, "a1073741823 a1073741824");
-  ASSERT_TRUE(m32.hasAmpleCapacity(f32t.front()));
-  ASSERT_FALSE(m32.hasAmpleCapacity(f32t.back()));
-
-  // pure power, last variable
-  auto l8 = parseVector(m8, "c63 c64");
-  ASSERT_TRUE(m8.hasAmpleCapacity(l8.front()));
-  ASSERT_FALSE(m8.hasAmpleCapacity(l8.back()));
-
-  auto l16 = parseVector(m16, "d16383 d16384");
-  ASSERT_TRUE(m16.hasAmpleCapacity(l16.front()));
-  ASSERT_FALSE(m16.hasAmpleCapacity(l16.back()));
-
-  auto l32 = parseVector(m32, "e1073741823 e1073741824");
-  ASSERT_TRUE(m32.hasAmpleCapacity(l32.front()));
-  ASSERT_FALSE(m32.hasAmpleCapacity(l32.back()));
-
-  auto l32t = parseVector(m32t, "n1073741823 n1073741824");
-  ASSERT_TRUE(m32t.hasAmpleCapacity(l32t.front()));
-  ASSERT_FALSE(m32t.hasAmpleCapacity(l32t.back()));
-
-  // no exponent is too high but the degree is
-  auto d8 = parseVector(m8, "abc52 abc53");
-  ASSERT_TRUE(m8.hasAmpleCapacity(d8.front()));
-  ASSERT_FALSE(m8.hasAmpleCapacity(d8.back()));
-
-  auto d16 = parseVector(m16, "abcd16380 abcd16381");
-  ASSERT_TRUE(m16.hasAmpleCapacity(d16.front()));
-  ASSERT_FALSE(m16.hasAmpleCapacity(d16.back()));
-
-  auto d32 = parseVector(m32, "abcde1073741810 abcde1073741811");
-  ASSERT_TRUE(m32.hasAmpleCapacity(d32.front()));
-  ASSERT_FALSE(m32.hasAmpleCapacity(d32.back()));
-
-  auto d32t = parseVector
-    (m32t, "abcdefghijklmn1073741810 abcdefghijklmn1073741811");
-  ASSERT_TRUE(m32t.hasAmpleCapacity(d32t.front()));
-  ASSERT_FALSE(m32t.hasAmpleCapacity(d32t.back()));
+TYPED_TEST(Monoid, HasAmpleCapacityTotalDegree) {
+  typedef TypeParam Monoid;
+  typedef typename Monoid::Exponent Exponent;
+  typedef typename Monoid::VarIndex VarIndex;
+
+  for (VarIndex varCount = 1; varCount < 33; ++varCount) {
+    Monoid monoidTotalDegree(varCount);
+    std::vector<Exponent> v(varCount, 1);
+    Monoid monoidTotalDegreeImplicit(v);
+    v[0] = 7;
+    Monoid monoidGeneral(v);
+
+    Monoid* monoids[] = {
+      &monoidTotalDegree,
+      &monoidTotalDegreeImplicit,
+      &monoidGeneral
+    };
+    for (int j = 0; j < 3; ++j) {
+      auto& m = *monoids[j];
+      const auto firstDeg = (j == 2 ? v[0] : 1);
+      ASSERT_EQ(varCount, m.varCount());
+
+      typename Monoid::MonoPool p(m);
+      auto mono = p.alloc();
+      const auto last = m.varCount() - 1;
+      const auto max = std::numeric_limits<Exponent>::max() / 2;
+
+      // pure power, first variable
+      m.setIdentity(mono);
+      m.setExponent(0, max / firstDeg, mono);
+      ASSERT_TRUE(m.hasAmpleCapacity(mono));
+      m.setExponent(0, max / firstDeg + 1, mono);
+      ASSERT_FALSE(m.hasAmpleCapacity(mono));
+
+      if (varCount == 1)
+        continue;
+
+      // pure power, last variable
+      m.setIdentity(mono);
+      m.setExponent(last, max, mono);
+      ASSERT_TRUE(m.hasAmpleCapacity(mono));
+      m.setExponent(last, max + 1, mono);
+      ASSERT_FALSE(m.hasAmpleCapacity(mono));
+
+      // no exponent is too high but the degree is
+      m.setIdentity(mono);
+      m.setExponent(0, 12, mono);
+      m.setExponent(last, max - 12 * firstDeg, mono);
+      ASSERT_TRUE(m.hasAmpleCapacity(mono));
+      m.setExponent(0, 13, mono);
+      ASSERT_FALSE(m.hasAmpleCapacity(mono));
+    }
+  }
 }
diff --git a/src/test/monoidPict.in b/src/test/monoidPict.in
new file mode 100755
index 0000000..200ee7f
--- /dev/null
+++ b/src/test/monoidPict.in
@@ -0,0 +1,29 @@
+# See pict.in for what pict files do.
+# This file is for getting a good set of test instantiations of MonoMonoid.
+# See the test file MonoMonoid.cpp.
+#
+# To generate a set of test configurations, do
+#
+#   pict monoidPict.in /e:monoidPict.seed > monoidPict.out
+#
+# Then reformat the output and put it into MonoMonoid.cpp as the set
+# of PolyRing configurations to use.
+
+##############################################################
+# This is the PICT model specifying all parameters and their values
+#
+Exponent: int8, int16, int32
+HasComponent: 0,1
+StoreHash: 0,1
+StoreOrder: 0,1
+
+##############################################################
+# PICT submodels go here.
+#
+
+# we are not currently using PICT submodels
+
+##############################################################
+# This is the set of PICT constraints that rule out some combinations
+# of parameter values.
+#
diff --git a/src/test/monoidPict.seed b/src/test/monoidPict.seed
new file mode 100755
index 0000000..44aa83c
--- /dev/null
+++ b/src/test/monoidPict.seed
@@ -0,0 +1,9 @@
+Exponent	HasComponent	StoreHash	StoreOrder
+int32	1	1	1
+int32	0	1	1
+int32	0	0	1
+int32	0	0	0
+int16	1	1	1
+int16	0	1	1
+int16	0	0	1
+int16	0	0	0
diff --git a/src/test/pict.in b/src/test/pict.in
index 5b29f99..0557a0b 100755
--- a/src/test/pict.in
+++ b/src/test/pict.in
@@ -14,7 +14,7 @@
 #
 # To update the test in gb-test.cpp, do
 #
-#   pick pict.in > pict.out
+#   pict pict.in > pict.out
 #
 # Then place the entire contents of pict.out (including newlines) into
 # the string allPairsTest in gb-test.cpp.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git



More information about the debian-science-commits mailing list