Merge lp:~widelands-dev/widelands/ai_ga_unittests into lp:widelands

Proposed by TiborB
Status: Merged
Merged at revision: 9193
Proposed branch: lp:~widelands-dev/widelands/ai_ga_unittests
Merge into: lp:widelands
Diff against target: 110 lines (+77/-5)
3 files modified
src/ai/test/CMakeLists.txt (+1/-0)
src/ai/test/test_ai.cc (+1/-5)
src/ai/test/test_ga.cc (+75/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/ai_ga_unittests
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+372091@code.launchpad.net

Commit message

Handful of AI unittests

Description of the change

Without effect on the game itself

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5363. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/578959736.
Appveyor build 5133. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_ga_unittests-5133.

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM :)

Just 1 tiny nit: What does ga mean? Add a comment to the test file.

Revision history for this message
TiborB (tiborb95) wrote :

ga = Genetic Algorithm :)
I am going to add the comment..

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks!

I have done some final cleanup, so this can go in now :)

@bunnybot merge

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5377. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/579270151.
Appveyor build 5147. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_ga_unittests-5147.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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-31 20:13:39 +0000
@@ -2,6 +2,7 @@
2 SRCS2 SRCS
3 ai_test_main.cc3 ai_test_main.cc
4 test_ai.cc4 test_ai.cc
5 test_ga.cc
5 DEPENDS6 DEPENDS
6 base_log7 base_log
7 base_macros8 base_macros
89
=== 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-31 20:13:39 +0000
@@ -30,13 +30,9 @@
30// Triggered by BOOST_AUTO_TEST_CASE30// Triggered by BOOST_AUTO_TEST_CASE
31CLANG_DIAG_OFF("-Wdisabled-macro-expansion")31CLANG_DIAG_OFF("-Wdisabled-macro-expansion")
3232
33namespace Widelands { // Needed?
34class World;
35} // namespace Widelands
36
37using namespace Widelands;33using namespace Widelands;
3834
39BOOST_AUTO_TEST_SUITE(ai)35BOOST_AUTO_TEST_SUITE(warehouse_distance)
4036
41BOOST_AUTO_TEST_CASE(flag_distance_soft_expiry) {37BOOST_AUTO_TEST_CASE(flag_distance_soft_expiry) {
42 FlagWarehouseDistances fw;38 FlagWarehouseDistances fw;
4339
=== 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-31 20:13:39 +0000
@@ -0,0 +1,75 @@
1/*
2 * Copyright (C) 2007-2019 by the Widelands Development Team
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20// Unittests related to Genetic Algorithm
21
22#include <exception>
23
24#include <boost/test/unit_test.hpp>
25
26#ifdef _WIN32
27#include "base/log.h"
28#endif
29#include "ai/ai_help_structs.h"
30#include "base/macros.h"
31
32// Triggered by BOOST_AUTO_TEST_CASE
33CLANG_DIAG_OFF("-Wdisabled-macro-expansion")
34
35using namespace Widelands;
36
37BOOST_AUTO_TEST_SUITE(ai_ga)
38
39// Neuron presents a curve, of integers in range (0-20) (21 values)
40BOOST_AUTO_TEST_CASE(neuron) {
41 Neuron n1 = Neuron(-50, 0, 0);
42 BOOST_CHECK_EQUAL(n1.get_id(), 0);
43 BOOST_CHECK_EQUAL(n1.get_weight(), -50);
44 BOOST_CHECK_EQUAL(n1.get_result(10), -25);
45 BOOST_CHECK_EQUAL(n1.get_result(20), -50);
46 BOOST_CHECK_EQUAL(n1.get_result_safe(100), -50);
47}
48
49BOOST_AUTO_TEST_CASE(neuron_updated_weight) {
50 Neuron n1 = Neuron(-50, 0, 0);
51 n1.set_weight(50);
52 n1.recalculate();
53 BOOST_CHECK_EQUAL(n1.get_id(), 0);
54 BOOST_CHECK_EQUAL(n1.get_weight(), 50);
55 BOOST_CHECK_EQUAL(n1.get_result(10), 25);
56 BOOST_CHECK_EQUAL(n1.get_result_safe(100), 50);
57}
58
59// FNeuron is uint32_t that serves as 32 bools, that can be set and get independently
60BOOST_AUTO_TEST_CASE(fneuron_position) {
61 FNeuron fn = FNeuron(0, 0);
62 BOOST_CHECK_EQUAL(fn.get_int(), 0); // Initialized as 0, so must be still 0
63 const bool val0 = fn.get_position(0);
64 const bool val1 = fn.get_position(1);
65 BOOST_CHECK_EQUAL(fn.get_position(0), val0);
66 fn.flip_bit(0);
67 BOOST_CHECK_EQUAL(!fn.get_position(0), val0);
68 BOOST_CHECK_EQUAL(fn.get_position(1), val1); //should not be changed
69 BOOST_CHECK(fn.get_int() != 0); // Initialized as 0, so now must be different
70 fn.flip_bit(0); // reverting back
71 BOOST_CHECK_EQUAL(fn.get_int(), 0);
72}
73
74
75BOOST_AUTO_TEST_SUITE_END()

Subscribers

People subscribed via source and target branches

to status/vote changes: