# Testing BlocklyToSmartPascal

This section contains some of our tests of BlocklyToSmartPascal. You can use the tests as further examples from which to learn. Our demonstrations also form part of our testing, so we include them in our links to examples of the use of each type of block. The blocks are arranged below in the order that they appear in the toolbox.

Our initial aim was to provide at least one working example of each type of block, preferably covering all of the options. You may find that a block needs to operate on a variable rather than on a hard-coded string or number (or vice versa). For example, in Smart Pascal, the instruction `([3,2,4]).sort;` causes the error message 'Syntax Error: Array method "sort" is restricted to dynamic arrays'. It is then up to you to develop a workaround. (We sometimes resort to little workarounds with new commercial software).

Sometimes the generated Smart Pascal code contains unnecessary pairs of parentheses. One of these pairs may be necessary in more complex situations, so we generate them both to be on the safe side. If you see an expression within two matched pairs of parentheses e.g. `intOneEqTwo := if Boolean((1 = 2)) then 10 else -10;`, you can safely remove one of the pairs.

**Logic**- controls-if
- Searching an array
- Displaying Pascal's Triangle (if with else)
- logic_compare
- Searching an array (EQ)
- Demonstration of while loop (EQ and NEQ)
- Testing Boolean blocks (EQ, NEQ, LT, GT, LTE, GTE)
- Displaying Pascal's Triangle
- logic_operation
- Testing Boolean blocks (AND and OR)
- Displaying Pascal's Triangle
- logic_negate
- Testing Boolean blocks
- logic_boolean
- Searching an array (TRUE and FALSE)
- Converting strings to integers
- logic_ternary
- Testing Boolean blocks

**Loops**- controls_repeat_ext
- Simple test of the controls_repeat_ext block
- controls_whileUntil
- Demonstration of while loop (WHILE and REPEAT)
- controls-for
- Searching an array
- Displaying Pascal's Triangle
- controls_forEach
- Searching an array
- controls_flow_statements
- Searching an array (BREAK and CONTINUE)
- Converting strings to integers (BREAK)
- Caesar Cipher (CONTINUE)

**Math**- math_number
- Demonstration of loops
- Converting strings to integers
- math_arithmetic
- Demonstration of loops (MULTIPLY)
- Rounding floats (DIVIDE)
- Generating Smart Pascal code that outputs XML code for a block (MINUS)
- Testing the math_arithmetic, math_trig, math_constant and math_number_property blocks (ADD, MINUS, MULTIPLY, DIVIDE)
- math_single
- Rounding floats (POW10)
- Converting strings to integers (POW10)
- math_trig
- Testing the math_arithmetic, math_trig, math_constant and math_number_property blocks (TAN, SIN, COS, ATAN, ASIN, ACOS)
- Drawing on a Canvas (SIN)
- math_constant
- Testing the math_arithmetic, math_trig, math_constant and math_number_property blocks (E, SQRT2, SQRT1_2, INFINITY, GOLDEN_RATIO)
- math_number_property
- Testing the math_arithmetic, math_trig, math_constant and math_number_property blocks (EVEN, ODD, PRIME, WHOLE, POSITIVE, NEGATIVE)
- math_round
- Rounding floats (ROUND)
- Displaying Pascal's Triangle (ROUND)
- math_on_list
- Sum, maximum and minimum of arrays (SUM, MIN and MAX)
- math_modulo
- Testing the math_constrain, math_modulo and math_random_float blocks
- math_constrain
- Testing the math_constrain, math_modulo and math_random_float blocks
- math_random_int
- Using the random integer block to create a random identifier
- math_random_float
- Testing the math_constrain, math_modulo and math_random_float blocks

