Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

63
LINES

< > BotCompany Repo | #1035399 // test_BStack_v3 (OK)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (24992L/152K).

scope test_BStack_v3

please include function test_BStack.

/* Goal: Java code with backtracking, like this, to return 4 different values:

  S color = "black" or "white";
  S shape = "circle" or "square";
  return "A " + color + " " + shape;
*/

svoid test_BStack_v3() {
  test_BStack_v3_oneBranch();
  test_BStack_v3_twoBranches();
  test_BStack_v3_undos();
  test_BStack_v3_oneBranch3Options();
  test_BStack_v3_twoBranches3Options();
  test_BStack_v3_noOptions();
}

svoid test_BStack_v3_oneBranch() {
  assertEqualsVerbose(
    ll("Color is black", "Color is white"),
    new BStackComputeAllWithPrintStruct(new BStack_v3, new test_BStack_OneBranch)!);
}

svoid test_BStack_v3_oneBranch3Options() {
  assertEqualsVerbose(
    ll("Color is black", "Color is white", "Color is gray"),
    new BStackComputeAllWithPrintStruct(new BStack_v3, new test_BStack_OneBranch3Options)!);
}

svoid test_BStack_v3_twoBranches() {
  assertEqualsVerbose(
    ll("A black circle", "A black square",
      "A white circle", "A white square"),
    new BStackComputeAllWithPrintStruct(new BStack_v3, new test_BStack_TwoBranches)!);
}

svoid test_BStack_v3_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"),
    new BStackComputeAllWithPrintStruct(new BStack_v3, new test_BStack_TwoBranches3Options)!);
}

svoid test_BStack_v3_undos() {
  new LS things; // list that is changed during execution to test the undos
  
  var stack = new BStack_v3<>(new test_BStack_TwoBranchesWithUndos(things));
  for (S color : ll("black", "white"))
    for (S shape : ll("circle", "square")) {
      assertEqualsVerbose("A \*color*/ \*shape*/", stack.nextResultWithPrintStruct(10));
      assertEqualsVerbose(ll(color, shape), things);
      stack = stack.backtrack();
    }
  assertNull(stack);}

svoid test_BStack_v3_noOptions() {
  assertInnerExceptionOfTypeVerbose(BStack_v3.NoOptionsException.class,
    -> new BStackComputeAllWithPrintStruct(new BStack_v3, new test_BStack_NoOptions)!);
}

Author comment

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: #1035399
Snippet name: test_BStack_v3 (OK)
Eternal ID of this version: #1035399/3
Text MD5: 9c63ba0fecbd98d11e67617969be435f
Transpilation MD5: b013b90eb1f6da0c552c2cb19c2da6a3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-08 15:57:46
Source code size: 2204 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 183
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)