<commit_before>/* linbox/tests/test-field.h
 * Copyright (C) 2001, 2002 <NAME>
 *
 * ========LICENCE========
 * This file is part of the library LinBox.
 *
 * LinBox is free software: you can redistribute it and/or modify
 * it under the terms of the  GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * ========LICENCE========
 *.
 *
 * Extracted by bds from test-generic.h, written by <NAME> <<EMAIL>>
 */

/*! @file tests/test-field.h
 * @ingroup tests
 * @brief tests field operations
 * @test  tests field operations
 */

/*
// top level test that doesn't use field_subtests.
bool testField

// top level test that uses subtest testRandomIteratorStep.
bool testRandomIterator

// top level runBasicRingTests calls these field_subtests.
bool testFieldNegation
bool testFieldDistributivity
bool testFieldAssociativity
bool testFieldCharacteristic
bool testGeometricSummation
bool testRingArithmeticConsistency
bool testAxpyConsistency
bool testRanditerBasic

// top level runFieldTests calls these field_subtests after runBasicRingTests.
bool testFieldInversion
bool testFieldCommutativity
bool testInvDivConsistency
bool testFreshmansDream
bool testRingTrivia

*/

#ifndef __LINBOX_test_field_H
#define __LINBOX_test_field_H

#include <iostream>
//#include <fstream>
#include <sstream>
#include <vector>
#include <cstdio>

#include "linbox/util/commentator.h"
#include "linbox/util/field-axpy.h"
#include "linbox/randiter/nonzero.h"
//#include "linbox/vector/stream.h"
#include "linbox/integer.h"
// #include "linbox/field/givaro.h"

#include "test-common.h"

/* Modular exponentiation */
using namespace std;

// LinBox::Commentator commentator(std::cout);

using LinBox::commentator ;


template <class Field>
typename Field::Element& expt (const Field &F, typename Field::Element &res, const typename Field::Element &a, LinBox::integer &n)
{
	if (n == 0) {
		F.init (res, 1);
	}
	else if (n == 1) {
		F.assign (res, a);
	}
	else if (Givaro::isOdd(n)) {
		n -= 1;
		expt (F, res, a, n);
		F.mulin (res, a);
	}
	else {
		n /= 2;
		expt (F, res, a, n);
		typename Field::Element tmp;
		F.init(tmp,0);
		res = F.mul (tmp, res, res);
	}

	return res;
}

bool reportError(string rep, bool& flag)
{
	ostream &report = std::cout; //commentator().report (LinBox::Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR);
	report << "ERROR: " << rep << endl;
	return flag = false;
}


/** Check each field or ring operation.
 *
 * Test various field operations
 *
 * F - Field over which to perform computations
 * title - String to use as the descriptive title of this test
 * fieldp - use true if inv and div must work for all nonzero denominators
 *
 * Return true on success and false on failure
 */

template<class Field>
bool testField (Field &F, const char *title, bool fieldp = true)
{
	commentator().start (title, "testField", 5);
	// ostream &report = std::cout ;
	ostream &report = commentator().report (LinBox::Commentator::LEVEL_UNIMPORTANT, INTERNAL_DESCRIPTION);
<commit_msg>Minor change<commit_after>/* linbox/tests/test-field.h
 * Copyright (C) 2001, 2002 <NAME>
 *
 * ========LICENCE========
 * This file is part of the library LinBox.
 *
 * LinBox is free software: you can redistribute it and/or modify
 * it under the terms of the  GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * ========LICENCE========
 *.
 *
 * Extracted by bds from test-generic.h, written by <NAME> <<EMAIL>>
 */

/*! @file tests/test-field.h
 * @ingroup tests
 * @brief tests field operations
 * @test  tests field operations
 */

/*
// top level test that doesn't use field_subtests.
bool testField

// top level test that uses subtest testRandomIteratorStep.
bool testRandomIterator

// top level runBasicRingTests calls these field_subtests.
bool testFieldNegation
bool testFieldDistributivity
bool testFieldAssociativity
bool testFieldCharacteristic
bool testGeometricSummation
bool testRingArithmeticConsistency
bool testAxpyConsistency
bool testRanditerBasic

// top level runFieldTests calls these field_subtests after runBasicRingTests.
bool testFieldInversion
bool testFieldCommutativity
bool testInvDivConsistency
bool testFreshmansDream
bool testRingTrivia

*/

#ifndef __LINBOX_test_field_H
#define __LINBOX_test_field_H

#include <iostream>
//#include <fstream>
#include <sstream>
#include <vector>
#include <cstdio>

#include "linbox/util/commentator.h"
#include "linbox/util/field-axpy.h"
#include "linbox/randiter/nonzero.h"
//#include "linbox/vector/stream.h"
#include "linbox/integer.h"
// #include "linbox/field/givaro.h"

#include "test-common.h"

/* Modular exponentiation */
using namespace std;

// LinBox::Commentator commentator(std::cout);

using LinBox::commentator ;


template <class Field>
typename Field::Element& expt (const Field &F, typename Field::Element &res, const typename Field::Element &a, LinBox::integer &n)
{
	if (n == 0) {
		F.init (res, 1);
	}
	else if (n == 1) {
		F.assign (res, a);
	}
	else if (Givaro::isOdd(n)) {
		n -= 1;
		expt (F, res, a, n);
		F.mulin (res, a);
	}
	else {
		n /= 2;
		expt (F, res, a, n);
		typename Field::Element tmp;
		F.init(tmp,0);
		res = F.mul (tmp, res, res);
	}

	return res;
}

bool reportError(string rep, bool& flag)
{
	ostream &report = commentator().report (LinBox::Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR);
	report << "ERROR: " << rep << endl;
	return flag = false;
}


/** Check each field or ring operation.
 *
 * Test various field operations
 *
 * F - Field over which to perform computations
 * title - String to use as the descriptive title of this test
 * fieldp - use true if inv and div must work for all nonzero denominators
 *
 * Return true on success and false on failure
 */

template<class Field>
bool testField (Field &F, const char *title, bool fieldp = true)
{
	commentator().start (title, "testField", 5);
	// ostream &report = std::cout ;
	ostream &report = commentator().report (LinBox::Commentator::LEVEL_UNIMPORTANT, INTERNAL_DESCRIPTION);

{'fraction_non_alphanumeric': 0.111938202247191, 'fraction_numerical': 0.007865168539325843, 'mean_word_length': 4.3581640331076, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3276012', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2196, 'n_words': 804}