Ludwig.Test

Module Members

assertion

(Function)

Create a unit Test without an expected value by asserting a fact about the value.

Example:

test1: Test.assertion{ name: “Multiply by two is even”, actual: 2*2, expectedMsg: “an even number”, property: fun(x): (x % 2) == 0 }

Type Signature

 fun { name: String,
       actual: a,
       expectedMsg: String,
       property: fun (a) -> Bool} -> Test
Argument: name

The heading printed in the test output.

Type: String

Argument: actual

The value to compute for the test.

Type: a

Argument: expectedMsg

The message to print desribing the expected value if the test fails.

Type: String

Argument: property

The comparison function used to test the actual value.

Type: fun ( a) -> Bool

Returns:

Test Unit test value for use as an input to Test.group.

Type: Test

group

(Function)

Create a test group from a list of tests.

Example:

group1: Test.group{
  name: "Example group",
  tests: [
    Test.unit{ name: "multiply", actual: 2*2, expected: 4 },
    Test.unit{ name: "add", actual: 2+2, expected: 4 }
  ]
}

Type Signature

 fun { name: String,
       tests: List<Test> } -> Test
Argument: name

The heading printed at the top of the output.

Type: String

Argument: tests

The Tests to group together.

Type: List<Test>

Returns:

Test group for use as an input to Test.run.

Type: Test

run

(Function)

Execute a list of tests.

Example:

results: Test.run{
  name: "Simple test",
  tests: [
    Test.group{
      name: "Example group",
      tests: [
        Test.unit{ name: "multiply", actual: 2*2, expected: 4 },
        Test.unit{ name: "add", actual: 2+2, expected: 4 }
      ]
    }
  ]
}

# Simple test
# Example group
#   multiply: OK
#   add: OK
# 0 out of 2 failed

Type Signature

 fun { tests: List<Test>,
       name: Optional<String> } -> 0-tuple
Argument: tests

The Tests to test.

Type: List<Test>

Argument: name

The heading printed at the top of the output.

Type: Optional<String>

Returns:

() Pretty prints the test results to stderr.

Type: 0-tuple

true

(Function)

Create a unit Test, verifying that something is ‘True’.

Example:

test1: true{ value: List.isEmpty([]), name: "empty list is empty"}

Type Signature

 fun { name: String,
       value: Bool} -> Test
Argument: name

The heading printed in the test output.

Type: String

Argument: value

The value that should be true.

Type: Bool

Returns:

Test Unit test value for use as an input to Test.group.

Type: Test

unit

(Function)

Create a unit Test.

Example:

test1: Test.unit{ name: "multiply", actual: 2*2, expected: 4 }

Type Signature

 fun { name: String,
       actual: a,
       expected: a,
       comparison: Optional<fun (a, a) -> Bool> } -> Test
Argument: name

The heading printed in the test output.

Type: String

Argument: actual

The value to compute for the test.

Type: a

Argument: expected

The expected value for the test.

Type: a

Argument: comparison

The comparison function used to compare the actual and expected. Default is ==.

Type: Optional<fun (a, a) -> Bool>

Returns:

Test Unit test value for use as an input to Test.group.

Type: Test

Test

(Type)

type Test:
  | Test
      isFail: Bool
      message: Doc
  | Group
      name: Doc
      tests: List<Test>

Group

(Constructor)

Argument:

Record {

Field: name
Type: Doc
Field: tests
Type: List<Test>

}

Test

(Constructor)

Argument:

Record {

Field: isFail
Type: Bool
Field: message
Type: Doc

}