public void TestUniformity_InUnitCircle() { var rng = new StatelessRng(kSeed); // Parametrization based on polar coords Func <Vector2, Vector2?> Parametrize = cartesian => { float radius = cartesian.magnitude; if (radius == 0) { return(null); } // cdf = cumulative distribution function ~= "area under" // area of cirle of radius "mag" relative to area of entire circle // to make uniform, compute cdf(var) / cdf (total) = mag^2 / 1^2 float radiusUniform = radius * radius; // area increases linearly with angle01, so just need to rescale to [0,1) float angle = Mathf.Atan2(cartesian.y, cartesian.x); float angleUniform = ToAngle01(angle); return(new Vector2(angleUniform, radiusUniform)); }; S.CheckUniformity(new[] { "theta", "rr" }, Gen(i => Parametrize(rng.InUnitCircle(i)))); }
public void TestForSaltReuse() { var seen = new HashSet <int>(); var rng = new StatelessRng(kSeed); StatelessRng.SaltUsed = (salt) => { Assert.IsTrue(seen.Add(salt), "Salt {0} is unused", salt); }; try { rng.OnUnitCircle(0); seen.Clear(); rng.InUnitCircle(0); seen.Clear(); rng.OnUnitSphere(0); seen.Clear(); rng.InUnitSphere(0); seen.Clear(); rng.Rotation(0); seen.Clear(); } finally { StatelessRng.SaltUsed = null; } }
public void TestCheckUniformity() { var rng = new StatelessRng(kSeed); Func <Vector2, Vector2?> Parametrize = v => new Vector2((v.x + 1) / 2, (v.y + 1) / 2); Assert.Throws <AssertionException>(() => S.CheckUniformity(new[] { "x", "y" }, Gen(i => Parametrize(rng.InUnitCircle(i))))); }