feat: random generators, frozenset and __hash__/__iter__/__getitem__/__contains__ in Ren'Py python
renpy.random/random get choices, sample, randrange and Random(seed); frozenset, iter and hash are builtins. User classes may define __hash__ (dict keys), __iter__, __getitem__ and __contains__; the converter accepts them instead of rejecting the whole class, which removes the Perk/Skill/Status wall in SaintlyCorruption. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f9eb5c1212
commit
e1c596288e
8 files changed
+165
-18
No files matched your search
@@ -73,3 +73,19 @@ test("an animated preview discarded before its first timer does not keep renderi
|
||||
assert.equal(rendered, 1);
|
||||
} finally { engine.destroy(); }
|
||||
});
|
||||
|
||||
test("random generators: choices, sample, seeded Random and frozenset", () => {
|
||||
const { engine } = makeEngine(runtime());
|
||||
try {
|
||||
engine.newStore();
|
||||
const { renpy, frozenset } = engine.builtins;
|
||||
assert.deepEqual(frozenset([1, 2, 2, 3]), [1, 2, 3]);
|
||||
const picked = renpy.random.choices(["a", "b"], { __kw: { weights: [0, 1], k: 5 } });
|
||||
assert.deepEqual(picked, ["b", "b", "b", "b", "b"]);
|
||||
const sample = renpy.random.sample([1, 2, 3, 4], 3);
|
||||
assert.equal(new Set(sample).size, 3);
|
||||
const first = renpy.random.Random("seed"), second = renpy.random.Random("seed");
|
||||
assert.deepEqual([first.randint(1, 1000), first.randint(1, 1000)], [second.randint(1, 1000), second.randint(1, 1000)]);
|
||||
assert.ok(renpy.random.randrange(0, 10, 5) % 5 === 0);
|
||||
} finally { engine.destroy(); }
|
||||
});
|
||||
Reference in new issue
Block a user