Libraryless. Click here for Pure Java version (25414L/155K).
scope test_PStack /* Goal: Allow probabilistic branching deep within nested function calls Like this, to return 4 different values: S color = "black" with probability 0.75 or "white" with probability 0.25; S shape = "circle" with probability 0.4 or "square" with probability 0.6; return "A " + color + " " + shape; */ sclass #C1 extends PStackComputableWithStep<S> { S color; public void step(IPStack stack) { if (step == 0) { ++step; stack.options(this, ll( o -> o.color = "red", o -> o.color = "green")); } else stack.ret(color); } } please include function test_BStack. svoid test_PStack() { test_PStack_oneBranch(); test_PStack_twoBranches(); test_PStack_oneBranch3Options(); test_PStack_twoBranches3Options(); test_PStack_noOptions(); } svoid test_PStack_oneBranch() { assertEqualsVerbose( ll("Color is black", "Color is white"), pstackComputeAll(new test_BStack_OneBranch)); } svoid test_PStack_oneBranch3Options() { assertEqualsVerbose( ll("Color is black", "Color is white", "Color is gray"), pstackComputeAll(new test_BStack_OneBranch3Options)); } svoid test_PStack_twoBranches() { assertEqualsVerbose( ll("A black circle", "A black square", "A white circle", "A white square"), pstackComputeAll(new test_BStack_TwoBranches)); } svoid test_PStack_twoBranches3Options() { assertEqualsVerbose( ll("A black circle", "A black square", "A black triangle", "A white circle", "A white square", "A white triangle", "A gray circle", "A gray square", "A gray triangle"), pstackComputeAll(new test_BStack_TwoBranches3Options)); } svoid test_PStack_noOptions() { assertInnerExceptionOfTypeVerbose(PStack.NoOptionsException.class, -> pstackComputeAll(new test_BStack_NoOptions)); }
Began life as a copy of #1035397
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035428 |
Snippet name: | test_PStack (OK) |
Eternal ID of this version: | #1035428/5 |
Text MD5: | 14bdfcb42edf4a7280f05e81f3a9c61f |
Transpilation MD5: | daf30db31239a6388630dc4776c01b7e |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-08 21:06:39 |
Source code size: | 1894 bytes / 68 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 144 / 230 |
Version history: | 4 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |