6.1.1200 DEPTH CORE

( -- +n )

+n is the number of single-cell values contained in the data stack before +n was placed on the stack.

Testing:

T{ 0 1 DEPTH -> 0 1 2 }T
T{   0 DEPTH -> 0 1   }T
T{     DEPTH -> 0     }T

ContributeContributions

MatteoVitturiavatar of MatteoVitturi [207] More general TestcaseSuggested Testcase2021-08-18 13:39:23

Hello all,

I was testing with Annex F Test Suite and got some unexpected error messages on the DEPTH testcases.

T{ 0 1 DEPTH -> 0 1 2 }T
T{   0 DEPTH -> 0 1   }T
T{     DEPTH -> 0     }T

After some investigation, I realized that this is due to how the Test Harness is built, since current DEPTH testcases relies on an empty-stack, but that may not be always true.

To get around this ambiguity, I used the very same Test Suite's START-DEPTH variable to adjust the value DEPTH returns.

T{  0 1 DEPTH   START-DEPTH @ -   ->  0 1 2  }T
T{  0   DEPTH   START-DEPTH @ -   ->  0 1    }T
T{      DEPTH   START-DEPTH @ -   ->  0      }T
\ or / and
T{  0 1 DEPTH   ->  0 1 2  START-DEPTH @ +   }T
T{  0   DEPTH   ->    0 1  START-DEPTH @ +   }T
T{      DEPTH   ->      0  START-DEPTH @ +   }T

I think the power of the test isn't decreased by this amendment.

_Matteo

MitraArdronavatar of MitraArdron

I hit a similar problem and think it would be better not to depend on START-DEPTH instead

T{  DEPTH DEPTH - -> -1 }T
T{  DEPTH  0 SWAP DEPTH  -  ->  0 -1    }T
T{ DEPTH 0 1 ROT DEPTH -   ->  0 1 -2      }T

MatteoVitturiavatar of MatteoVitturi

@MitraArdron : I agree with you ! I've tried your suggestions and I have to say the last two don't work because the final negative literal is one off. They should be:

T{  DEPTH  0 SWAP DEPTH  -  ->  0 -2    }T
T{  DEPTH 0 1 ROT DEPTH -   ->  0 1 -3      }T

Then, following your method, I would add some more:

T{  DEPTH 9 8  ->  9 8 DEPTH 2 - ROT ROT  }T
T{  DEPTH 9    ->  9   DEPTH 1 - SWAP     }T
T{  9 DEPTH    ->  DEPTH 9 SWAP  1 +      }T
T{  9 8 DEPTH  ->  DEPTH 9 8 ROT 2 +      }T

AntonErtlavatar of AntonErtl

The original Hayes tester assumed that each test case was called with an empty stack (and did not work as intended when it was not). One of the improvements of the ttester (T{ ... }T) was that it would also work if a test starts with a non-empty stack. Of course for Hayes' test cases for DEPTH, the test cases themselves require that the test case is invoked with an empty stack.

There is no standard way to test that DEPTH returns the absolute depth. Both suggested approaches for testing whether DEPTH works correctly for relative depths are ok; the latter approach is preferable because understanding it does not require intimate knowledge of the testing framework. Thank you both.

Reply New Version