Skip to content

ndrogers/apltest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APLTEST

A simple test reporting tool with examples. For complete example usage see ./meta_test.aplf as it runs every possible combination of the test function.

Additional Resources:

The comments in the source files are to be considered additional documentation, and kept up to date before any push. To learn more about the implementation, please read the comments as a stand alone documentation source.

Usage

To use this project:

    ]link.create # 'path/to/apltest' 
Linked: #  path/to/apltest

The entry point to this test reporting tool is ./test.aplf

To execute all test cases in this project:

  #.examples test 

┌──────────┬───┬──────┬──────┬─────┬───────────────────────────────────────────────────────────────────┐
│AOC2015RANPASSEDFAILEDERRORREPORT                                                             │
├──────────┼───┼──────┼──────┼─────┼───────────────────────────────────────────────────────────────────┤
│s035140    │┌───────────┬───────────┬───────────┬───────────┐                  │
│          │   │      │      │     ││   Input: 1Input: 1Input: 1Input: 1│                  │
│          │   │      │      │     │├───────────┼───────────┼───────────┼───────────┤                  │
│          │   │      │      │     ││Expected: 5Expected: 6Expected: 7Expected: 8│                  │
│          │   │      │      │     │├───────────┼───────────┼───────────┼───────────┤                  │
│          │   │      │      │     ││     Got: 2Got: 2Got: 2Got: 2│                  │
│          │   │      │      │     │└───────────┴───────────┴───────────┴───────────┘                  │
├──────────┼───┼──────┼──────┼─────┼───────────────────────────────────────────────────────────────────┤
│TOTALS171340FAILED: s03                                                        │
├──────────┼───┼──────┼──────┼─────┼───────────────────────────────────────────────────────────────────┤
│AOC2016RANPASSEDFAILEDERRORREPORT                                                             │
├──────────┼───┼──────┼──────┼─────┼───────────────────────────────────────────────────────────────────┤
│TOTALS1100PASS                                                               │
├──────────┼───┼──────┼──────┼─────┼───────────────────────────────────────────────────────────────────┤
│FAIL_DEMORANPASSEDFAILEDERRORREPORT                                                             │
├──────────┼───┼──────┼──────┼─────┼───────────────────────────────────────────────────────────────────┤
│will_error2022    │┌────────────────────┬────────────────────┐                        │
│          │   │      │      │     ││   Input: 1Input: 3         │                        │
│          │   │      │      │     │├────────────────────┼────────────────────┤                        │
········································································································
├──────────┼───┼──────┼──────┼─────┼───────────────────────────────────────────────────────────────────┤
│TOTALS7072FAILED: will_error,will_fail                                       │
└──────────┴───┴──────┴──────┴─────┴───────────────────────────────────────────────────────────────────┘      

Legal arguments to test

RESULT Example
Perform test ⍬ inside namespace ⍺. For each namespace in ⍺, run every dfn with their corresponding test cases. namespace #.examples test ⍬
Run every dfn defined in each namespace in # with their corresponding test cases test ⍬
Run every defn defined in ⍵ with their corresponding test cases namespace test #.aoc2015
Run the dfns ⍵ defined in ⍺ namespace nested charvec #.aoc2015 test 's01' 's02
Run dfn ⍵ in ⍺ namespace charvec #.aoc2015 test 's01'

Defining tests and test cases

Create a new file named ./examples/my_namespace.apln containing:

:Namespace my_namespace
    
:EndNamespace

Inside that namespace, define a function, and a corresponding test case. Test cases are identified by appending _tests to the name of a given function.

my_fn{}

my_fn_tests

This test will not execute because there are no test cases, and my_fn returns no results so calling it will probably result in an error.

To defined the first case, change the values to the following:

my_fn{+/}

my_fn_tests(1 1)

But this will not work correctly, returning that 2 tests passed. Test cases must be defined as a nested vector, so if there is a single test case define it as follows:

my_fn{+/}

my_fn_tests,(1 1)

Usually more than 1 test case per dfn will be defined, so to add a few more:

my_fn{+/}

my_fn_tests(1 1) ((1 2) 3) ((2 4) 8) ((2 8 20) 30)

Notice that the new test cases contain a tuple of arguments. Each cell is a tuple containing strictly 2 values. First is the input, second is the expected result. In the first test case, our input is 1, and our expected result is 1. In the last case, our input is 2 8 20 and our expected result is 30

Now call test to run all tests in our new namespace:

      test #.examples.my_namespace
┌───────────────────────┬───┬──────┬──────┬─────┬───────────────┐
│#.EXAMPLES.MY_NAMESPACERANPASSEDFAILEDERRORREPORT         │
├───────────────────────┼───┼──────┼──────┼─────┼───────────────┤
│my_fn4310    │┌─────────────┐│
│                       │   │      │      │     ││   Input: 2 4││
│                       │   │      │      │     │├─────────────┤│
│                       │   │      │      │     ││Expected: 8  ││
│                       │   │      │      │     │├─────────────┤│
│                       │   │      │      │     ││     Got: 6  ││
│                       │   │      │      │     │└─────────────┘│
├───────────────────────┼───┼──────┼──────┼─────┼───────────────┤
│TOTALS4310FAILED: my_fn  │
└───────────────────────┴───┴──────┴──────┴─────┴───────────────┘

OOPS! Looks like one of the test cases failed. The function didn't fail however, the test case is poorly defined because 8 ≠ +/ 2 4. In this case rather than modifying my_fn, ensure the test cases are correct by either changing the expected result or the arguments.

my_fn{+/}

my_fn_tests(1 1) ((1 2) 3) ((2 4) 6) ((2 8 20) 30)

Now if the test is run, the same results are produced. To run test cases for a single dfn, the following argument form for test is valid:

      #.examples.my_namespace test 'my_fn'
┌───────────────────────┬───┬──────┬──────┬─────┬──────┐
│#.EXAMPLES.MY_NAMESPACERANPASSEDFAILEDERRORREPORT│
├───────────────────────┼───┼──────┼──────┼─────┼──────┤
│TOTALS4400PASS  │
└───────────────────────┴───┴──────┴──────┴─────┴──────┘

In this specific instance, the results of ns test 'fn' and test ns are the same because there is only 1 dfn in #examples.my_namespace. But as more test cases and dfns are added, use test ns to run all of them, or ns test 'fn' to run a select test.

      {(test ⍵)≡⍵ test'my_fn'}#.examples.my_namespace
1

Precautions

  • At present, this framework only allows for dfns accepting a right argument. The framework also presently only tests dfns defined in the provided namespace, and does not recursively check for more nested namespaces to test.

  • Errors caused by function execution are trapped, so any embedded error handling won't be handled or tested.

  • No mocking is provided. Any dfn that requires user interaction, or anything depending on outside data isn't guaranteed.

TODO:

  • config.apln should be used to house user configuration of the test suite. Config.apl should be its own source of documenation, containing options and potential configuration of results.

About

simple test suite

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published