TiborB has proposed merging lp:~widelands-dev/widelands/ai_ga_unittests into lp:widelands.
Commit message: Handful of AI unittests Requested reviews: Widelands Developers (widelands-dev) For more details, see: https://code.launchpad.net/~widelands-dev/widelands/ai_ga_unittests/+merge/372091 Without effect on the game itself -- Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/ai_ga_unittests into lp:widelands.
=== modified file 'src/ai/test/CMakeLists.txt' --- src/ai/test/CMakeLists.txt 2019-07-11 18:33:59 +0000 +++ src/ai/test/CMakeLists.txt 2019-08-30 19:03:54 +0000 @@ -2,6 +2,7 @@ SRCS ai_test_main.cc test_ai.cc + test_ga.cc DEPENDS base_log base_macros === modified file 'src/ai/test/test_ai.cc' --- src/ai/test/test_ai.cc 2019-08-02 09:54:55 +0000 +++ src/ai/test/test_ai.cc 2019-08-30 19:03:54 +0000 @@ -36,7 +36,7 @@ using namespace Widelands; -BOOST_AUTO_TEST_SUITE(ai) +BOOST_AUTO_TEST_SUITE(warehouse_distance) BOOST_AUTO_TEST_CASE(flag_distance_soft_expiry) { FlagWarehouseDistances fw; === added file 'src/ai/test/test_ga.cc' --- src/ai/test/test_ga.cc 1970-01-01 00:00:00 +0000 +++ src/ai/test/test_ga.cc 2019-08-30 19:03:54 +0000 @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2007-2019 by the Widelands Development Team + * + * 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 the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include <exception> + +#include <boost/test/unit_test.hpp> + +#ifdef _WIN32 +#include "base/log.h" +#endif +#include "ai/ai_help_structs.h" +#include "base/macros.h" + +// Triggered by BOOST_AUTO_TEST_CASE +CLANG_DIAG_OFF("-Wdisabled-macro-expansion") + +namespace Widelands { // Needed? +class World; +} // namespace Widelands + +using namespace Widelands; + +BOOST_AUTO_TEST_SUITE(ai_ga) + +BOOST_AUTO_TEST_CASE(neuron) { + //weight(w), type(f), id(i) + Neuron n1 = Neuron(-50, 0, 0); + BOOST_CHECK_EQUAL(n1.get_id(), 0); + BOOST_CHECK_EQUAL(n1.get_weight(), -50); + BOOST_CHECK_EQUAL(n1.get_result(10), -25); + BOOST_CHECK_EQUAL(n1.get_result(20), -50); + BOOST_CHECK_EQUAL(n1.get_result_safe(100), -50); +} + +BOOST_AUTO_TEST_CASE(neuron_updated_weight) { + //weight(w), type(f), id(i) + Neuron n1 = Neuron(-50, 0, 0); + n1.set_weight(50); + n1.recalculate(); + BOOST_CHECK_EQUAL(n1.get_id(), 0); + BOOST_CHECK_EQUAL(n1.get_weight(), 50); + BOOST_CHECK_EQUAL(n1.get_result(10), 25); + BOOST_CHECK_EQUAL(n1.get_result_safe(100), 50); +} + +BOOST_AUTO_TEST_CASE(fneuron_position) { + //core(c), id(i) + FNeuron fn = FNeuron(0, 0); + BOOST_CHECK_EQUAL(fn.get_int(), 0); // Initialized as 0, so must be still 0 + const bool val0 = fn.get_position(0); + const bool val1 = fn.get_position(1); + BOOST_CHECK_EQUAL(fn.get_position(0), val0); + fn.flip_bit(0); + BOOST_CHECK_EQUAL(!fn.get_position(0), val0); + BOOST_CHECK_EQUAL(fn.get_position(1), val1); //should not be changed + BOOST_CHECK(fn.get_int() != 0); // Initialized as 0, so now must be different + fn.flip_bit(0); // reverting back + BOOST_CHECK_EQUAL(fn.get_int(), 0); +} + + +BOOST_AUTO_TEST_SUITE_END()
_______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp