Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy, move constructors and copy assignment operator added #824

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 31 additions & 21 deletions src/mlpack/tests/det_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,21 +456,23 @@ BOOST_AUTO_TEST_CASE(CopyConstructorAndOperatorTest)
<< 5 << 0 << 1 << 7 << 1 << arma::endr
<< 5 << 6 << 7 << 1 << 8 << arma::endr;

DTree<arma::Mat<float>> tree(testData);
DTree<arma::Mat<float>>* tree = new DTree<arma::Mat<float>>(testData);

// Copy the genarated DTree
DTree<arma::Mat<float>> tree2(tree);
DTree<arma::Mat<float>> tree3 = tree;
DTree<arma::Mat<float>> tree2(*tree);
DTree<arma::Mat<float>> tree3 = *tree;

double max0, max1, max2, min0, min1, min2;

// Computing the max and min vals
max0 = tree.maxVals[0];
max1 = tree.maxVals[1];
max2 = tree.maxVals[2];
min0 = tree.minVals[0];
min1 = tree.minVals[1];
min2 = tree.minVals[2];
max0 = tree->maxVals[0];
max1 = tree->maxVals[1];
max2 = tree->maxVals[2];
min0 = tree->minVals[0];
min1 = tree->minVals[1];
min2 = tree->minVals[2];

delete tree;

// Comparing with the DTree constructed using copy constructor
BOOST_REQUIRE_EQUAL(tree2.maxVals[0], max0);
Expand Down Expand Up @@ -498,25 +500,33 @@ BOOST_AUTO_TEST_CASE(MoveConstructorTest)
<< 5 << 0 << 1 << 7 << 1 << arma::endr
<< 5 << 6 << 7 << 1 << 8 << arma::endr;

DTree<arma::Mat<float>> tree(testData);
DTree<arma::Mat<float>>* tree = new DTree<arma::Mat<float>>(testData);

double max0, max1, max2, min0, min1, min2, logNegError;

// Computing the max and min val and the logNegError that has been calculated
max0 = tree.maxVals[0];
max1 = tree.maxVals[1];
max2 = tree.maxVals[2];
min0 = tree.minVals[0];
min1 = tree.minVals[1];
min2 = tree.minVals[2];
logNegError = tree.logNegError;

DTree<arma::Mat<float>> tree2 = std::move(tree);
max0 = tree->maxVals[0];
max1 = tree->maxVals[1];
max2 = tree->maxVals[2];
min0 = tree->minVals[0];
min1 = tree->minVals[1];
min2 = tree->minVals[2];
logNegError = tree->logNegError;

BOOST_REQUIRE_EQUAL(tree2.logNegError, logNegError);
DTree<arma::Mat<float>> tree2 = std::move(*tree);

// Checking for the default values in tree after move is performed
BOOST_REQUIRE_EQUAL(tree.logNegError, -DBL_MAX);
BOOST_REQUIRE_EQUAL(tree->logNegError, -DBL_MAX);

delete tree;

BOOST_REQUIRE_EQUAL(tree2.maxVals[0], max0);
BOOST_REQUIRE_EQUAL(tree2.maxVals[1], max1);
BOOST_REQUIRE_EQUAL(tree2.maxVals[2], max2);
BOOST_REQUIRE_EQUAL(tree2.minVals[0], min0);
BOOST_REQUIRE_EQUAL(tree2.minVals[1], min1);
BOOST_REQUIRE_EQUAL(tree2.minVals[2], min2);
BOOST_REQUIRE_EQUAL(tree2.logNegError, logNegError);
}

/**
Expand Down