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..

9184. By TiborB

some comments added

9185. By TiborB

trunk merged

9186. By GunChleoc

Cleanup

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
1=== modified file 'src/ai/test/CMakeLists.txt'
2--- src/ai/test/CMakeLists.txt 2019-07-11 18:33:59 +0000
3+++ src/ai/test/CMakeLists.txt 2019-08-31 20:13:39 +0000
4@@ -2,6 +2,7 @@
5 SRCS
6 ai_test_main.cc
7 test_ai.cc
8+ test_ga.cc
9 DEPENDS
10 base_log
11 base_macros
12
13=== modified file 'src/ai/test/test_ai.cc'
14--- src/ai/test/test_ai.cc 2019-08-02 09:54:55 +0000
15+++ src/ai/test/test_ai.cc 2019-08-31 20:13:39 +0000
16@@ -30,13 +30,9 @@
17 // Triggered by BOOST_AUTO_TEST_CASE
18 CLANG_DIAG_OFF("-Wdisabled-macro-expansion")
19
20-namespace Widelands { // Needed?
21-class World;
22-} // namespace Widelands
23-
24 using namespace Widelands;
25
26-BOOST_AUTO_TEST_SUITE(ai)
27+BOOST_AUTO_TEST_SUITE(warehouse_distance)
28
29 BOOST_AUTO_TEST_CASE(flag_distance_soft_expiry) {
30 FlagWarehouseDistances fw;
31
32=== added file 'src/ai/test/test_ga.cc'
33--- src/ai/test/test_ga.cc 1970-01-01 00:00:00 +0000
34+++ src/ai/test/test_ga.cc 2019-08-31 20:13:39 +0000
35@@ -0,0 +1,75 @@
36+/*
37+ * Copyright (C) 2007-2019 by the Widelands Development Team
38+ *
39+ * This program is free software; you can redistribute it and/or
40+ * modify it under the terms of the GNU General Public License
41+ * as published by the Free Software Foundation; either version 2
42+ * of the License, or (at your option) any later version.
43+ *
44+ * This program is distributed in the hope that it will be useful,
45+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
46+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47+ * GNU General Public License for more details.
48+ *
49+ * You should have received a copy of the GNU General Public License
50+ * along with this program; if not, write to the Free Software
51+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
52+ *
53+ */
54+
55+// Unittests related to Genetic Algorithm
56+
57+#include <exception>
58+
59+#include <boost/test/unit_test.hpp>
60+
61+#ifdef _WIN32
62+#include "base/log.h"
63+#endif
64+#include "ai/ai_help_structs.h"
65+#include "base/macros.h"
66+
67+// Triggered by BOOST_AUTO_TEST_CASE
68+CLANG_DIAG_OFF("-Wdisabled-macro-expansion")
69+
70+using namespace Widelands;
71+
72+BOOST_AUTO_TEST_SUITE(ai_ga)
73+
74+// Neuron presents a curve, of integers in range (0-20) (21 values)
75+BOOST_AUTO_TEST_CASE(neuron) {
76+ Neuron n1 = Neuron(-50, 0, 0);
77+ BOOST_CHECK_EQUAL(n1.get_id(), 0);
78+ BOOST_CHECK_EQUAL(n1.get_weight(), -50);
79+ BOOST_CHECK_EQUAL(n1.get_result(10), -25);
80+ BOOST_CHECK_EQUAL(n1.get_result(20), -50);
81+ BOOST_CHECK_EQUAL(n1.get_result_safe(100), -50);
82+}
83+
84+BOOST_AUTO_TEST_CASE(neuron_updated_weight) {
85+ Neuron n1 = Neuron(-50, 0, 0);
86+ n1.set_weight(50);
87+ n1.recalculate();
88+ BOOST_CHECK_EQUAL(n1.get_id(), 0);
89+ BOOST_CHECK_EQUAL(n1.get_weight(), 50);
90+ BOOST_CHECK_EQUAL(n1.get_result(10), 25);
91+ BOOST_CHECK_EQUAL(n1.get_result_safe(100), 50);
92+}
93+
94+// FNeuron is uint32_t that serves as 32 bools, that can be set and get independently
95+BOOST_AUTO_TEST_CASE(fneuron_position) {
96+ FNeuron fn = FNeuron(0, 0);
97+ BOOST_CHECK_EQUAL(fn.get_int(), 0); // Initialized as 0, so must be still 0
98+ const bool val0 = fn.get_position(0);
99+ const bool val1 = fn.get_position(1);
100+ BOOST_CHECK_EQUAL(fn.get_position(0), val0);
101+ fn.flip_bit(0);
102+ BOOST_CHECK_EQUAL(!fn.get_position(0), val0);
103+ BOOST_CHECK_EQUAL(fn.get_position(1), val1); //should not be changed
104+ BOOST_CHECK(fn.get_int() != 0); // Initialized as 0, so now must be different
105+ fn.flip_bit(0); // reverting back
106+ BOOST_CHECK_EQUAL(fn.get_int(), 0);
107+}
108+
109+
110+BOOST_AUTO_TEST_SUITE_END()

Subscribers

People subscribed via source and target branches

to status/vote changes: