added first tests (do not work)

This commit is contained in:
Andrei Yankovich 2019-07-09 15:35:24 +03:00
parent 4b0ff2c688
commit a0c3ff3409
4 changed files with 49 additions and 10 deletions

@ -43,9 +43,7 @@ BigInt::BigInt(double val):
}
std::string BigInt::getString(int base) const {
char *str = nullptr;
mpz_get_str(str, base, data);
char *str = mpz_get_str(nullptr, base, data);
return str;
}
@ -53,6 +51,11 @@ BigInt::~BigInt() {
mpz_clear(data);
}
BigInt &BigInt::operator =(const BigInt &val) {
mpz_set(data, val.data);
return *this;
}
// add operators
BigInt operator +(BigInt left, unsigned int right) {
mpz_add_ui(left.data, left.data, right);

@ -32,6 +32,8 @@ public:
std::string getString(int base = 10) const;
~BigInt();
BigInt& operator = (const BigInt& val);
friend BigInt operator + ( BigInt left, const BigInt& right);
friend BigInt operator + ( BigInt left, unsigned int right);
friend BigInt operator + ( BigInt left, int right);

@ -8,3 +8,5 @@ TEMPLATE = app
TARGET = miniGmpTests
SOURCES += tst_arithmetictests.cpp
include(../GMP.pri)

@ -1,4 +1,5 @@
#include <QtTest>
#include <bigint.h>
// add necessary includes here
@ -11,25 +12,56 @@ public:
~arithmetictests();
private slots:
void test_case1();
void operatorsTest();
void constructorsTest();
};
arithmetictests::arithmetictests()
{
arithmetictests::arithmetictests() {
}
arithmetictests::~arithmetictests()
{
arithmetictests::~arithmetictests() {
}
void arithmetictests::test_case1()
{
void arithmetictests::constructorsTest() {
BigInt num1; // should be 0 by default
QVERIFY(num1 == 0);
BigInt num2(0); // 0 passed as an integer
QVERIFY(num2 == 0);
BigInt num3("0"); // 0 passed as a string
QVERIFY(num3 == 0);
BigInt num4(num3); // object with value 0 passed to copy constructor
QVERIFY(num4 == 0);
BigInt num5(0.0); // object with value 0 passed to copy constructor
QVERIFY(num5 == 0);
BigInt num21(1); // 0 passed as an integer
auto txt = num21.getString(10);
QVERIFY(num2 != 0);
BigInt num31("0.1"); // 0 passed as a string
QVERIFY(num3 != 0);
BigInt num41(num3); // object with value 0 passed to copy constructor
QVERIFY(num4 != 0);
BigInt num51(0.1); // object with value 0 passed to copy constructor
QVERIFY(num5 != 0);
}
void arithmetictests::operatorsTest() {
}
QTEST_APPLESS_MAIN(arithmetictests)
#include "tst_arithmetictests.moc"