forked from github/server
tests for basic movement
This commit is contained in:
parent
12e15978b8
commit
d0e2ad542a
5 changed files with 95 additions and 2 deletions
|
@ -260,6 +260,9 @@ void json_race(cJSON *json, race *rc) {
|
||||||
else if (strcmp(child->string, "weight")==0) {
|
else if (strcmp(child->string, "weight")==0) {
|
||||||
rc->weight = child->valueint;
|
rc->weight = child->valueint;
|
||||||
}
|
}
|
||||||
|
else if (strcmp(child->string, "speed")==0) {
|
||||||
|
rc->speed = child->valueint;
|
||||||
|
}
|
||||||
else if (strcmp(child->string, "capacity")==0) {
|
else if (strcmp(child->string, "capacity")==0) {
|
||||||
rc->capacity = child->valueint;
|
rc->capacity = child->valueint;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ static void check_flag(CuTest *tc, const char *name, int flag) {
|
||||||
char data[1024];
|
char data[1024];
|
||||||
const struct race *rc;
|
const struct race *rc;
|
||||||
cJSON *json;
|
cJSON *json;
|
||||||
sprintf(data, "{\"races\" : { \"orc\": { \"flags\" : [ \"%s\"] }}}", name);
|
sprintf(data, "{\"races\" : { \"orc\": { \"speed\" : 1, \"flags\" : [ \"%s\"] }}}", name);
|
||||||
|
|
||||||
json = cJSON_Parse(data);
|
json = cJSON_Parse(data);
|
||||||
free_races();
|
free_races();
|
||||||
|
@ -27,6 +27,7 @@ static void check_flag(CuTest *tc, const char *name, int flag) {
|
||||||
rc = rc_find("orc");
|
rc = rc_find("orc");
|
||||||
CuAssertPtrNotNull(tc, rc);
|
CuAssertPtrNotNull(tc, rc);
|
||||||
CuAssertIntEquals(tc, flag, rc->flags);
|
CuAssertIntEquals(tc, flag, rc->flags);
|
||||||
|
CuAssertIntEquals(tc, 1, rc->speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_flags(CuTest *tc) {
|
static void test_flags(CuTest *tc) {
|
||||||
|
|
|
@ -648,6 +648,8 @@ static void rps_nowrap(FILE * F, const char *s)
|
||||||
const char *x = s;
|
const char *x = s;
|
||||||
size_t indent = 0;
|
size_t indent = 0;
|
||||||
|
|
||||||
|
if (!x) return;
|
||||||
|
|
||||||
while (*x++ == ' ') ;
|
while (*x++ == ' ') ;
|
||||||
indent = x - s - 1;
|
indent = x - s - 1;
|
||||||
if (*(x - 1) && indent && *x == ' ')
|
if (*(x - 1) && indent && *x == ' ')
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
-- new tests 2014-06-11
|
-- new tests 2014-06-11
|
||||||
|
|
||||||
require "tests.settings"
|
require "tests.settings"
|
||||||
require "tests.config"
|
require "tests.config"
|
||||||
require "tests.locale"
|
require "tests.locale"
|
||||||
require "tests.regions"
|
require "tests.regions"
|
||||||
require "tests.ships"
|
require "tests.ships"
|
||||||
require "tests.study"
|
require "tests.study"
|
||||||
|
require "tests.movement"
|
||||||
|
|
||||||
|
|
87
tests/movement.lua
Normal file
87
tests/movement.lua
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
require "lunit"
|
||||||
|
|
||||||
|
module("tests.movement", package.seeall, lunit.testcase)
|
||||||
|
|
||||||
|
function setup()
|
||||||
|
eressea.free_game()
|
||||||
|
eressea.settings.set("nmr.removenewbie", "0")
|
||||||
|
eressea.settings.set("nmr.timeout", "0")
|
||||||
|
eressea.settings.set("rules.ships.storms", "0")
|
||||||
|
conf = [[{
|
||||||
|
"races": {
|
||||||
|
"human" : { "speed" : 1, "flags" : [ "walk" ] },
|
||||||
|
"troll" : {}
|
||||||
|
},
|
||||||
|
"items" : {
|
||||||
|
"horse" : {
|
||||||
|
"capacity" : 7000,
|
||||||
|
"weight" : 5000,
|
||||||
|
"flags" : [ "big", "animal" ]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"terrains" : {
|
||||||
|
"ocean": { "flags" : [ "sea", "sail" ] },
|
||||||
|
"plain": { "flags" : [ "land", "walk", "sail" ] },
|
||||||
|
"glacier": { "flags" : [ "land", "walk" ] }
|
||||||
|
},
|
||||||
|
"directions" : {
|
||||||
|
"de" : {
|
||||||
|
"east" : "OSTEN",
|
||||||
|
"west" : "WESTEN"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"keywords" : {
|
||||||
|
"de" : {
|
||||||
|
"move" : "NACH"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]]
|
||||||
|
|
||||||
|
eressea.config.reset()
|
||||||
|
eressea.config.parse(conf)
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_walk_to_land()
|
||||||
|
local r1 = region.create(0, 0, "plain")
|
||||||
|
local r2 = region.create(1, 0, "plain")
|
||||||
|
local f = faction.create("test@example.com", "human", "de")
|
||||||
|
local u = unit.create(f, r1, 1)
|
||||||
|
u:add_order("NACH O")
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r2, u.region)
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_walk_to_ocean()
|
||||||
|
local r1 = region.create(0, 0, "plain")
|
||||||
|
local r2 = region.create(1, 0, "ocean")
|
||||||
|
local f = faction.create("test@example.com", "human", "de")
|
||||||
|
local u = unit.create(f, r1, 1)
|
||||||
|
u:add_order("NACH O")
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r1, u.region)
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_walk_distance()
|
||||||
|
local r1 = region.create(0, 0, "plain")
|
||||||
|
local r2 = region.create(1, 0, "plain")
|
||||||
|
local r3 = region.create(2, 0, "plain")
|
||||||
|
local f = faction.create("test@example.com", "human", "de")
|
||||||
|
local u = unit.create(f, r1, 1)
|
||||||
|
u:add_order("NACH O O")
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r2, u.region)
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_ride_distance()
|
||||||
|
local r1 = region.create(0, 0, "plain")
|
||||||
|
local r2 = region.create(1, 0, "plain")
|
||||||
|
local r3 = region.create(2, 0, "plain")
|
||||||
|
local f = faction.create("test@example.com", "human", "de")
|
||||||
|
local u = unit.create(f, r1, 1)
|
||||||
|
u:add_item("horse", 1)
|
||||||
|
u:set_skill("riding", 2)
|
||||||
|
u:add_order("NACH O O")
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r3, u.region)
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue