disable randomness that causes some tests to become intermittent.

fix normalvariante and chance so they work better with constant
rng always returning zero
This commit is contained in:
Enno Rehling 2017-05-02 08:45:18 +02:00
parent 5d710fa79f
commit 83d40962d2
6 changed files with 15 additions and 2 deletions

View file

@ -17,6 +17,7 @@ require 'eressea.path'
require 'tests.e2' require 'tests.e2'
require 'lunit' require 'lunit'
rng_default(0)
rules = require('eressea.' .. config.rules) rules = require('eressea.' .. config.rules)
result = lunit.main() result = lunit.main()
return result.errors + result.failed return result.errors + result.failed

View file

@ -17,6 +17,7 @@ require 'eressea.xmlconf'
require 'tests.e3' require 'tests.e3'
require 'lunit' require 'lunit'
rng_default(0)
eressea.settings.set("rules.alliances", "0") eressea.settings.set("rules.alliances", "0")
rules = require('eressea.' .. config.rules) rules = require('eressea.' .. config.rules)
result = lunit.main() result = lunit.main()

View file

@ -218,6 +218,9 @@ function test_gmtool()
local r1 = region.create(1, 0, "plain") local r1 = region.create(1, 0, "plain")
local r2 = region.create(1, 1, "plain") local r2 = region.create(1, 1, "plain")
local r3 = region.create(1, 2, "plain") local r3 = region.create(1, 2, "plain")
if not gmtool then
return
end
gmtool.open() gmtool.open()
gmtool.select(r1, true) gmtool.select(r1, true)
gmtool.select_at(0, 1, true) gmtool.select_at(0, 1, true)

View file

@ -6,6 +6,7 @@ function setup()
eressea.game.reset() eressea.game.reset()
eressea.settings.set("rules.food.flags", "4") -- food is free eressea.settings.set("rules.food.flags", "4") -- food is free
eressea.settings.set("NewbieImmunity", "0") eressea.settings.set("NewbieImmunity", "0")
eressea.settings.set("study.random_progress", "0")
end end
local function create_faction(race) local function create_faction(race)

View file

@ -990,6 +990,12 @@ static void parse_inifile(lua_State * L, const dictionary * d, const char *secti
} }
} }
static int lua_rng_default(lua_State *L) {
UNUSED_ARG(L);
random_source_inject_constant(0);
return 0;
}
void tolua_bind_open(lua_State * L); void tolua_bind_open(lua_State * L);
int tolua_bindings_open(lua_State * L, const dictionary *inifile) int tolua_bindings_open(lua_State * L, const dictionary *inifile)
@ -1060,6 +1066,7 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
tolua_function(L, TOLUA_CAST "get_ship", tolua_get_ship); tolua_function(L, TOLUA_CAST "get_ship", tolua_get_ship);
tolua_function(L, TOLUA_CAST "get_building", tolua_get_building); tolua_function(L, TOLUA_CAST "get_building", tolua_get_building);
tolua_function(L, TOLUA_CAST "get_region", tolua_get_region); tolua_function(L, TOLUA_CAST "get_region", tolua_get_region);
tolua_function(L, TOLUA_CAST "rng_default", lua_rng_default);
tolua_function(L, TOLUA_CAST "factions", tolua_get_factions); tolua_function(L, TOLUA_CAST "factions", tolua_get_factions);
tolua_function(L, TOLUA_CAST "regions", tolua_get_regions); tolua_function(L, TOLUA_CAST "regions", tolua_get_regions);
tolua_function(L, TOLUA_CAST "read_turn", tolua_read_turn); tolua_function(L, TOLUA_CAST "read_turn", tolua_read_turn);

View file

@ -46,7 +46,7 @@ double normalvariate(double mu, double sigma)
double z; double z;
for (;;) { for (;;) {
double u1 = rng_double(); double u1 = rng_double();
double u2 = 1.0 - rng_double(); double u2 = rng_double();
z = NV_MAGICCONST * (u1 - 0.5) / u2; z = NV_MAGICCONST * (u1 - 0.5) / u2;
if (z * z / 4.0 <= -log(u2)) { if (z * z / 4.0 <= -log(u2)) {
break; break;
@ -73,7 +73,7 @@ bool chance(double x)
{ {
if (x >= 1.0) if (x >= 1.0)
return true; return true;
return rng_double() < x; return (1-rng_double()) < x;
} }
typedef struct random_source { typedef struct random_source {