From a1bad11403e3c2da0b7563d440098b3ebdd3af83 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 30 May 2021 21:49:34 -0400 Subject: Begin writing fuzz tester, mostly shape generation --- test/fuzz.bqn | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/fuzz.bqn (limited to 'test') diff --git a/test/fuzz.bqn b/test/fuzz.bqn new file mode 100644 index 00000000..1bc10213 --- /dev/null +++ b/test/fuzz.bqn @@ -0,0 +1,59 @@ +# Tester that checks primitives on random arguments + +# Linear congruential RNG; result in ↕2⋆16 +rr ← 2⋆16 # Random range +_makeRand ← {st←𝕗 + d‿m←2⋆15‿31 + {𝕤⋄ d ⌊∘÷˜ st ↩ m|2531011+214013×st } +} +RandGen ← 1234 _makeRand +Rand ← { 𝕩 | 0 rr⊸×⊸+˜´ RandGen¨↕⌈rr⋆⁼𝕩 }∘(1⊸⌈)⚇0 +_randChoose ← { Rand∘(≠𝕗)◶𝕗 } + +# Prime factorization +⟨Factor⟩ ← { + p ← (¬∘∊/⊣)⟜(⥊×⌜˜)2↓↕m←60 + Pr ← {m<𝕩}◶{𝕩↑p}‿{ m↩(טm)⌊2×𝕩 ⋄ p∾↩1↓/1(m⥊0<↕)⊸∧´p ⋄ Pr 𝕩 } + Factor ⇐ { + !(1=•Type𝕩)∧(𝕩=⌊𝕩)∧0<𝕩 + ∧ 𝕩 {(0<≠∘⊢)◶⟨⥊⊣,⊢∾𝕊⟩⍟(>⟜1)˜⟜(𝕨÷×´)𝕩/˜0=𝕩|𝕨} Pr ⌈√𝕩 + } +} + +Sigmoid ← (40≤|)◶⟨1(-÷+)˜⋆,×⟩ + +# 𝕩 is maximum bound plus 1 for both functions +⟨RandBound,RandShape⟩ ← { + RandBound ⇐ ⟨ + Rand # Uniform + Rand 128⊸⌊ # Small + -⟜1 ⌊ Rand∘(1⌈⌈)⌾((2⋆3+⊢)⁼) + ¯7+Rand∘15 # Near power of two + ⟩_randChoose + + RandRank ← { 𝕊⊸+⍟(1=-)⟜Rand 4 } + + Augment ← { + d ← 1+⌊𝕨÷1⌈×´𝕩 # Maximum bound that can be added, plus 1 + C ← 10⊸+ Rand⊸< 1.2⊸√ # Decide whether to add + d (𝕨 𝕊 ⟨∾,∾˜⟩_randChoose⟜RandBound˜)⍟(C⊣) 𝕩 + } + Combine ← ⟨ + Rand∘≠⊸⌽ (2+Rand∘≠)⊸{×´¨𝕨↑(𝕨|↕∘≠)⊸⊔𝕩}∘⊢ # Random number of groups + ×´¨ (⊐·Rand⥊˜∘≠)⊸⊔∘⊢ # Distribute randomly + ⟩_randChoose + RandShape ⇐ ⊢ Augment ⟨ + ⊢ (⊢ ⌊∘× ⊢ ≠⊸√ (Sigmoid⊸÷1⌈×´⊸÷˜)) · Rand¨ (RandRank⌈√