Here's a short example of a test class:
import tart.collections.ArrayList;import tart.reflect.ComplexType;import tart.testing.Test;@EntryPointdef main(args:String[]) -> int {return ArrayListTest().runTests(ArrayListTest);}class ArrayListTest : Test {def testConstruct() {let a = ArrayList[int](1, 2, 3);assertEq(3, a.length);assertEq(1, a[0]);assertEq(2, a[1]);assertEq(3, a[2]);}def testImplicitType() {let a = ArrayList(1, 2, 3);assertEq(3, a.length);assertEq(1, a[0]);assertEq(2, a[1]);assertEq(3, a[2]);}}
This demonstrates a number of interesting language features:
- Reflection of class methods.
- "import namespace". The 'assertEq' methods are defined in class "Asserts". Class Test does an "import namespace Asserts", which means that all of the assert methods are available without needing a qualifier (i.e. Asserts.assertEq).
The test output looks like this:
[Running] ArrayListTest.testConstruct[Running] ArrayListTest.testImplicitType[OK ]
No comments:
Post a Comment