expose RANDOMIZE_HEURISTICS config in •internal.Temp
This commit is contained in:
parent
59923b25df
commit
860594ae48
@ -6,6 +6,13 @@
|
||||
#include "../utils/calls.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifndef DEBUG
|
||||
#define DEBUG 0
|
||||
#endif
|
||||
#ifndef TEST_UTILS
|
||||
#define TEST_UTILS DEBUG
|
||||
#endif
|
||||
|
||||
B itype_c1(B t, B x) {
|
||||
B r;
|
||||
if(isVal(x)) {
|
||||
@ -297,11 +304,11 @@ B internalTemp_c1(B t, B x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
#if DEBUG && !defined(TEST_UTILS)
|
||||
#define TEST_UTILS 1
|
||||
#endif
|
||||
#ifdef TEST_UTILS
|
||||
#if TEST_UTILS
|
||||
#include "../utils/mut.h"
|
||||
#if RANDOMIZE_HEURISTICS
|
||||
extern u64 heuristic_seed;
|
||||
#endif
|
||||
#endif
|
||||
#if NATIVE_COMPILER
|
||||
extern B native_comp;
|
||||
@ -325,6 +332,28 @@ B internalTemp_c2(B t, B w, B x) {
|
||||
printI(x);
|
||||
return x;
|
||||
}
|
||||
#if RANDOMIZE_HEURISTICS
|
||||
case 1: {
|
||||
if (isC32(x)) { // read seed
|
||||
i32* rp;
|
||||
r = m_i32arrv(&rp, 2);
|
||||
rp[0] = (u32) heuristic_seed;
|
||||
rp[1] = (u32) (heuristic_seed >> 32);
|
||||
return r;
|
||||
}
|
||||
if (q_i32(x)) { // simple set seed
|
||||
heuristic_seed = o2i(x);
|
||||
return x;
|
||||
}
|
||||
if (isArr(x)) { // full set seed
|
||||
x = toI32Any(x);
|
||||
i32* xp = i32any_ptr(x);
|
||||
heuristic_seed = (u32)xp[0] | ((u64)(u32)xp[1])<<32;
|
||||
return x;
|
||||
}
|
||||
thrM("•internal.Temp: bad RANDOMIZE_HEURISTICS usage");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NATIVE_COMPILER
|
||||
case 100: {
|
||||
@ -460,10 +489,20 @@ B iKeep_c1(B t, B x) { return x; }
|
||||
B iProperties_c2(B t, B w, B x) {
|
||||
if (w.u!=m_c32(0).u || x.u != m_c32(0).u) thrM("𝕨 •internal.Properties 𝕩: bad arg");
|
||||
i32* rp;
|
||||
B r = m_i32arrv(&rp, 3);
|
||||
B r = m_i32arrv(&rp, 7);
|
||||
rp[0] = sizeof(usz)*8;
|
||||
rp[1] = PROPER_FILLS;
|
||||
rp[2] = EACH_FILLS;
|
||||
rp[3] = 0;
|
||||
#if RANDOMIZE_HEURISTICS
|
||||
rp[3] = 1;
|
||||
#endif
|
||||
rp[4] = 0;
|
||||
#if HEAP_VERIFY
|
||||
rp[4] = 1;
|
||||
#endif
|
||||
rp[5] = DEBUG;
|
||||
rp[6] = TEST_UTILS;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@ -634,11 +634,11 @@ DEBUG_FN void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); }
|
||||
#define MATCH_ERROR_MESSAGES 1
|
||||
#endif
|
||||
|
||||
u64 seed;
|
||||
u64 heuristic_seed;
|
||||
bool heuristic_rand(bool heuristic, bool true_req, bool false_req) {
|
||||
assert(heuristic? true_req : false_req);
|
||||
if (!true_req | !false_req) return heuristic;
|
||||
return wyrand(&seed) & 1;
|
||||
return wyrand(&heuristic_seed) & 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
35
test/run.bqn
35
test/run.bqn
@ -15,6 +15,7 @@ Trim ← {((∨`⌾⌽∧∨`)𝕩≠' ')/𝕩}
|
||||
•Out " update-messages Auto-update error messages in tests"
|
||||
•Out " ignore-messages Don't warn about incorrect error messages"
|
||||
•Out " bin-search Binary search for some property. Next argument should be /[01]*/, with a 1 appended every time the property is matched, and a 0 otherwise"
|
||||
•Out " seed=123 Random seed for tests that care (default=1; seed=u will choose a random seed)"
|
||||
•Exit 0
|
||||
}⍟⊢ (0=≠•args) ∨´ "help"‿"h"‿"?"∊'-'⊸≠⊸/¨•args
|
||||
|
||||
@ -28,8 +29,9 @@ o ← {
|
||||
search ↩ search∾1
|
||||
args ↩ (¬n∨𝕩)/args
|
||||
}⍟(∨´) "bin-search"⊸≡¨ args
|
||||
named ← "run"‿"lint"‿"update-messages"‿"slow"‿"ignore-messages"‿"noerr"‿"heapverify"‿"debug"‿"no-catch"
|
||||
i ← named⊐args
|
||||
|
||||
named ← "run"‿"lint"‿"update-messages"‿"slow"‿"ignore-messages"‿"noerr"‿"heapverify"‿"debug"‿"no-catch"‿"seed"
|
||||
i ← named⊐{𝕩↑˜⊑𝕩⊐'='}¨ args
|
||||
run ⇐ ∨´i=0
|
||||
lint ⇐ ∨´i=1
|
||||
update ⇐ ∨´i=2
|
||||
@ -39,11 +41,22 @@ o ← {
|
||||
heapverify ⇐ ∨´i=6
|
||||
debug ⇐ ∨´i=7
|
||||
noCatch ⇐ ∨´i=8
|
||||
seed ⇐ {
|
||||
⟨⟩: 1;
|
||||
⟨"u"⟩: s←•rand.Range 2⋆31 ⋄ •Out "seed="∾•Repr s ⋄ s;
|
||||
⟨s⟩: •ParseFloat 5↓s
|
||||
} (i=9)/args
|
||||
|
||||
⟨
|
||||
usz
|
||||
properFills
|
||||
eachFills
|
||||
randomizeHeuristics
|
||||
knownHeapverify
|
||||
knownDebug
|
||||
hasTestUtils
|
||||
⟩ ⇐ 32‿0‿0‿0‿0‿0‿0 {(≠𝕨)↑ 𝕩 ∾ (≠𝕩)↓𝕨} {⟨P⇐Properties⟩: @P@; ⟨⟩} •internal
|
||||
|
||||
pr ← 32‿0‿0 {𝕩∾(≠𝕩)↓𝕨} {⟨P⇐Properties⟩: 3↑@P@; ⟨⟩} •internal
|
||||
usz ⇐ 0⊑pr
|
||||
properFills ⇐ 1⊑pr
|
||||
eachFills ⇐ 2⊑pr
|
||||
noerr∨↩ heapverify
|
||||
update∧↩ ¬heapverify
|
||||
files ⇐ (i=≠named)/args
|
||||
@ -148,7 +161,15 @@ Run ← { 𝕊 testname:
|
||||
badCount+↩ 1
|
||||
}
|
||||
ErrMsg ← {𝕊: m←•CurrentError@ ⋄ {1==m? ∧´2=•Type¨m? m; •Repr⎊"(unrepresentable)" m}}
|
||||
Eval ← {⟨dir, ∾⟨testname,"_line_",•Repr currLn+1,".bqn"⟩, ⟨helpers,"arg0",1⟩⟩ •BQN 𝕩}
|
||||
|
||||
PreEval ← ⊢
|
||||
_addPreEval ← {𝕩? PreEval↩PreEval 𝔽; @}
|
||||
{𝕊: 1 •internal.Temp o.seed}_addPreEval o.randomizeHeuristics
|
||||
|
||||
Eval ← {
|
||||
PreEval@
|
||||
⟨dir, ∾⟨testname,"_line_",•Repr currLn+1,".bqn"⟩, ⟨helpers,"arg0",1⟩⟩ •BQN 𝕩
|
||||
}
|
||||
EvalS ← •BQN⎊{𝕊: Bad "Bad comparison value" ⋄ "(bad)"}
|
||||
toRun ← tests
|
||||
toRun {{𝕩.enabled}∘⊑¨⊸/𝕩}↩
|
||||
|
||||
Loading…
Reference in New Issue
Block a user