вторник, 13 октября 2015 г.

#845. ToDo. Tests for script words

Original in Russian: http://programmingmindstream.blogspot.ru/2015/06/todo_27.html
Something like this:

operator EVAL
// - operator to calculate the value of aWhat
 RIGHT IN aWhat
 aWhat |^ DO
; // EVAL 
 
 EVAL %Tests 'tests for operator EVAL'
 (
 // - tests for operator EVAL
  : T1
   EVAL 1 PrintStack
  ; // T1
 
  : T2
   EVAL '2' PrintStack
  ; // T2
 
  : T3
   VAR X
   X := 1
   EVAL X PrintStack
  ; // T3
 
  : T4
   EVAL ( 123 456 ) PrintStack
  ; // T4
 
  : T5
   EVAL ( 123 456 + ) PrintStack
  ; // T5
 
  : T6
   EVAL ( 1 2 + ) == 3 ASSERTS
  ; // T6
 
  : T7
   EVAL ( 'A' 'B' Cat ) == 'AB' ASSERTS
  ; // T7
 
 ) // EVAL %Tests

We get the tests subtree in DUnit:

EVAL are the tests for operator EVAL
 T1
 T2
 T3
 T4
 T5
 T6
 T7

My “paranoia”:

+ %Tests 'Tests for operator +'
(
 : T1
  1 2 + == 3 ASSERT
 ; // T1
 
 : T2
  1 -2 + == -1 ASSERT
 ; // T2
 
 : T3
  VAR A A := 1
  VAR B B := 2
  A B + == 3 ASSERT
 ; // T3
 
 : T4
  VAR A A := 1
  VAR B B := 2
  VAR C C := 3
  A B + == C ASSERT
 ; // T4
 
) // + %Tests

We get the tests subtree in DUnit:

+ - Tests for operator +
 T1
 T2
 T3
 T4

ARRAY %Tests ' Tests for operator ARRAY'
(
  : T1
   [ ] PrintStack
  ; // T1
 
  : T2
   [ 1 2 ] PrintStack
  ; // T2
 
  : T3
   [ 1 2 3 ] PrintStack
  ; // T3
 
  : T4
   [ 1 2 3 ] Revert PrintStack
  ; // T4
 
  : T5
   [ 1 2 2 3 1 3 5 6 7 ] RemoveDup PrintStack
  ; // T5
 
  : T6
   ARRAY VAR A
   A := [ 1 2 2 3 1 3 5 6 7 ] 
   A RemoveDup PrintStack
  ; // T6
 
  : T7
   ARRAY VAR A
   A := [ 1 2 2 3 1 3 5 6 7 ] 
   A RemoveDup ==> Print
  ; // T7
 
) // ARRAY %Tests

I hope you understand my idea.

We have the functionality and the “atomic tests” for it.

I believe this is not a new idea.

As for me, it is fun. The key point is that I’ve almost implemented it, I only need to register it in DUnit.

I need to register it in ANY application that contains these words and DUnit and I will get a separate branch of tests for the words.

%Tests looks as follows:
VOID operator %Tests
 LEFT IN aWord
 RIGHT IN aDoc
 RIGHT IN aTests
 
 VAR l_Group
 
 DUnit:AddTestsGroup aWord aDoc >>> l_Group
 
 aCode MembersIterator ==> ( IN aTest
  l_Group DUnit:TestsGroup:AddTest aTest
 )
; // %Tests

We can go further:

'TControl' RTTIObject %Tests 'Tests for class TControl'
(
 : T1
  OBJECT VAR l_Control
  'TControl' RTTIClass 'Create' RTTIConstructor RTTIExecute [ nil { - This is the Owner} ] >>> l_Control
  CONST cName 'MyControl'
  'TControl' RTTIClass 'Name' RTTIProperty l_Control RTTISet [ cName { - This is the Name value} ]
  STRING VAR l_Name
  'TControl' RTTIClass 'Name' RTTIProperty l_Control RTTIGet >>> l_Name
  l_Name == cName ASSERT
 ; // T1
)

Комментариев нет:

Отправить комментарий