**Text**- text
- Demonstration of loops
- text_join
- Testing the creation of strings from hard-coded and variable Integers, Floats and Strings
- Demonstration of loops
- text_append
- Generating Smart Pascal code that outputs XML code for a block
- Testing the lists_reverse, lists_sort and lists_repeat blocks
- text_length
- Testing the text_length, text_isEmpty, text_indexOf and text_getSubstring blocks
- Converting strings to integers
- text_isEmpty
- Testing the text_length, text_isEmpty, text_indexOf and text_getSubstring blocks
- text_indexOf
- Testing the text_length, text_isEmpty, text_indexOf and text_getSubstring blocks (FIRST, LAST)
- Vowel Count (FIRST)
- text_charAt
- Testing the text_charAt block (FIRST, LAST, FROM_START, FROM_END and RANDOM)
- Using the random integer block to create a random identifier (FROM_START)
- text_getSubstring
- Testing the text_length, text_isEmpty, text_indexOf and text_getSubstring blocks (FIRST, LAST, FROM_START, FROM_END)
- Converting strings to integers (FROM_START, LAST)
- text_changeCase
- Searching an array (UPPERCASE)
- Demonstration of while loop (LOWERCASE)
- text_trim
- Testing the text_trim, text_count, text_replace and text_reverse blocks (LEFT, RIGHT and BOTH)
- text_count
- Testing the text_trim, text_count, text_replace and text_reverse blocks
- Vowel Count
- text_replace
- Testing the text_trim, text_count, text_replace and text_reverse blocks
- text_reverse
- Testing the text_trim, text_count, text_replace and text_reverse blocks
- text_print
- Demonstration of loops
- Generating Smart Pascal code that outputs XML code for a block
- Testing the lists_reverse, lists_sort and lists_repeat blocks
- text_prompt_ext
- Searching an array
- Converting strings to integers

**Lists**- lists_create_with
- Testing the creation of arrays
- lists_repeat
- Testing the lists_reverse, lists_sort and lists_repeat blocks
- lists_length
- Testing the lists_indexOf, lists_getIndex, lists_setIndex, lists_length and lists_getSublist blocks
- Generating Smart Pascal code that outputs XML code for a block
- lists_isEmpty
- Testing the creation of arrays
- lists_indexOf
- Testing the lists_indexOf, lists_getIndex, lists_setIndex, lists_length and lists_getSublist blocks (FIRST, LAST)
- lists_getIndex
- Generating Smart Pascal code that outputs XML code for a block (GET FROM_START)
- Testing the lists_indexOf, lists_getIndex, lists_setIndex, lists_length and lists_getSublist blocks (GET FROM_START, REMOVE FROM_END)
- Testing random selection of array element (RANDOM GET and RANDOM GET_REMOVE)
- Testing the removal of the first array element (GET_REMOVE and REMOVE FIRST)
- lists_setIndex
- Testing the lists_indexOf, lists_getIndex, lists_setIndex, lists_length and lists_getSublist blocks (INSERT FROM_START)
- lists_getSublist
- Testing the lists_indexOf, lists_getIndex, lists_setIndex, lists_length and lists_getSublist blocks (FROM_START, LAST)
- Subarrays, combining arrays, array sorting and converting arrays to text (FROM_START)
- lists_split
- Searching an array (SPLIT)
- Testing the lists_indexOf, lists_getIndex, lists_setIndex, lists_length and lists_getSublist blocks (SPLIT)
- Converting an Array to Text (SPLIT and JOIN)
- lists_sort
- Subarrays, combining arrays, array sorting and converting arrays to text
- Testing the creation of arrays (NUMERIC -1: descending)
- Testing the lists_reverse, lists_sort and lists_repeat blocks (TEXT 1: ascending, IGNORE_CASE 1: ascending)
- lists_reverse
- Testing the lists_reverse, lists_sort and lists_repeat blocks

**Variables**- variables_set
- Testing the creation of strings from hard-coded and variable Integers, Floats and Strings
- Displaying Pascal's Triangle
- math_change
- Vowel Count
- Combining Arrays

**Functions**- procedures_defnoreturn
- Demonstrations of BlocklyToSmartPascal
- Displaying Pascal's Triangle
- procedures_defreturn
- Rounding floats
- Generating Smart Pascal code that outputs XML code for a block
- Displaying Pascal's Triangle
- procedures_callnoreturn
- Demonstrations of BlocklyToSmartPascal
- Displaying Pascal's Triangle
- procedures_callreturn
- Generating Smart Pascal code that outputs XML code for a block
- Displaying Pascal's Triangle

Follow the numbered links for full details of some tests.