Frobby 0.9.5
LibTest.cpp
Go to the documentation of this file.
1/* Frobby: Software for monomial ideal computations.
2 Copyright (C) 2009 Bjarke Hammersholt Roune (www.broune.com)
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see http://www.gnu.org/licenses/.
16*/
17#include "stdinc.h"
18#include "LibTest.h"
19
20#include "tests.h"
21
22#include <algorithm>
23
24TEST_SUITE(LibraryInterface)
25
27 size_t varCount = ideal.getVarCount();
28
29 Frobby::Ideal libIdeal(varCount);
30 for (size_t generator = 0; generator < ideal.getGeneratorCount(); ++generator) {
31 if (varCount == 0)
32 libIdeal.addExponent(0);
33 else
34 for (size_t var = 0; var < varCount; ++var)
35 libIdeal.addExponent(ideal[generator][var].get_mpz_t());
36 }
37
38 return libIdeal;
39}
40
41const mpz_t* castLibArray(const vector<mpz_class>& vect) {
42 // The following cast depends on knowing that mpz_class just
43 // consists of a single mpz_t, so (nearly) assert that that is true.
44 ASSERT(sizeof(mpz_class) == sizeof(mpz_t));
45 return reinterpret_cast<const mpz_t*>(&(vect[0]));
46}
47
49 _hasAnyOutput(false),
50 _ideal(names) {
51}
52
53void LibIdealConsumer::idealBegin(size_t varCount) {
54 ASSERT(varCount == _ideal.getVarCount());
55
56 _ideal.clear();
57 _hasAnyOutput = true;
58}
59
60void LibIdealConsumer::consume(mpz_ptr* exponentVector) {
62 for (size_t var = 0; var < _ideal.getVarCount(); ++var)
63 _ideal.getLastTermRef()[var] = mpz_class(exponentVector[var]);
64}
65
68 return _ideal;
69}
70
72 return _hasAnyOutput;
73}
74
75
77 _names(names) {
78}
79
80void LibIdealsConsumer::idealBegin(size_t varCount) {
81 ASSERT(_names.getVarCount() == varCount);
82 _ideals.push_back(BigIdeal(_names));
83}
84
85void LibIdealsConsumer::consume(mpz_ptr* exponentVector) {
86 _ideals.back().newLastTerm();
87 for (size_t var = 0; var < _names.getVarCount(); ++var)
88 _ideals.back().getLastTermRef()[var] = mpz_class(exponentVector[var]);
89}
90
91const vector<BigIdeal>& LibIdealsConsumer::getIdeals() const {
92 for (size_t i = 0; i < _ideals.size(); ++i)
93 _ideals[i].sortGenerators();
94 sort(_ideals.begin(), _ideals.end());
95 return _ideals;
96}
97
99 _polynomial(names) {
100}
101
103 ASSERT(varCount == _polynomial.getVarCount());
104}
105
106void LibPolynomialConsumer::consume(const mpz_t coef, mpz_ptr* exponentVector) {
108 _polynomial.getLastCoef() = mpz_class(coef);
109 for (size_t var = 0; var < _polynomial.getVarCount(); ++var)
110 _polynomial.getLastTerm()[var] = mpz_class(exponentVector[var]);
111}
112
const mpz_t * castLibArray(const vector< mpz_class > &vect)
Returns a pointer to an array of mpt_t that represents the entries in the mpz_class.
Definition LibTest.cpp:41
Frobby::Ideal toLibIdeal(const BigIdeal &ideal)
Returns a library interface ideal that corresponds to the parameter ideal.
Definition LibTest.cpp:26
void sortGenerators()
Definition BigIdeal.cpp:280
void newLastTerm()
Definition BigIdeal.cpp:104
size_t getVarCount() const
Definition BigIdeal.h:148
void clear()
Definition BigIdeal.cpp:218
vector< mpz_class > & getLastTermRef()
Definition BigIdeal.h:133
mpz_class & getLastCoef()
size_t getVarCount() const
vector< mpz_class > & getLastTerm()
void sortTermsReverseLex()
void addExponent(const mpz_t exponent)
Call addExponent once for each variable to add a term one exponent at a time.
Definition frobby.cpp:221
Represents a monomial ideal with int exponents.
Definition Ideal.h:27
const BigIdeal & getIdeal() const
Returns the recorded ideal in a canonical form.
Definition LibTest.cpp:66
virtual void consume(mpz_ptr *exponentVector)
For output of a generator of the ideal.
Definition LibTest.cpp:60
virtual void idealBegin(size_t varCount)
Called before output of a monomial ideal.
Definition LibTest.cpp:53
bool _hasAnyOutput
Definition LibTest.h:53
LibIdealConsumer(const VarNames &names)
Definition LibTest.cpp:48
BigIdeal _ideal
Definition LibTest.h:54
bool hasAnyOutput() const
Returns whether any ideal has been recorded.
Definition LibTest.cpp:71
VarNames _names
Definition LibTest.h:70
virtual void consume(mpz_ptr *exponentVector)
For output of a generator of the ideal.
Definition LibTest.cpp:85
LibIdealsConsumer(const VarNames &names)
Definition LibTest.cpp:76
virtual void idealBegin(size_t varCount)
Called before output of a monomial ideal.
Definition LibTest.cpp:80
const vector< BigIdeal > & getIdeals() const
Returns the recorded ideals in a canonical form.
Definition LibTest.cpp:91
vector< BigIdeal > _ideals
Definition LibTest.h:69
const BigPolynomial & getPolynomial() const
Returns the recorded polynomial in a canonical form.
Definition LibTest.cpp:113
virtual void polynomialBegin(size_t varCount)
Called before output of a polynomial.
Definition LibTest.cpp:102
virtual void consume(const mpz_t coef, mpz_ptr *exponentVector)
For output of a term of the polynomial.
Definition LibTest.cpp:106
BigPolynomial _polynomial
Definition LibTest.h:85
LibPolynomialConsumer(const VarNames &names)
Definition LibTest.cpp:98
Defines the variables of a polynomial ring and facilities IO involving them.
Definition VarNames.h:40
size_t getVarCount() const
Returns the current number of variables.
Definition VarNames.h:113
#define TEST_SUITE(SUITE)
Definition macroes.h:26
The namespace Frobby contains the public interface of Frobby.
Definition frobby.h:36
This header file includes common definitions and is included as the first line of code in every imple...
#define ASSERT(X)
Definition stdinc.h:86