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

Fix CAlphabet::Clone + unit test #3676

Merged
merged 1 commit into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/shogun/features/Alphabet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,14 @@ void CAlphabet::translate_from_single_order_reversed(ST* obs, int32_t sequence_l
}
}

CSGObject * CAlphabet::clone()
{
CAlphabet * alph_clone = (CAlphabet *) CSGObject::clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no whitespace before *

alph_clone->init_map_table();
alph_clone->copy_histogram(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this all that is needed? If so this is a neat solution

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping you guys could tell! There was that obscure comment in the code here, I can't say for sure the patch is enough. Certainly the code before wasn't all that was needed :P

return alph_clone;
}

template <class ST>
void CAlphabet::translate_from_single_order(ST* obs, int32_t sequence_length, int32_t start, int32_t p_order, int32_t max_val, int32_t gap)
{
Expand Down
2 changes: 2 additions & 0 deletions src/shogun/features/Alphabet.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ class CAlphabet : public CSGObject
template <class ST>
static void translate_from_single_order_reversed(ST* obs, int32_t sequence_length, int32_t start, int32_t p_order, int32_t max_val, int32_t gap);

CSGObject * clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually have no space before pointer *


private:
/** Do basic initialisations like default settings
* and registering parameters */
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/features/Alphabet_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BSD please, see more recent headers

* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2017 Leon Kuchenbecker
*/

#include <shogun/features/Alphabet.h>
#include <gtest/gtest.h>

using namespace shogun;

TEST(AlphabetTest, test_clone)
{
CAlphabet * alph = new CAlphabet(PROTEIN);
CAlphabet * alph_clone = (CAlphabet *) alph->clone();

EXPECT_EQ(alph->get_num_symbols(), alph_clone->get_num_symbols());
EXPECT_EQ(alph->get_num_symbols_in_histogram(), alph_clone->get_num_symbols_in_histogram());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you valgrind check this for leaks?


SG_UNREF(alph);
SG_UNREF(alph_clone);
}