mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-09 09:33:57 -07:00
add deck hashing tests
This commit is contained in:
parent
2b690f8c87
commit
b6c5c5ea4c
5 changed files with 84 additions and 7 deletions
|
|
@ -4,6 +4,7 @@ add_test(NAME expression_test COMMAND expression_test)
|
|||
|
||||
add_test(NAME test_age_formatting COMMAND test_age_formatting)
|
||||
add_test(NAME password_hash_test COMMAND password_hash_test)
|
||||
add_test(NAME deck_hash_test COMMAND deck_hash_test)
|
||||
|
||||
# Find GTest
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ add_executable(dummy_test dummy_test.cpp)
|
|||
add_executable(expression_test expression_test.cpp)
|
||||
add_executable(test_age_formatting test_age_formatting.cpp)
|
||||
add_executable(password_hash_test password_hash_test.cpp)
|
||||
add_executable(deck_hash_test ../common/decklist.cpp deck_hash_test.cpp)
|
||||
|
||||
find_package(GTest)
|
||||
|
||||
|
|
@ -41,6 +43,7 @@ if(NOT GTEST_FOUND)
|
|||
add_dependencies(expression_test gtest)
|
||||
add_dependencies(test_age_formatting gtest)
|
||||
add_dependencies(password_hash_test gtest)
|
||||
add_dependencies(deck_hash_test gtest)
|
||||
endif()
|
||||
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
|
|
@ -50,6 +53,9 @@ target_link_libraries(test_age_formatting Threads::Threads ${GTEST_BOTH_LIBRARIE
|
|||
target_link_libraries(
|
||||
password_hash_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
|
||||
)
|
||||
target_link_libraries(
|
||||
deck_hash_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
|
||||
)
|
||||
|
||||
add_subdirectory(carddatabase)
|
||||
add_subdirectory(loading_from_clipboard)
|
||||
|
|
|
|||
44
tests/deck_hash_test.cpp
Normal file
44
tests/deck_hash_test.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "../../common/decklist.h"
|
||||
#include<QDebug>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
QString bigDeck;
|
||||
|
||||
TEST(DeckHashTest, RepeatTest)
|
||||
{
|
||||
DeckList decklist(R"(<?xml version="1.0"?><cockatrice_deck version="1"><deckname></deckname><comments></comments><zone name="main"><card number="1" name="Mountain"/><card number="2" name="Island"/></zone><zone name="side"><card number="3" name="Forest"/></zone></cockatrice_deck>)");
|
||||
for (int i = 0; i < 1e6; ++i){ // repeat hashing a million times
|
||||
decklist.updateDeckHash();
|
||||
}
|
||||
auto hash = decklist.getDeckHash().toStdString();
|
||||
ASSERT_EQ(hash, "5cac19qm") << "The hash matches";
|
||||
}
|
||||
|
||||
TEST(DeckHashTest, NumberTest)
|
||||
{
|
||||
DeckList decklist(R"(<?xml version="1.0"?><cockatrice_deck version="1"><deckname></deckname><comments></comments><zone name="main"><card number="1000000" name="Island"/></zone></cockatrice_deck>)");
|
||||
auto hash = decklist.getDeckHash().toStdString();
|
||||
ASSERT_EQ(hash, "2k8cdi4s") << "The hash matches";
|
||||
}
|
||||
|
||||
TEST(DeckHashTest, UniquesTest)
|
||||
{
|
||||
DeckList decklist(bigDeck);
|
||||
auto hash = decklist.getDeckHash().toStdString();
|
||||
ASSERT_EQ(hash, "s544mlan") << "The hash matches";
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QStringList deckString;
|
||||
deckString << R"(<?xml version="1.0"?><cockatrice_deck version="1"><deckname></deckname><comments></comments><zone name="main"><card number="1" name="card 0)";
|
||||
for (int i = 1; i < 1e6; ++i){ // add a million unique cards
|
||||
deckString << R"("/><card number="1" name="card )" + QString::number(i);
|
||||
}
|
||||
deckString << R"("/></zone></cockatrice_deck>)";
|
||||
bigDeck = deckString.join("");
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
@ -3,22 +3,33 @@
|
|||
#include <QTextStream>
|
||||
#include <libcockatrice/deck_list/tree/deck_list_card_node.h>
|
||||
|
||||
void testEmpty(const QString &clipboard)
|
||||
DeckList getDeckList(const QString &clipboard)
|
||||
{
|
||||
QString cp(clipboard);
|
||||
DeckList deckList;
|
||||
QString cp(clipboard);
|
||||
QTextStream stream(&cp); // text stream requires local copy
|
||||
deckList.loadFromStream_Plain(stream, false);
|
||||
return deckList;
|
||||
}
|
||||
|
||||
void testEmpty(const QString &clipboard)
|
||||
{
|
||||
DeckList deckList = getDeckList(clipboard);
|
||||
|
||||
ASSERT_TRUE(deckList.getCardList().isEmpty());
|
||||
}
|
||||
|
||||
void testHash(const QString &clipboard, const std::string &hash)
|
||||
{
|
||||
DeckList deckList = getDeckList(clipboard);
|
||||
std::cout << deckList.writeToString_Native().toStdString() << std::endl;
|
||||
|
||||
ASSERT_EQ(deckList.getDeckHash().toStdString(), hash);
|
||||
}
|
||||
|
||||
void testDeck(const QString &clipboard, const Result &result)
|
||||
{
|
||||
QString cp(clipboard);
|
||||
DeckList deckList;
|
||||
QTextStream stream(&cp); // text stream requires local copy
|
||||
deckList.loadFromStream_Plain(stream, false);
|
||||
DeckList deckList = getDeckList(clipboard);
|
||||
|
||||
ASSERT_EQ(result.name, deckList.getName().toStdString());
|
||||
ASSERT_EQ(result.comments, deckList.getComments().toStdString());
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ struct Result
|
|||
};
|
||||
|
||||
void testEmpty(const QString &clipboard);
|
||||
|
||||
void testHash(const QString &clipboard, const std::string &hash);
|
||||
void testDeck(const QString &clipboard, const Result &result);
|
||||
|
||||
#endif // CLIPBOARD_TESTING_H
|
||||
|
|
|
|||
|
|
@ -203,6 +203,22 @@ TEST(LoadingFromClipboardTest, emptyMainBoard)
|
|||
testEmpty(clipboard);
|
||||
}
|
||||
|
||||
TEST(LoadingFromClipboardTest, emptyHash)
|
||||
{
|
||||
QString clipboard("");
|
||||
|
||||
testHash(clipboard, "r8sq7riu");
|
||||
}
|
||||
|
||||
TEST(LoadingFromClipboardTest, deckHash)
|
||||
{
|
||||
QString clipboard("1 Mountain\n"
|
||||
"2 Island\n"
|
||||
"SB: 3 Forest\n");
|
||||
|
||||
testHash(clipboard, "5cac19qm");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue