15 #define GETTEXT_DOMAIN "wesnoth-test"
17 #include <boost/test/unit_test.hpp>
28 if(key ==
"strength") {
30 }
else if(key ==
"agility") {
40 if(key ==
"members") {
44 std::vector<variant> members;
45 for(
int n = 0;
n != 3; ++
n) {
50 }
else if(key ==
"char") {
76 BOOST_CHECK_EQUAL(
formula(
"strength").evaluate(c).as_int(), 15);
77 BOOST_CHECK_EQUAL(
formula(
"17").evaluate().as_int(), 17);
79 BOOST_CHECK_EQUAL(
formula(
"strength/2 + agility").evaluate(c).as_int(), 19);
80 BOOST_CHECK_EQUAL(
formula(
"(strength+agility)/2").evaluate(c).as_int(), 13);
82 BOOST_CHECK_EQUAL(
formula(
"20 % 3").evaluate().as_int(), 2);
83 BOOST_CHECK_EQUAL(
formula(
"19.5 % 3").evaluate().as_decimal(),
84 static_cast<int>(1000.0 * 1.5));
86 BOOST_CHECK_EQUAL(
formula(
"-5").evaluate().as_int(), -5);
88 BOOST_CHECK_EQUAL(
formula(
"4^2").evaluate().as_int(), 16);
89 BOOST_CHECK_EQUAL(
formula(
"2+3^3").evaluate().as_int(), 29);
90 BOOST_CHECK_EQUAL(
formula(
"2*3^3+2").evaluate().as_int(), 56);
91 BOOST_CHECK_EQUAL(
formula(
"2^3^2").evaluate().as_int(), 512);
92 BOOST_CHECK_EQUAL(
formula(
"9^3").evaluate().as_int(), 729);
93 BOOST_CHECK(
formula(
"(-2)^0.5").evaluate().is_null());
98 BOOST_CHECK_EQUAL(
formula(
"strength > 12").evaluate(
c).as_int(), 1);
99 BOOST_CHECK_EQUAL(
formula(
"strength > 18").evaluate(
c).as_int(), 0);
101 BOOST_CHECK_EQUAL(
formula(
"if(strength > 12, 7, 2)").evaluate(
c).as_int(), 7);
102 BOOST_CHECK_EQUAL(
formula(
"if(strength > 18, 7, 2)").evaluate(
c).as_int(), 2);
104 BOOST_CHECK_EQUAL(
formula(
"2 and 1").evaluate().as_int(), 1);
105 BOOST_CHECK_EQUAL(
formula(
"2 and 0").evaluate().as_int(), 0);
106 BOOST_CHECK_EQUAL(
formula(
"2 or 0").evaluate().as_int(), 2);
108 BOOST_CHECK_EQUAL(
formula(
"not 5").evaluate().as_int(), 0);
109 BOOST_CHECK_EQUAL(
formula(
"not 0").evaluate().as_int(), 1);
116 BOOST_CHECK_EQUAL(
formula(
"char.strength").evaluate(
p).as_int(), 15);
117 BOOST_CHECK_EQUAL(
formula(
"choose(members,strength).strength").evaluate(
p).as_int(), 16);
119 BOOST_CHECK_EQUAL(
formula(
"char.sum([strength, agility, intelligence])").evaluate(
p).as_int(), 37);
124 BOOST_CHECK_EQUAL(
formula(
"x*5 where x=1").evaluate().as_int(), 5);
125 BOOST_CHECK_EQUAL(
formula(
"x*5 where x=2").evaluate().as_int(), 10);
127 BOOST_CHECK_EQUAL(
formula(
"x*(a*b where a=2,b=1) where x=5").evaluate().as_int(), 10);
128 BOOST_CHECK_EQUAL(
formula(
"char.strength * ability where ability=3").evaluate(
p).as_int(), 45);
133 BOOST_CHECK_EQUAL(
formula(
"'abcd' = 'abcd'").evaluate().as_bool(),
true);
134 BOOST_CHECK_EQUAL(
formula(
"'abcd' = 'acd'").evaluate().as_bool(),
false);
136 BOOST_CHECK_EQUAL(
formula(
"'ab' .. 'cd'").evaluate().as_string(),
"abcd");
138 BOOST_CHECK_EQUAL(
formula(
"'strength, agility: [strength], [agility]'").evaluate(
c).as_string(),
139 "strength, agility: 15, 12");
141 BOOST_CHECK_EQUAL(
formula(
"'String with [']quotes['] and [(]brackets[)]!'").evaluate().as_string(),
142 "String with 'quotes' and [brackets]!");
143 BOOST_CHECK_EQUAL(
formula(
"'String with ['embedded ' .. 'string']!'").evaluate().as_string(),
144 "String with embedded string!");
149 assert(dice_roll >= 3 && dice_roll <= 18);
155 BOOST_CHECK_EQUAL(myarray[0].as_int(), 1);
156 BOOST_CHECK_EQUAL(myarray[1].as_int(), 2);
157 BOOST_CHECK_EQUAL(myarray[2].as_int(), 3);
161 BOOST_CHECK_EQUAL(mydict[
variant(
"foo")].as_int(), 5);
162 BOOST_CHECK_EQUAL(mydict[
variant(
"bar")].as_int(), 7);
166 BOOST_CHECK_EQUAL(myrange[0].as_int(), -2);
167 BOOST_CHECK_EQUAL(myrange[1].as_int(), -1);
168 BOOST_CHECK_EQUAL(myrange[2].as_int(), 0);
169 BOOST_CHECK_EQUAL(myrange[3].as_int(), 1);
170 BOOST_CHECK_EQUAL(myrange[4].as_int(), 2);
174 BOOST_CHECK_EQUAL(myslice[0].as_int(), 11);
175 BOOST_CHECK_EQUAL(myslice[1].as_int(), 13);
176 BOOST_CHECK_EQUAL(myslice[2].as_int(), 17);
177 BOOST_CHECK_EQUAL(myslice[3].as_int(), 19);
180 BOOST_AUTO_TEST_SUITE_END()
size_t num_elements() const
variant get_value(const std::string &key) const
BOOST_AUTO_TEST_SUITE(test_map_location)
variant get_value(const std::string &key) const
GLsizei const GLcharARB ** string