1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/***
* Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
*
* Copyright (C) 2020 by the authors listed in the AUTHORS file at
* https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
*
* This file is part of Bitwuzla under the MIT license. See COPYING for more
* information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
*/
#ifndef BZLALS__TEST__TEST_H
#define BZLALS__TEST__TEST_H
#include <gtest/gtest.h>
#include <cmath>
#include <string>
#include "bv/bitvector.h"
#include "rng/rng.h"
#include "test.h"
namespace bzla::test {
/* -------------------------------------------------------------------------- */
class TestCommon : public ::testing::Test
{
protected:
static void gen_all_combinations(size_t size,
const std::vector<char>& bits,
std::vector<std::string>& values);
static void gen_xvalues(uint64_t bw, std::vector<std::string>& values);
static void gen_values(uint64_t bw, std::vector<std::string>& values);
};
/* -------------------------------------------------------------------------- */
void
TestCommon::gen_all_combinations(size_t size,
const std::vector<char>& bits,
std::vector<std::string>& values)
{
size_t num_values;
size_t num_bits = bits.size();
std::vector<size_t> psizes;
num_values = static_cast<size_t>(
pow(static_cast<double>(num_bits), static_cast<double>(size)));
for (size_t i = 0; i < size; ++i)
{
psizes.push_back(num_values
/ static_cast<size_t>(pow(static_cast<double>(num_bits),
static_cast<double>(i + 1))));
}
/* Generate all combinations of 'bits'. */
for (size_t row = 0; row < num_values; ++row)
{
std::string val;
for (size_t col = 0; col < size; ++col)
{
val += bits[(row / psizes[col]) % num_bits];
}
values.push_back(val);
}
}
void
TestCommon::gen_xvalues(uint64_t bw, std::vector<std::string>& values)
{
gen_all_combinations(bw, {'x', '0', '1'}, values);
}
void
TestCommon::gen_values(uint64_t bw, std::vector<std::string>& values)
{
gen_all_combinations(bw, {'0', '1'}, values);
}
/* -------------------------------------------------------------------------- */
} // namespace bzla::test
#endif
|