Assert object

Available from version 5.3.5.

In AskiaScript, the assert object is a predefined object that contains static methods and properties to validate an AskiaScript expression. It is used you are testing the validity of collected interview data with AskiaTools' verification script feature. Each assert condition is a test of the data; when the script is run, a message is logged for each of these conditions that was not satisfied. The assert statement is within the global scope.

Methods

AddContext(question[, prefix])

In AskiaTools' verification script window, this keyword adds an extra Context column, containing the answer of the specified question. It can help you understand on which condition an assert failed (or succeeded).

Returns the Assert object (for the call chain).

Parameters
Example
Assert.AddContext( Gender ).AddContext( Age ,"Age=")
Assert.Check(Gender = 1 and Age < 18, "Expected all males above 18 years old")

The above script produces the following output:

Interview ID Assert Context 1 Context 2
1 1 Expected all males above 18 years old Man 17
2 2 Expected all males above 18 years old Man 12
3 3 Expected all males above 18 years old Man 15

 

 

 

 

 

↑ Top of page ↑

Check(expression, message)

Evaluate the AskiaScript expression as a Boolean value.

If the value of the expression evaluates as true, then the assert succeeds and returns true.

Returns a Boolean value.

Parameters
Examples
If Country has {1} Then
   Assert.Check(Language has {1}, "When country is 'UK', 'English' language should be selected, but was {%= Country.Answers[1].Caption%}")
EndIf
'
' Example output:
' "When contry is 'UK', 'English' language should be selected, but was 'French'"
If Country has {1} Then
   Assert.Check(Q1.HasNA, "If 'UK', Q1 must be skipped, but was ask")
EndIf
Assert.Check(Q2.Responses[3].IsIgnored, "The third response of Q2 should be ignored")
' Use the return value of assert
If Gender Has {1} Then
   If Assert.Check(AgeRecod.HasNA, "AgeRecod must be skipped for 'man') Then
      If Age < 26 Then
       Assert.Check(AgeRecord Has {1}, "AgeRecod must be 'Less than 25' when Age < 25, but was {%= AgeRecord.Answers[1].Caption%}")
      Else If Age < 46 Then
       Assert.Check(AgeRecord Has {2}, "AgeRecod must be '25-45' when Age < 46, but was {%= AgeRecord.Answers[1].Caption%}")
      Else
       Assert.Check(AgeRecord Has {3}, "AgeRecod must be 'Greater 45' when Age > 45, but was {%= AgeRecord.Answers[1].Caption%}")
      EndIf
   EndIf
EndIf

 

↑ Top of page ↑

ResetContext()

After adding a context using Assert.AddContext(), this method clears it. You can then add a new context for a different assert.

Returns the Assert object (for the call chain).

Example
Assert.AddContext( Gender ).AddContext( Age ,"Age=")
Assert.Check(Gender = 1 and Age < 18, "Expected all males above 18 years old")

Assert.ResetContext() ' <= Reset the previous context

Assert.AddContext( Profession ).AddContext(Age, "Not allowed age=")
Assert.Check(Profession has {12} and Age < 55, "Expected all retired above 55 years old")

The above script produces the following output:

Interview ID Assert Context 1 Context 2
1 1 Expected all males above 18 years old Man Age=17
2 2 Expected all males above 18 years old Man Age=12
3 3 Expected all males above 18 years old Man Age=15
4 4 Expected all retired above 55 years old Retired Not allowed age=10
8 8 Expected all retired above 55 years old Retired Not allowed age=45
12 12 Expected all retired above 55 years old Retired Not allowed age=35

 

 

 

 

 

 

 

 

↑ Top of page ↑

ToString()

Returns a string which represents the current Assert object.

Returns a String.

Example
Assert.ToString() ' => <Assert::123456> 
' (TODO::Probably have to be improved or 
' done differently like XML or JSON format)

↑ Top of page ↑

TypeOf()

Always returns "assert".

Returns a String.

Example
Assert.TypeOf() ' => "assert" 

↑ Top of page ↑

Create your own Knowledge Base