mirror of
https://github.com/google/blockly.git
synced 2026-01-06 16:40:07 +01:00
feat!: delete angle, colour, and multiline input fields and blocks (#7932)
* chore: delete mocha tests for angle field * feat! : delete angle field * chore(tests): delete colour tests from generator tests and golden files * chore: delete colour blocks and associated generators * chore: remove colour blocks from playgrounds * chore: delete mocha tests for colour fields * chore: fix incorrect comment * chore: delete colour field from core * chore: delete multiline input tests from generators tests and golden files * chore: delete multiline text block and associated generators * chore: remove multiline text block from playgrounds * chore: delete mocha tests for multiline input field * chore: delete multiline input field from core
This commit is contained in:
@@ -1,318 +0,0 @@
|
||||
<xml xmlns="https://developers.google.com/blockly/xml">
|
||||
<block type="procedures_defnoreturn" x="260" y="14">
|
||||
<field name="NAME">test colour picker</field>
|
||||
<comment pinned="false" h="80" w="160">Describe this function...</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">static colour</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="colour_picker">
|
||||
<field name="COLOUR">#ff6600</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">#ff6600</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="630" y="13">
|
||||
<field name="NAME">test rgb</field>
|
||||
<comment pinned="false" h="80" w="160">Describe this function...</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">from rgb</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="colour_rgb" inline="false">
|
||||
<value name="RED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="GREEN">
|
||||
<block type="math_number">
|
||||
<field name="NUM">40</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BLUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">#ff6600</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="unittest_main" x="-5" y="49">
|
||||
<field name="SUITE_NAME">Colour</field>
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test colour picker"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test blend"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test rgb"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test colour random"></mutation>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="-7" y="223">
|
||||
<field name="NAME">test colour random</field>
|
||||
<comment pinned="false" h="80" w="160">Describe this function...</comment>
|
||||
<statement name="STACK">
|
||||
<block type="controls_repeat_ext" inline="true">
|
||||
<value name="TIMES">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">item</field>
|
||||
<value name="VALUE">
|
||||
<block type="colour_random"></block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text_join">
|
||||
<mutation items="2"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="text">
|
||||
<field name="TEXT">length of random colour string: </field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_length" inline="false">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">7</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text_join">
|
||||
<mutation items="2"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="text">
|
||||
<field name="TEXT">format of random colour string: </field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_charAt">
|
||||
<mutation at="false"></mutation>
|
||||
<field name="WHERE">FIRST</field>
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">#</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">i</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">6</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="unittest_assertvalue" inline="false">
|
||||
<field name="EXPECTED">TRUE</field>
|
||||
<value name="MESSAGE">
|
||||
<block type="text_join">
|
||||
<mutation items="4"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="text">
|
||||
<field name="TEXT">contents of random colour string: </field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="text">
|
||||
<field name="TEXT"> at index: </field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="unittest_adjustindex">
|
||||
<value name="INDEX">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">i</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">NEQ</field>
|
||||
<value name="A">
|
||||
<block type="unittest_adjustindex">
|
||||
<value name="INDEX">
|
||||
<block type="math_number">
|
||||
<field name="NUM">-1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="text_indexOf" inline="false">
|
||||
<field name="END">FIRST</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT">abcdefABDEF0123456789</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="FIND">
|
||||
<block type="text_charAt">
|
||||
<mutation at="true"></mutation>
|
||||
<field name="WHERE">FROM_START</field>
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="AT">
|
||||
<block type="unittest_adjustindex">
|
||||
<value name="INDEX">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">i</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="638" y="213">
|
||||
<field name="NAME">test blend</field>
|
||||
<comment pinned="false" h="80" w="160">Describe this function...</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">blend</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="colour_blend" inline="false">
|
||||
<value name="COLOUR1">
|
||||
<block type="colour_picker">
|
||||
<field name="COLOUR">#ff0000</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="COLOUR2">
|
||||
<block type="colour_rgb" inline="false">
|
||||
<value name="RED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="GREEN">
|
||||
<block type="math_number">
|
||||
<field name="NUM">40</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BLUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="RATIO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0.4</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">#ff2900</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</xml>
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'dart:math' as Math;
|
||||
|
||||
var unittestResults, test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy;
|
||||
var unittestResults, test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy;
|
||||
|
||||
String unittest_report() {
|
||||
// Create test report.
|
||||
@@ -941,20 +941,6 @@ void test_replace() {
|
||||
unittest_assertequals(''.replaceAll('a', 'chicken'), '', 'empty source');
|
||||
}
|
||||
|
||||
/// Tests the "multiline" block.
|
||||
void test_multiline() {
|
||||
unittest_assertequals('', '', 'no text');
|
||||
unittest_assertequals('Google', 'Google', 'simple');
|
||||
unittest_assertequals('paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'no compile error with newlines');
|
||||
unittest_assertequals(text_count('bark bark' + '\n' +
|
||||
'bark bark bark' + '\n' +
|
||||
'bark bark bark bark', 'bark'), 9, 'count with newlines');
|
||||
}
|
||||
|
||||
/// Checks that the number of calls is one in order
|
||||
/// to confirm that a function was only called once.
|
||||
void check_number_of_calls2(test_name) {
|
||||
@@ -1426,80 +1412,6 @@ void test_lists_reverse() {
|
||||
unittest_assertequals(new List.from(list.reversed), [], 'empty list');
|
||||
}
|
||||
|
||||
/// Describe this function...
|
||||
void test_colour_picker() {
|
||||
unittest_assertequals('#ff6600', '#ff6600', 'static colour');
|
||||
}
|
||||
|
||||
String colour_rgb(num r, num g, num b) {
|
||||
num rn = (Math.max(Math.min(r, 100), 0) * 2.55).round();
|
||||
String rs = rn.toInt().toRadixString(16);
|
||||
rs = '0$rs';
|
||||
rs = rs.substring(rs.length - 2);
|
||||
num gn = (Math.max(Math.min(g, 100), 0) * 2.55).round();
|
||||
String gs = gn.toInt().toRadixString(16);
|
||||
gs = '0$gs';
|
||||
gs = gs.substring(gs.length - 2);
|
||||
num bn = (Math.max(Math.min(b, 100), 0) * 2.55).round();
|
||||
String bs = bn.toInt().toRadixString(16);
|
||||
bs = '0$bs';
|
||||
bs = bs.substring(bs.length - 2);
|
||||
return '#$rs$gs$bs';
|
||||
}
|
||||
|
||||
/// Describe this function...
|
||||
void test_rgb() {
|
||||
unittest_assertequals(colour_rgb(100, 40, 0), '#ff6600', 'from rgb');
|
||||
}
|
||||
|
||||
String colour_random() {
|
||||
String hex = '0123456789abcdef';
|
||||
var rnd = new Math.Random();
|
||||
return '#${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}'
|
||||
'${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}'
|
||||
'${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}';
|
||||
}
|
||||
|
||||
/// Describe this function...
|
||||
void test_colour_random() {
|
||||
for (int count4 = 0; count4 < 100; count4++) {
|
||||
item = colour_random();
|
||||
unittest_assertequals(item.length, 7, ['length of random colour string: ',item].join());
|
||||
unittest_assertequals(item[0], '#', ['format of random colour string: ',item].join());
|
||||
for (i = 1; i <= 6; i++) {
|
||||
unittest_assertequals(0 != 'abcdefABDEF0123456789'.indexOf(item[((i + 1) - 1)]) + 1, true, ['contents of random colour string: ',item,' at index: ',i + 1].join());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String colour_blend(String c1, String c2, num ratio) {
|
||||
ratio = Math.max(Math.min(ratio, 1), 0);
|
||||
int r1 = int.parse('0x${c1.substring(1, 3)}');
|
||||
int g1 = int.parse('0x${c1.substring(3, 5)}');
|
||||
int b1 = int.parse('0x${c1.substring(5, 7)}');
|
||||
int r2 = int.parse('0x${c2.substring(1, 3)}');
|
||||
int g2 = int.parse('0x${c2.substring(3, 5)}');
|
||||
int b2 = int.parse('0x${c2.substring(5, 7)}');
|
||||
num rn = (r1 * (1 - ratio) + r2 * ratio).round();
|
||||
String rs = rn.toInt().toRadixString(16);
|
||||
num gn = (g1 * (1 - ratio) + g2 * ratio).round();
|
||||
String gs = gn.toInt().toRadixString(16);
|
||||
num bn = (b1 * (1 - ratio) + b2 * ratio).round();
|
||||
String bs = bn.toInt().toRadixString(16);
|
||||
rs = '0$rs';
|
||||
rs = rs.substring(rs.length - 2);
|
||||
gs = '0$gs';
|
||||
gs = gs.substring(gs.length - 2);
|
||||
bs = '0$bs';
|
||||
bs = bs.substring(bs.length - 2);
|
||||
return '#$rs$gs$bs';
|
||||
}
|
||||
|
||||
/// Describe this function...
|
||||
void test_blend() {
|
||||
unittest_assertequals(colour_blend('#ff0000', colour_rgb(100, 40, 0), 0.4), '#ff2900', 'blend');
|
||||
}
|
||||
|
||||
/// Describe this function...
|
||||
void test_procedure() {
|
||||
procedure_1(8, 2);
|
||||
@@ -1642,7 +1554,6 @@ main() {
|
||||
test_count_text();
|
||||
test_text_reverse();
|
||||
test_replace();
|
||||
test_multiline();
|
||||
print(unittest_report());
|
||||
unittestResults = null;
|
||||
|
||||
@@ -1671,15 +1582,6 @@ main() {
|
||||
print(unittest_report());
|
||||
unittestResults = null;
|
||||
|
||||
unittestResults = [];
|
||||
print('\n====================\n\nRunning suite: Colour');
|
||||
test_colour_picker();
|
||||
test_blend();
|
||||
test_rgb();
|
||||
test_colour_random();
|
||||
print(unittest_report());
|
||||
unittestResults = null;
|
||||
|
||||
unittestResults = [];
|
||||
print('\n====================\n\nRunning suite: Variables');
|
||||
item = 123;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var unittestResults, test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy;
|
||||
var unittestResults, test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy;
|
||||
|
||||
function unittest_report() {
|
||||
// Create test report.
|
||||
@@ -920,20 +920,6 @@ function test_replace() {
|
||||
assertEquals(textReplace('', 'a', 'chicken'), '', 'empty source');
|
||||
}
|
||||
|
||||
// Tests the "multiline" block.
|
||||
function test_multiline() {
|
||||
assertEquals('', '', 'no text');
|
||||
assertEquals('Google', 'Google', 'simple');
|
||||
assertEquals('paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'no compile error with newlines');
|
||||
assertEquals(textCount('bark bark' + '\n' +
|
||||
'bark bark bark' + '\n' +
|
||||
'bark bark bark bark', 'bark'), 9, 'count with newlines');
|
||||
}
|
||||
|
||||
// Checks that the number of calls is one in order
|
||||
// to confirm that a function was only called once.
|
||||
function check_number_of_calls2(test_name) {
|
||||
@@ -1376,65 +1362,6 @@ function test_lists_reverse() {
|
||||
assertEquals(list.slice().reverse(), [], 'empty list');
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_colour_picker() {
|
||||
assertEquals('#ff6600', '#ff6600', 'static colour');
|
||||
}
|
||||
|
||||
function colourRgb(r, g, b) {
|
||||
r = Math.max(Math.min(Number(r), 100), 0) * 2.55;
|
||||
g = Math.max(Math.min(Number(g), 100), 0) * 2.55;
|
||||
b = Math.max(Math.min(Number(b), 100), 0) * 2.55;
|
||||
r = ('0' + (Math.round(r) || 0).toString(16)).slice(-2);
|
||||
g = ('0' + (Math.round(g) || 0).toString(16)).slice(-2);
|
||||
b = ('0' + (Math.round(b) || 0).toString(16)).slice(-2);
|
||||
return '#' + r + g + b;
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_rgb() {
|
||||
assertEquals(colourRgb(100, 40, 0), '#ff6600', 'from rgb');
|
||||
}
|
||||
|
||||
function colourRandom() {
|
||||
var num = Math.floor(Math.random() * Math.pow(2, 24));
|
||||
return '#' + ('00000' + num.toString(16)).substr(-6);
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_colour_random() {
|
||||
for (var count4 = 0; count4 < 100; count4++) {
|
||||
item = colourRandom();
|
||||
assertEquals(item.length, 7, 'length of random colour string: ' + String(item));
|
||||
assertEquals(item.charAt(0), '#', 'format of random colour string: ' + String(item));
|
||||
for (i = 1; i <= 6; i++) {
|
||||
assertEquals(0 != 'abcdefABDEF0123456789'.indexOf(item.charAt(((i + 1) - 1))) + 1, true, ['contents of random colour string: ',item,' at index: ',i + 1].join(''));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function colourBlend(c1, c2, ratio) {
|
||||
ratio = Math.max(Math.min(Number(ratio), 1), 0);
|
||||
var r1 = parseInt(c1.substring(1, 3), 16);
|
||||
var g1 = parseInt(c1.substring(3, 5), 16);
|
||||
var b1 = parseInt(c1.substring(5, 7), 16);
|
||||
var r2 = parseInt(c2.substring(1, 3), 16);
|
||||
var g2 = parseInt(c2.substring(3, 5), 16);
|
||||
var b2 = parseInt(c2.substring(5, 7), 16);
|
||||
var r = Math.round(r1 * (1 - ratio) + r2 * ratio);
|
||||
var g = Math.round(g1 * (1 - ratio) + g2 * ratio);
|
||||
var b = Math.round(b1 * (1 - ratio) + b2 * ratio);
|
||||
r = ('0' + (r || 0).toString(16)).slice(-2);
|
||||
g = ('0' + (g || 0).toString(16)).slice(-2);
|
||||
b = ('0' + (b || 0).toString(16)).slice(-2);
|
||||
return '#' + r + g + b;
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_blend() {
|
||||
assertEquals(colourBlend('#ff0000', colourRgb(100, 40, 0), 0.4), '#ff2900', 'blend');
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_procedure() {
|
||||
procedure_1(8, 2);
|
||||
@@ -1576,7 +1503,6 @@ test_trim();
|
||||
test_count_text();
|
||||
test_text_reverse();
|
||||
test_replace();
|
||||
test_multiline();
|
||||
console.log(unittest_report());
|
||||
unittestResults = null;
|
||||
|
||||
@@ -1605,15 +1531,6 @@ test_lists_reverse();
|
||||
console.log(unittest_report());
|
||||
unittestResults = null;
|
||||
|
||||
unittestResults = [];
|
||||
console.log('\n====================\n\nRunning suite: Colour')
|
||||
test_colour_picker();
|
||||
test_blend();
|
||||
test_rgb();
|
||||
test_colour_random();
|
||||
console.log(unittest_report());
|
||||
unittestResults = null;
|
||||
|
||||
unittestResults = [];
|
||||
console.log('\n====================\n\nRunning suite: Variables')
|
||||
item = 123;
|
||||
|
||||
@@ -1015,21 +1015,6 @@ function test_replace()
|
||||
end
|
||||
|
||||
|
||||
-- Tests the "multiline" block.
|
||||
function test_multiline()
|
||||
assertEquals('', '', 'no text')
|
||||
assertEquals('Google', 'Google', 'simple')
|
||||
assertEquals('paragraph' .. '\n' ..
|
||||
'with newlines' .. '\n' ..
|
||||
'yup', 'paragraph' .. '\n' ..
|
||||
'with newlines' .. '\n' ..
|
||||
'yup', 'no compile error with newlines')
|
||||
assertEquals(text_count('bark bark' .. '\n' ..
|
||||
'bark bark bark' .. '\n' ..
|
||||
'bark bark bark bark', 'bark'), 9, 'count with newlines')
|
||||
end
|
||||
|
||||
|
||||
-- Checks that the number of calls is one in order
|
||||
-- to confirm that a function was only called once.
|
||||
function check_number_of_calls2(test_name)
|
||||
@@ -1645,58 +1630,6 @@ function test_lists_reverse()
|
||||
end
|
||||
|
||||
|
||||
-- Describe this function...
|
||||
function test_colour_picker()
|
||||
assertEquals('#ff6600', '#ff6600', 'static colour')
|
||||
end
|
||||
|
||||
|
||||
function colour_rgb(r, g, b)
|
||||
r = math.floor(math.min(100, math.max(0, r)) * 2.55 + .5)
|
||||
g = math.floor(math.min(100, math.max(0, g)) * 2.55 + .5)
|
||||
b = math.floor(math.min(100, math.max(0, b)) * 2.55 + .5)
|
||||
return string.format("#%02x%02x%02x", r, g, b)
|
||||
end
|
||||
|
||||
-- Describe this function...
|
||||
function test_rgb()
|
||||
assertEquals(colour_rgb(100, 40, 0), '#ff6600', 'from rgb')
|
||||
end
|
||||
|
||||
|
||||
-- Describe this function...
|
||||
function test_colour_random()
|
||||
for count4 = 1, 100 do
|
||||
item = string.format("#%06x", math.random(0, 2^24 - 1))
|
||||
assertEquals(#item, 7, 'length of random colour string: ' .. item)
|
||||
assertEquals(string.sub(item, 1, 1), '#', 'format of random colour string: ' .. item)
|
||||
for i = 1, 6, 1 do
|
||||
assertEquals(0 ~= firstIndexOf('abcdefABDEF0123456789', text_char_at(item, i + 1)), true, table.concat({'contents of random colour string: ', item, ' at index: ', i + 1}))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function colour_blend(colour1, colour2, ratio)
|
||||
local r1 = tonumber(string.sub(colour1, 2, 3), 16)
|
||||
local r2 = tonumber(string.sub(colour2, 2, 3), 16)
|
||||
local g1 = tonumber(string.sub(colour1, 4, 5), 16)
|
||||
local g2 = tonumber(string.sub(colour2, 4, 5), 16)
|
||||
local b1 = tonumber(string.sub(colour1, 6, 7), 16)
|
||||
local b2 = tonumber(string.sub(colour2, 6, 7), 16)
|
||||
local ratio = math.min(1, math.max(0, ratio))
|
||||
local r = math.floor(r1 * (1 - ratio) + r2 * ratio + .5)
|
||||
local g = math.floor(g1 * (1 - ratio) + g2 * ratio + .5)
|
||||
local b = math.floor(b1 * (1 - ratio) + b2 * ratio + .5)
|
||||
return string.format("#%02x%02x%02x", r, g, b)
|
||||
end
|
||||
|
||||
-- Describe this function...
|
||||
function test_blend()
|
||||
assertEquals(colour_blend('#ff0000', colour_rgb(100, 40, 0), 0.4), '#ff2900', 'blend')
|
||||
end
|
||||
|
||||
|
||||
-- Describe this function...
|
||||
function test_procedure()
|
||||
procedure_1(8, 2)
|
||||
@@ -1846,7 +1779,6 @@ test_trim()
|
||||
test_count_text()
|
||||
test_text_reverse()
|
||||
test_replace()
|
||||
test_multiline()
|
||||
print(unittest_report())
|
||||
unittestResults = nil
|
||||
|
||||
@@ -1875,15 +1807,6 @@ test_lists_reverse()
|
||||
print(unittest_report())
|
||||
unittestResults = nil
|
||||
|
||||
unittestResults = {}
|
||||
print('\n====================\n\nRunning suite: Colour')
|
||||
test_colour_picker()
|
||||
test_blend()
|
||||
test_rgb()
|
||||
test_colour_random()
|
||||
print(unittest_report())
|
||||
unittestResults = nil
|
||||
|
||||
unittestResults = {}
|
||||
print('\n====================\n\nRunning suite: Variables')
|
||||
item = 123
|
||||
|
||||
@@ -53,7 +53,7 @@ function unittest_fail($message) {
|
||||
|
||||
// Describe this function...
|
||||
function test_if() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
if (false) {
|
||||
unittest_fail('if false');
|
||||
}
|
||||
@@ -91,7 +91,7 @@ function test_if() {
|
||||
|
||||
// Describe this function...
|
||||
function test_ifelse() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$ok = false;
|
||||
if (true) {
|
||||
$ok = true;
|
||||
@@ -110,7 +110,7 @@ function test_ifelse() {
|
||||
|
||||
// Describe this function...
|
||||
function test_equalities() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(2 == 2, true, 'Equal yes');
|
||||
assertEquals(3 == 4, false, 'Equal no');
|
||||
assertEquals(5 != 6, true, 'Not equal yes');
|
||||
@@ -127,7 +127,7 @@ function test_equalities() {
|
||||
|
||||
// Describe this function...
|
||||
function test_and() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(true && true, true, 'And true/true');
|
||||
assertEquals(false && true, false, 'And false/true');
|
||||
assertEquals(true && false, false, 'And true/false');
|
||||
@@ -136,7 +136,7 @@ function test_and() {
|
||||
|
||||
// Describe this function...
|
||||
function test_or() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(true || true, true, 'Or true/true');
|
||||
assertEquals(false || true, true, 'Or false/true');
|
||||
assertEquals(true || false, true, 'Or true/false');
|
||||
@@ -145,14 +145,14 @@ function test_or() {
|
||||
|
||||
// Describe this function...
|
||||
function test_ternary() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(true ? 42 : 99, 42, 'if true');
|
||||
assertEquals(false ? 42 : 99, 99, 'if true');
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_foreach() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$log = '';
|
||||
foreach (array('a', 'b', 'c') as $x) {
|
||||
$log .= $x;
|
||||
@@ -162,7 +162,7 @@ function test_foreach() {
|
||||
|
||||
// Describe this function...
|
||||
function test_repeat() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$count = 0;
|
||||
for ($count2 = 0; $count2 < 10; $count2++) {
|
||||
$count += 1;
|
||||
@@ -172,7 +172,7 @@ function test_repeat() {
|
||||
|
||||
// Describe this function...
|
||||
function test_while() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
while (false) {
|
||||
unittest_fail('while 0');
|
||||
}
|
||||
@@ -193,7 +193,7 @@ function test_while() {
|
||||
|
||||
// Describe this function...
|
||||
function test_repeat_ext() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$count = 0;
|
||||
for ($count3 = 0; $count3 < 10; $count3++) {
|
||||
$count += 1;
|
||||
@@ -203,7 +203,7 @@ function test_repeat_ext() {
|
||||
|
||||
// Describe this function...
|
||||
function test_count_by() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$log = '';
|
||||
for ($x = 1; $x <= 8; $x += 2) {
|
||||
$log .= $x;
|
||||
@@ -256,7 +256,7 @@ function test_count_by() {
|
||||
|
||||
// Describe this function...
|
||||
function test_count_loops() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$log = '';
|
||||
for ($x = 1; $x <= 8; $x++) {
|
||||
$log .= $x;
|
||||
@@ -293,7 +293,7 @@ function test_count_loops() {
|
||||
|
||||
// Describe this function...
|
||||
function test_continue() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$log = '';
|
||||
$count = 0;
|
||||
while ($count != 8) {
|
||||
@@ -334,7 +334,7 @@ function test_continue() {
|
||||
|
||||
// Describe this function...
|
||||
function test_break() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$count = 1;
|
||||
while ($count != 10) {
|
||||
if ($count == 5) {
|
||||
@@ -371,7 +371,7 @@ function test_break() {
|
||||
|
||||
// Tests the "single" block.
|
||||
function test_single() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(sqrt(25), 5, 'sqrt');
|
||||
assertEquals(abs(-25), 25, 'abs');
|
||||
assertEquals(-(-25), 25, 'negate');
|
||||
@@ -384,7 +384,7 @@ function test_single() {
|
||||
// Tests the "arithmetic" block for all operations and checks
|
||||
// parenthesis are properly generated for different orders.
|
||||
function test_arithmetic() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(1 + 2, 3, 'add');
|
||||
assertEquals(1 - 2, -1, 'subtract');
|
||||
assertEquals(1 - (0 + 2), -1, 'subtract order with add');
|
||||
@@ -399,7 +399,7 @@ function test_arithmetic() {
|
||||
|
||||
// Tests the "trig" block.
|
||||
function test_trig() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(sin(90 / 180 * pi()), 1, 'sin');
|
||||
assertEquals(cos(180 / 180 * pi()), -1, 'cos');
|
||||
assertEquals(tan(0 / 180 * pi()), 0, 'tan');
|
||||
@@ -410,7 +410,7 @@ function test_trig() {
|
||||
|
||||
// Tests the "constant" blocks.
|
||||
function test_constant() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(floor(M_PI * 1000), 3141, 'const pi');
|
||||
assertEquals(floor(M_E * 1000), 2718, 'const e');
|
||||
assertEquals(floor(((1 + sqrt(5)) / 2) * 1000), 1618, 'const golden');
|
||||
@@ -440,7 +440,7 @@ function math_isPrime($n) {
|
||||
|
||||
// Tests the "number property" blocks.
|
||||
function test_number_properties() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(42 % 2 == 0, true, 'even');
|
||||
assertEquals(42.1 % 2 == 1, false, 'odd');
|
||||
assertEquals(math_isPrime(5), true, 'prime 5');
|
||||
@@ -458,7 +458,7 @@ function test_number_properties() {
|
||||
|
||||
// Tests the "round" block.
|
||||
function test_round() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(round(42.42), 42, 'round');
|
||||
assertEquals(ceil(-42.42), -42, 'round up');
|
||||
assertEquals(floor(42.42), 42, 'round down');
|
||||
@@ -466,7 +466,7 @@ function test_round() {
|
||||
|
||||
// Tests the "change" block.
|
||||
function test_change() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$varToChange = 100;
|
||||
$varToChange += 42;
|
||||
assertEquals($varToChange, 142, 'change');
|
||||
@@ -512,7 +512,7 @@ function indexOf($haystack, $needle) {
|
||||
|
||||
// Tests the "list operation" blocks.
|
||||
function test_operations_on_list() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(array_sum((array(3, 4, 5))), 12, 'sum');
|
||||
assertEquals(min((array(3, 4, 5))), 3, 'min');
|
||||
assertEquals(max((array(3, 4, 5))), 5, 'max');
|
||||
@@ -526,13 +526,13 @@ function test_operations_on_list() {
|
||||
|
||||
// Tests the "mod" block.
|
||||
function test_mod() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(42 % 5, 2, 'mod');
|
||||
}
|
||||
|
||||
// Tests the "constrain" block.
|
||||
function test_constraint() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(min(max(100, 0), 42), 42, 'constraint');
|
||||
}
|
||||
|
||||
@@ -545,7 +545,7 @@ function math_random_int($a, $b) {
|
||||
|
||||
// Tests the "random integer" block.
|
||||
function test_random_integer() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$rand = math_random_int(5, 10);
|
||||
assertEquals($rand >= 5 && $rand <= 10, true, 'randRange');
|
||||
assertEquals(is_int($rand), true, 'randInteger');
|
||||
@@ -553,14 +553,14 @@ function test_random_integer() {
|
||||
|
||||
// Tests the "random fraction" block.
|
||||
function test_random_fraction() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$rand = (float)rand()/(float)getrandmax();
|
||||
assertEquals($rand >= 0 && $rand <= 1, true, 'randFloat');
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_atan2() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(atan2(5, -5) / pi() * 180, 135, 'atan2');
|
||||
assertEquals(atan2(-12, 0) / pi() * 180, -90, 'atan2');
|
||||
}
|
||||
@@ -568,14 +568,14 @@ function test_atan2() {
|
||||
// Checks that the number of calls is one in order
|
||||
// to confirm that a function was only called once.
|
||||
function check_number_of_calls($test_name) {
|
||||
global $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$test_name .= 'number of calls';
|
||||
assertEquals($number_of_calls, 1, $test_name);
|
||||
}
|
||||
|
||||
// Tests the "create text with" block with varying number of inputs.
|
||||
function test_create_text() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals('', '', 'no text');
|
||||
assertEquals('Hello', 'Hello', 'create single');
|
||||
assertEquals(-1, '-1', 'create single number');
|
||||
@@ -587,13 +587,13 @@ function test_create_text() {
|
||||
|
||||
// Creates an empty string for use with the empty test.
|
||||
function get_empty() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
return '';
|
||||
}
|
||||
|
||||
// Tests the "is empty" block".
|
||||
function test_empty_text() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(empty('Google'), false, 'not empty');
|
||||
assertEquals(empty(''), true, 'empty');
|
||||
assertEquals(empty(get_empty()), true, 'empty complex');
|
||||
@@ -609,7 +609,7 @@ function length($value) {
|
||||
|
||||
// Tests the "length" block.
|
||||
function test_text_length() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(length(''), 0, 'zero length');
|
||||
assertEquals(length('Google'), 6, 'non-zero length');
|
||||
assertEquals(length(true ? 'car' : null), 3, 'length order');
|
||||
@@ -617,7 +617,7 @@ function test_text_length() {
|
||||
|
||||
// Tests the "append text" block with different types of parameters.
|
||||
function test_append() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$item = 'Miserable';
|
||||
$item .= 'Failure';
|
||||
assertEquals($item, 'MiserableFailure', 'append text');
|
||||
@@ -641,7 +641,7 @@ function text_lastIndexOf($text, $search) {
|
||||
|
||||
// Tests the "find" block with a variable.
|
||||
function test_find_text_simple() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$text = 'Banana';
|
||||
assertEquals(text_indexOf($text, 'an'), 2, 'find first simple');
|
||||
assertEquals(text_lastIndexOf($text, 'an'), 4, 'find last simple');
|
||||
@@ -650,14 +650,14 @@ function test_find_text_simple() {
|
||||
|
||||
// Creates a string for use with the find test.
|
||||
function get_fruit() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls += 1;
|
||||
return 'Banana';
|
||||
}
|
||||
|
||||
// Tests the "find" block with a function call.
|
||||
function test_find_text_complex() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls = 0;
|
||||
assertEquals(text_indexOf(get_fruit(), 'an'), 2, 'find first complex');
|
||||
check_number_of_calls('find first complex');
|
||||
@@ -684,7 +684,7 @@ function text_random_letter($text) {
|
||||
|
||||
// Tests the "get letter" block with a variable.
|
||||
function test_get_text_simple() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$text = 'Blockly';
|
||||
assertEquals(substr($text, 0, 1), 'B', 'get first simple');
|
||||
assertEquals(substr($text, -1), 'y', 'get last simple');
|
||||
@@ -698,14 +698,14 @@ function test_get_text_simple() {
|
||||
|
||||
// Creates a string for use with the get test.
|
||||
function get_Blockly() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls += 1;
|
||||
return 'Blockly';
|
||||
}
|
||||
|
||||
// Tests the "get letter" block with a function call.
|
||||
function test_get_text_complex() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$text = 'Blockly';
|
||||
$number_of_calls = 0;
|
||||
assertEquals(substr(get_Blockly(), 0, 1), 'B', 'get first complex');
|
||||
@@ -742,7 +742,7 @@ function test_get_text_complex() {
|
||||
|
||||
// Creates a string for use with the substring test.
|
||||
function get_numbers() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls += 1;
|
||||
return '123456789';
|
||||
}
|
||||
@@ -770,7 +770,7 @@ function text_get_substring($text, $where1, $at1, $where2, $at2) {
|
||||
|
||||
// Tests the "get substring" block with a variable.
|
||||
function test_substring_simple() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$text = '123456789';
|
||||
assertEquals(text_get_substring($text, 'FROM_START', 1, 'FROM_START', 2), '23', 'substring # simple');
|
||||
assertEquals(text_get_substring($text, 'FROM_START', ((true ? 2 : null) - 1), 'FROM_START', ((true ? 3 : null) - 1)), '23', 'substring # simple order');
|
||||
@@ -792,7 +792,7 @@ function test_substring_simple() {
|
||||
|
||||
// Tests the "get substring" block with a function call.
|
||||
function test_substring_complex() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls = 0;
|
||||
assertEquals(text_get_substring(get_numbers(), 'FROM_START', 1, 'FROM_START', 2), '23', 'substring # complex');
|
||||
check_number_of_calls('substring # complex');
|
||||
@@ -841,7 +841,7 @@ function test_substring_complex() {
|
||||
|
||||
// Tests the "change casing" block.
|
||||
function test_case() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$text = 'Hello World';
|
||||
assertEquals(strtoupper($text), 'HELLO WORLD', 'uppercase');
|
||||
assertEquals(strtoupper(true ? $text : null), 'HELLO WORLD', 'uppercase order');
|
||||
@@ -855,7 +855,7 @@ function test_case() {
|
||||
|
||||
// Tests the "trim" block.
|
||||
function test_trim() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$text = ' abc def ';
|
||||
assertEquals(trim($text), 'abc def', 'trim both');
|
||||
assertEquals(trim(true ? $text : null), 'abc def', 'trim both order');
|
||||
@@ -867,7 +867,7 @@ function test_trim() {
|
||||
|
||||
// Tests the "trim" block.
|
||||
function test_count_text() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$text = 'woolloomooloo';
|
||||
assertEquals(strlen('o') === 0 ? strlen($text) + 1 : substr_count($text, 'o'), 8, 'len 1');
|
||||
assertEquals(strlen('oo') === 0 ? strlen($text) + 1 : substr_count($text, 'oo'), 4, 'len 2');
|
||||
@@ -880,7 +880,7 @@ function test_count_text() {
|
||||
|
||||
// Tests the "trim" block.
|
||||
function test_text_reverse() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(strrev(''), '', 'empty string');
|
||||
assertEquals(strrev('a'), 'a', 'len 1');
|
||||
assertEquals(strrev('ab'), 'ba', 'len 2');
|
||||
@@ -889,7 +889,7 @@ function test_text_reverse() {
|
||||
|
||||
// Tests the "trim" block.
|
||||
function test_replace() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(str_replace('oo', '123', 'woolloomooloo'), 'w123ll123m123l123', 'replace all instances 1');
|
||||
assertEquals(str_replace('.oo', 'X', 'woolloomooloo'), 'woolloomooloo', 'literal string replacement');
|
||||
assertEquals(str_replace('abc', 'X', 'woolloomooloo'), 'woolloomooloo', 'not found');
|
||||
@@ -899,27 +899,10 @@ function test_replace() {
|
||||
assertEquals(str_replace('a', 'chicken', ''), '', 'empty source');
|
||||
}
|
||||
|
||||
// Tests the "multiline" block.
|
||||
function test_multiline() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals('', '', 'no text');
|
||||
assertEquals('Google', 'Google', 'simple');
|
||||
assertEquals('paragraph' . "\n" .
|
||||
'with newlines' . "\n" .
|
||||
'yup', 'paragraph' . "\n" .
|
||||
'with newlines' . "\n" .
|
||||
'yup', 'no compile error with newlines');
|
||||
assertEquals(strlen('bark') === 0 ? strlen('bark bark' . "\n" .
|
||||
'bark bark bark' . "\n" .
|
||||
'bark bark bark bark') + 1 : substr_count('bark bark' . "\n" .
|
||||
'bark bark bark' . "\n" .
|
||||
'bark bark bark bark', 'bark'), 9, 'count with newlines');
|
||||
}
|
||||
|
||||
// Checks that the number of calls is one in order
|
||||
// to confirm that a function was only called once.
|
||||
function check_number_of_calls2($test_name) {
|
||||
global $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$test_name .= 'number of calls';
|
||||
assertEquals($number_of_calls, 1, $test_name);
|
||||
}
|
||||
@@ -934,7 +917,7 @@ function lists_repeat($value, $count) {
|
||||
|
||||
// Tests the "create list with" and "create empty list" blocks.
|
||||
function test_create_lists() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(array(), array(), 'create empty');
|
||||
assertEquals(array(true, 'love'), array(true, 'love'), 'create items');
|
||||
assertEquals(lists_repeat('Eject', 3), array('Eject', 'Eject', 'Eject'), 'create repeated');
|
||||
@@ -943,13 +926,13 @@ function test_create_lists() {
|
||||
|
||||
// Creates an empty list for use with the empty test.
|
||||
function get_empty_list() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
return array();
|
||||
}
|
||||
|
||||
// Tests the "is empty" block.
|
||||
function test_lists_empty() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(empty((array(0))), false, 'not empty');
|
||||
assertEquals(empty((array())), true, 'empty');
|
||||
assertEquals(empty((get_empty_list())), true, 'empty complex');
|
||||
@@ -958,7 +941,7 @@ function test_lists_empty() {
|
||||
|
||||
// Tests the "length" block.
|
||||
function test_lists_length() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(length(array()), 0, 'zero length');
|
||||
assertEquals(length(array('cat')), 1, 'one length');
|
||||
assertEquals(length(array('cat', true, array())), 3, 'three length');
|
||||
@@ -975,7 +958,7 @@ function lastIndexOf($haystack, $needle) {
|
||||
|
||||
// Tests the "find" block with a variable.
|
||||
function test_find_lists_simple() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Alice', 'Eve', 'Bob', 'Eve');
|
||||
assertEquals(indexOf($list2, 'Eve'), 2, 'find first simple');
|
||||
assertEquals(lastIndexOf($list2, 'Eve'), 4, 'find last simple');
|
||||
@@ -984,14 +967,14 @@ function test_find_lists_simple() {
|
||||
|
||||
// Creates a list for use with the find test.
|
||||
function get_names() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls += 1;
|
||||
return array('Alice', 'Eve', 'Bob', 'Eve');
|
||||
}
|
||||
|
||||
// Tests the "find" block with a function call.
|
||||
function test_find_lists_complex() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls = 0;
|
||||
assertEquals(indexOf(get_names(), 'Eve'), 2, 'find first complex');
|
||||
check_number_of_calls('find first complex');
|
||||
@@ -1018,7 +1001,7 @@ function lists_get_random_item($list) {
|
||||
|
||||
// Tests the "get" block with a variable.
|
||||
function test_get_lists_simple() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Kirk', 'Spock', 'McCoy');
|
||||
assertEquals($list2[0], 'Kirk', 'get first simple');
|
||||
assertEquals(end($list2), 'McCoy', 'get last simple');
|
||||
@@ -1032,7 +1015,7 @@ function test_get_lists_simple() {
|
||||
|
||||
// Tests the "get" block with create list call.
|
||||
function test_get_lists_create_list() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(array('Kirk', 'Spock', 'McCoy')[0], 'Kirk', 'get first create list');
|
||||
assertEquals(end(array('Kirk', 'Spock', 'McCoy')), 'McCoy', 'get last simple');
|
||||
assertEquals(indexOf(array('Kirk', 'Spock', 'McCoy'), lists_get_random_item(array('Kirk', 'Spock', 'McCoy'))) > 0, true, 'get random simple');
|
||||
@@ -1045,14 +1028,14 @@ function test_get_lists_create_list() {
|
||||
|
||||
// Creates a list for use with the get test.
|
||||
function get_star_wars() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls += 1;
|
||||
return array('Kirk', 'Spock', 'McCoy');
|
||||
}
|
||||
|
||||
// Tests the "get" block with a function call.
|
||||
function test_get_lists_complex() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Kirk', 'Spock', 'McCoy');
|
||||
$number_of_calls = 0;
|
||||
assertEquals(get_star_wars()[0], 'Kirk', 'get first complex');
|
||||
@@ -1095,7 +1078,7 @@ function lists_get_remove_random_item(&$list) {
|
||||
|
||||
// Tests the "get and remove" block.
|
||||
function test_getRemove() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Kirk', 'Spock', 'McCoy');
|
||||
assertEquals(array_shift($list2), 'Kirk', 'getremove first');
|
||||
assertEquals($list2, array('Spock', 'McCoy'), 'getremove first list');
|
||||
@@ -1135,7 +1118,7 @@ function lists_remove_random_item(&$list) {
|
||||
|
||||
// Tests the "remove" block.
|
||||
function test_remove() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Kirk', 'Spock', 'McCoy');
|
||||
array_shift($list2);
|
||||
assertEquals($list2, array('Spock', 'McCoy'), 'remove first list');
|
||||
@@ -1180,7 +1163,7 @@ function lists_set_from_end(&$list, $at, $value) {
|
||||
|
||||
// Tests the "set" block.
|
||||
function test_set() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Picard', 'Riker', 'Crusher');
|
||||
$list2[0] = 'Jean-Luc';
|
||||
assertEquals($list2, array('Jean-Luc', 'Riker', 'Crusher'), 'set first list');
|
||||
@@ -1224,7 +1207,7 @@ function lists_insert_from_end(&$list, $at, $value) {
|
||||
|
||||
// Tests the "insert" block.
|
||||
function test_insert() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Picard', 'Riker', 'Crusher');
|
||||
array_unshift($list2, 'Data');
|
||||
assertEquals($list2, array('Data', 'Picard', 'Riker', 'Crusher'), 'insert first list');
|
||||
@@ -1264,7 +1247,7 @@ function test_insert() {
|
||||
|
||||
// Tests the "get sub-list" block with a variable.
|
||||
function test_sublist_simple() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Columbia', 'Challenger', 'Discovery', 'Atlantis', 'Endeavour');
|
||||
assertEquals(array_slice($list2, 1, 2 - 1 + 1), array('Challenger', 'Discovery'), 'sublist # simple');
|
||||
assertEquals(array_slice($list2, ((true ? 2 : null) - 1), ((true ? 3 : null) - 1) - ((true ? 2 : null) - 1) + 1), array('Challenger', 'Discovery'), 'sublist # simple order');
|
||||
@@ -1290,7 +1273,7 @@ function test_sublist_simple() {
|
||||
|
||||
// Creates a list for use with the sublist test.
|
||||
function get_space_shuttles() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls += 1;
|
||||
return array('Columbia', 'Challenger', 'Discovery', 'Atlantis', 'Endeavour');
|
||||
}
|
||||
@@ -1318,7 +1301,7 @@ function lists_get_sublist($list, $where1, $at1, $where2, $at2) {
|
||||
|
||||
// Tests the "get sub-list" block with a function call.
|
||||
function test_sublist_complex() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$number_of_calls = 0;
|
||||
assertEquals(array_slice(get_space_shuttles(), 1, 2 - 1 + 1), array('Challenger', 'Discovery'), 'sublist # start complex');
|
||||
check_number_of_calls('sublist # start complex');
|
||||
@@ -1367,7 +1350,7 @@ function test_sublist_complex() {
|
||||
|
||||
// Tests the "join" block.
|
||||
function test_join() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Vulcan', 'Klingon', 'Borg');
|
||||
assertEquals(implode(',', $list2), 'Vulcan,Klingon,Borg', 'join');
|
||||
assertEquals(implode(',', true ? $list2 : null), 'Vulcan,Klingon,Borg', 'join order');
|
||||
@@ -1375,7 +1358,7 @@ function test_join() {
|
||||
|
||||
// Tests the "split" block.
|
||||
function test_split() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$text = 'Vulcan,Klingon,Borg';
|
||||
assertEquals(explode(',', $text), array('Vulcan', 'Klingon', 'Borg'), 'split');
|
||||
assertEquals(explode(',', true ? $text : null), array('Vulcan', 'Klingon', 'Borg'), 'split order');
|
||||
@@ -1398,7 +1381,7 @@ function lists_sort($list, $type, $direction) {
|
||||
|
||||
// Tests the "alphabetic sort" block.
|
||||
function test_sort_alphabetic() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Vulcan', 'klingon', 'Borg');
|
||||
assertEquals(lists_sort($list2, "TEXT", 1), array('Borg', 'Vulcan', 'klingon'), 'sort alphabetic ascending');
|
||||
assertEquals(lists_sort(true ? $list2 : null, "TEXT", 1), array('Borg', 'Vulcan', 'klingon'), 'sort alphabetic ascending order');
|
||||
@@ -1406,7 +1389,7 @@ function test_sort_alphabetic() {
|
||||
|
||||
// Tests the "alphabetic sort ignore case" block.
|
||||
function test_sort_ignoreCase() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array('Vulcan', 'klingon', 'Borg');
|
||||
assertEquals(lists_sort($list2, "IGNORE_CASE", 1), array('Borg', 'klingon', 'Vulcan'), 'sort ignore case ascending');
|
||||
assertEquals(lists_sort(true ? $list2 : null, "IGNORE_CASE", 1), array('Borg', 'klingon', 'Vulcan'), 'sort ignore case ascending order');
|
||||
@@ -1414,7 +1397,7 @@ function test_sort_ignoreCase() {
|
||||
|
||||
// Tests the "numeric sort" block.
|
||||
function test_sort_numeric() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array(8, 18, -1);
|
||||
assertEquals(lists_sort($list2, "NUMERIC", -1), array(18, 8, -1), 'sort numeric descending');
|
||||
assertEquals(lists_sort(true ? $list2 : null, "NUMERIC", -1), array(18, 8, -1), 'sort numeric descending order');
|
||||
@@ -1422,7 +1405,7 @@ function test_sort_numeric() {
|
||||
|
||||
// Tests the "list reverse" block.
|
||||
function test_lists_reverse() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$list2 = array(8, 18, -1, 64);
|
||||
assertEquals(array_reverse($list2), array(64, -1, 18, 8), 'reverse a copy');
|
||||
assertEquals($list2, array(8, 18, -1, 64), 'reverse a copy original');
|
||||
@@ -1430,73 +1413,9 @@ function test_lists_reverse() {
|
||||
assertEquals(array_reverse($list2), array(), 'empty list');
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_colour_picker() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals('#ff6600', '#ff6600', 'static colour');
|
||||
}
|
||||
|
||||
function colour_rgb($r, $g, $b) {
|
||||
$r = round(max(min($r, 100), 0) * 2.55);
|
||||
$g = round(max(min($g, 100), 0) * 2.55);
|
||||
$b = round(max(min($b, 100), 0) * 2.55);
|
||||
$hex = '#';
|
||||
$hex .= str_pad(dechex($r), 2, '0', STR_PAD_LEFT);
|
||||
$hex .= str_pad(dechex($g), 2, '0', STR_PAD_LEFT);
|
||||
$hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
|
||||
return $hex;
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_rgb() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(colour_rgb(100, 40, 0), '#ff6600', 'from rgb');
|
||||
}
|
||||
|
||||
function colour_random() {
|
||||
return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_colour_random() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
for ($count4 = 0; $count4 < 100; $count4++) {
|
||||
$item = colour_random();
|
||||
assertEquals(length($item), 7, 'length of random colour string: ' . $item);
|
||||
assertEquals(substr($item, 0, 1), '#', 'format of random colour string: ' . $item);
|
||||
for ($i = 1; $i <= 6; $i++) {
|
||||
assertEquals(0 != text_indexOf('abcdefABDEF0123456789', substr($item, (($i + 1) - 1), 1)), true, implode('', array('contents of random colour string: ',$item,' at index: ',$i + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function colour_blend($c1, $c2, $ratio) {
|
||||
$ratio = max(min($ratio, 1), 0);
|
||||
$r1 = hexdec(substr($c1, 1, 2));
|
||||
$g1 = hexdec(substr($c1, 3, 2));
|
||||
$b1 = hexdec(substr($c1, 5, 2));
|
||||
$r2 = hexdec(substr($c2, 1, 2));
|
||||
$g2 = hexdec(substr($c2, 3, 2));
|
||||
$b2 = hexdec(substr($c2, 5, 2));
|
||||
$r = round($r1 * (1 - $ratio) + $r2 * $ratio);
|
||||
$g = round($g1 * (1 - $ratio) + $g2 * $ratio);
|
||||
$b = round($b1 * (1 - $ratio) + $b2 * $ratio);
|
||||
$hex = '#';
|
||||
$hex .= str_pad(dechex($r), 2, '0', STR_PAD_LEFT);
|
||||
$hex .= str_pad(dechex($g), 2, '0', STR_PAD_LEFT);
|
||||
$hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
|
||||
return $hex;
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_blend() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(colour_blend('#ff0000', colour_rgb(100, 40, 0), 0.4), '#ff2900', 'blend');
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function test_procedure() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
procedure_1(8, 2);
|
||||
assertEquals($proc_z, 4, 'procedure with global');
|
||||
$proc_w = false;
|
||||
@@ -1509,13 +1428,13 @@ function test_procedure() {
|
||||
|
||||
// Describe this function...
|
||||
function procedure_1($proc_x, $proc_y) {
|
||||
global $test_name, $naked, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$proc_z = $proc_x / $proc_y;
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function procedure_2($proc_x) {
|
||||
global $test_name, $naked, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
if ($proc_x) {
|
||||
return;
|
||||
}
|
||||
@@ -1524,7 +1443,7 @@ function procedure_2($proc_x) {
|
||||
|
||||
// Describe this function...
|
||||
function test_function() {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
assertEquals(function_1(2, 3), -1, 'function with arguments');
|
||||
assertEquals($func_z, 'side effect', 'function with side effect');
|
||||
$func_a = 'unchanged';
|
||||
@@ -1537,21 +1456,21 @@ function test_function() {
|
||||
|
||||
// Describe this function...
|
||||
function function_1($func_x, $func_y) {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_a, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$func_z = 'side effect';
|
||||
return $func_x - $func_y;
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function function_2($func_a) {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
$func_a += 1;
|
||||
return $func_a . $func_c;
|
||||
}
|
||||
|
||||
// Describe this function...
|
||||
function function_3($func_a) {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $n, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
if ($func_a) {
|
||||
return true;
|
||||
}
|
||||
@@ -1560,7 +1479,7 @@ function function_3($func_a) {
|
||||
|
||||
// Describe this function...
|
||||
function recurse($n) {
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $i, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
global $test_name, $naked, $proc_x, $proc_y, $func_x, $func_y, $func_a, $ok, $log, $count, $varToChange, $rand, $item, $text, $number_of_calls, $list2, $proc_z, $func_z, $x, $proc_w, $func_c, $if2, $loglist, $changing_list, $list_copy, $unittestResults;
|
||||
if ($n > 0) {
|
||||
$text = implode('', array(recurse($n - 1),$n,recurse($n - 1)));
|
||||
} else {
|
||||
@@ -1643,7 +1562,6 @@ test_trim();
|
||||
test_count_text();
|
||||
test_text_reverse();
|
||||
test_replace();
|
||||
test_multiline();
|
||||
print(unittest_report());
|
||||
$unittestResults = null;
|
||||
|
||||
@@ -1672,15 +1590,6 @@ test_lists_reverse();
|
||||
print(unittest_report());
|
||||
$unittestResults = null;
|
||||
|
||||
$unittestResults = array();
|
||||
print("\n====================\n\nRunning suite: Colour\n");
|
||||
test_colour_picker();
|
||||
test_blend();
|
||||
test_rgb();
|
||||
test_colour_random();
|
||||
print(unittest_report());
|
||||
$unittestResults = null;
|
||||
|
||||
$unittestResults = array();
|
||||
print("\n====================\n\nRunning suite: Variables\n");
|
||||
$item = 123;
|
||||
|
||||
@@ -27,7 +27,6 @@ x = None
|
||||
proc_w = None
|
||||
func_c = None
|
||||
if2 = None
|
||||
i = None
|
||||
loglist = None
|
||||
changing_list = None
|
||||
list_copy = None
|
||||
@@ -73,7 +72,7 @@ def fail(message):
|
||||
|
||||
# Describe this function...
|
||||
def test_if():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
if False:
|
||||
fail('if false')
|
||||
ok = False
|
||||
@@ -105,7 +104,7 @@ def test_if():
|
||||
|
||||
# Describe this function...
|
||||
def test_ifelse():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
ok = False
|
||||
if True:
|
||||
ok = True
|
||||
@@ -121,7 +120,7 @@ def test_ifelse():
|
||||
|
||||
# Describe this function...
|
||||
def test_equalities():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(2 == 2, True, 'Equal yes')
|
||||
assertEquals(3 == 4, False, 'Equal no')
|
||||
assertEquals(5 != 6, True, 'Not equal yes')
|
||||
@@ -137,7 +136,7 @@ def test_equalities():
|
||||
|
||||
# Describe this function...
|
||||
def test_and():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(True and True, True, 'And true/true')
|
||||
assertEquals(False and True, False, 'And false/true')
|
||||
assertEquals(True and False, False, 'And true/false')
|
||||
@@ -145,7 +144,7 @@ def test_and():
|
||||
|
||||
# Describe this function...
|
||||
def test_or():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(True or True, True, 'Or true/true')
|
||||
assertEquals(False or True, True, 'Or false/true')
|
||||
assertEquals(True or False, True, 'Or true/false')
|
||||
@@ -153,13 +152,13 @@ def test_or():
|
||||
|
||||
# Describe this function...
|
||||
def test_ternary():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(42 if True else 99, 42, 'if true')
|
||||
assertEquals(42 if False else 99, 99, 'if true')
|
||||
|
||||
# Describe this function...
|
||||
def test_foreach():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
log = ''
|
||||
for x in ['a', 'b', 'c']:
|
||||
log = str(log) + str(x)
|
||||
@@ -167,7 +166,7 @@ def test_foreach():
|
||||
|
||||
# Describe this function...
|
||||
def test_repeat():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
count = 0
|
||||
for count2 in range(10):
|
||||
count = (count if isinstance(count, Number) else 0) + 1
|
||||
@@ -175,7 +174,7 @@ def test_repeat():
|
||||
|
||||
# Describe this function...
|
||||
def test_while():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
while False:
|
||||
fail('while 0')
|
||||
while not True:
|
||||
@@ -191,7 +190,7 @@ def test_while():
|
||||
|
||||
# Describe this function...
|
||||
def test_repeat_ext():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
count = 0
|
||||
for count3 in range(10):
|
||||
count = (count if isinstance(count, Number) else 0) + 1
|
||||
@@ -209,7 +208,7 @@ def downRange(start, stop, step):
|
||||
|
||||
# Describe this function...
|
||||
def test_count_by():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
log = ''
|
||||
for x in range(1, 9, 2):
|
||||
log = str(log) + str(x)
|
||||
@@ -245,7 +244,7 @@ def test_count_by():
|
||||
|
||||
# Describe this function...
|
||||
def test_count_loops():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
log = ''
|
||||
for x in range(1, 9):
|
||||
log = str(log) + str(x)
|
||||
@@ -269,7 +268,7 @@ def test_count_loops():
|
||||
|
||||
# Describe this function...
|
||||
def test_continue():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
log = ''
|
||||
count = 0
|
||||
while count != 8:
|
||||
@@ -301,7 +300,7 @@ def test_continue():
|
||||
|
||||
# Describe this function...
|
||||
def test_break():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
count = 1
|
||||
while count != 10:
|
||||
if count == 5:
|
||||
@@ -329,7 +328,7 @@ def test_break():
|
||||
|
||||
# Tests the "single" block.
|
||||
def test_single():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(math.sqrt(25), 5, 'sqrt')
|
||||
assertEquals(math.fabs(-25), 25, 'abs')
|
||||
assertEquals(-(-25), 25, 'negate')
|
||||
@@ -341,7 +340,7 @@ def test_single():
|
||||
# Tests the "arithmetic" block for all operations and checks
|
||||
# parenthesis are properly generated for different orders.
|
||||
def test_arithmetic():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(1 + 2, 3, 'add')
|
||||
assertEquals(1 - 2, -1, 'subtract')
|
||||
assertEquals(1 - (0 + 2), -1, 'subtract order with add')
|
||||
@@ -355,7 +354,7 @@ def test_arithmetic():
|
||||
|
||||
# Tests the "trig" block.
|
||||
def test_trig():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(math.sin(90 / 180.0 * math.pi), 1, 'sin')
|
||||
assertEquals(math.cos(180 / 180.0 * math.pi), -1, 'cos')
|
||||
assertEquals(math.tan(0 / 180.0 * math.pi), 0, 'tan')
|
||||
@@ -365,7 +364,7 @@ def test_trig():
|
||||
|
||||
# Tests the "constant" blocks.
|
||||
def test_constant():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(math.floor(math.pi * 1000), 3141, 'const pi')
|
||||
assertEquals(math.floor(math.e * 1000), 2718, 'const e')
|
||||
assertEquals(math.floor(((1 + math.sqrt(5)) / 2) * 1000), 1618, 'const golden')
|
||||
@@ -394,7 +393,7 @@ def math_isPrime(n):
|
||||
|
||||
# Tests the "number property" blocks.
|
||||
def test_number_properties():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(42 % 2 == 0, True, 'even')
|
||||
assertEquals(42.1 % 2 == 1, False, 'odd')
|
||||
assertEquals(math_isPrime(5), True, 'prime 5')
|
||||
@@ -411,14 +410,14 @@ def test_number_properties():
|
||||
|
||||
# Tests the "round" block.
|
||||
def test_round():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(round(42.42), 42, 'round')
|
||||
assertEquals(math.ceil(-42.42), -42, 'round up')
|
||||
assertEquals(math.floor(42.42), 42, 'round down')
|
||||
|
||||
# Tests the "change" block.
|
||||
def test_change():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
varToChange = 100
|
||||
varToChange = (varToChange if isinstance(varToChange, Number) else 0) + 42
|
||||
assertEquals(varToChange, 142, 'change')
|
||||
@@ -470,7 +469,7 @@ def first_index(my_list, elem):
|
||||
|
||||
# Tests the "list operation" blocks.
|
||||
def test_operations_on_list():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(sum([3, 4, 5]), 12, 'sum')
|
||||
assertEquals(min([3, 4, 5]), 3, 'min')
|
||||
assertEquals(max([3, 4, 5]), 5, 'max')
|
||||
@@ -483,43 +482,43 @@ def test_operations_on_list():
|
||||
|
||||
# Tests the "mod" block.
|
||||
def test_mod():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(42 % 5, 2, 'mod')
|
||||
|
||||
# Tests the "constrain" block.
|
||||
def test_constraint():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(min(max(100, 0), 42), 42, 'constraint')
|
||||
|
||||
# Tests the "random integer" block.
|
||||
def test_random_integer():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
rand = random.randint(5, 10)
|
||||
assertEquals(rand >= 5 and rand <= 10, True, 'randRange')
|
||||
assertEquals(rand % 1 == 0, True, 'randInteger')
|
||||
|
||||
# Tests the "random fraction" block.
|
||||
def test_random_fraction():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
rand = random.random()
|
||||
assertEquals(rand >= 0 and rand <= 1, True, 'randFloat')
|
||||
|
||||
# Describe this function...
|
||||
def test_atan2():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(math.atan2(5, -5) / math.pi * 180, 135, 'atan2')
|
||||
assertEquals(math.atan2(-12, 0) / math.pi * 180, -90, 'atan2')
|
||||
|
||||
# Checks that the number of calls is one in order
|
||||
# to confirm that a function was only called once.
|
||||
def check_number_of_calls(test_name):
|
||||
global naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
test_name = str(test_name) + 'number of calls'
|
||||
assertEquals(number_of_calls, 1, test_name)
|
||||
|
||||
# Tests the "create text with" block with varying number of inputs.
|
||||
def test_create_text():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals('', '', 'no text')
|
||||
assertEquals('Hello', 'Hello', 'create single')
|
||||
assertEquals(str(-1), '-1', 'create single number')
|
||||
@@ -530,12 +529,12 @@ def test_create_text():
|
||||
|
||||
# Creates an empty string for use with the empty test.
|
||||
def get_empty():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
return ''
|
||||
|
||||
# Tests the "is empty" block".
|
||||
def test_empty_text():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(not len('Google'), False, 'not empty')
|
||||
assertEquals(not len(''), True, 'empty')
|
||||
assertEquals(not len(get_empty()), True, 'empty complex')
|
||||
@@ -543,14 +542,14 @@ def test_empty_text():
|
||||
|
||||
# Tests the "length" block.
|
||||
def test_text_length():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(len(''), 0, 'zero length')
|
||||
assertEquals(len('Google'), 6, 'non-zero length')
|
||||
assertEquals(len('car' if True else None), 3, 'length order')
|
||||
|
||||
# Tests the "append text" block with different types of parameters.
|
||||
def test_append():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
item = 'Miserable'
|
||||
item = str(item) + 'Failure'
|
||||
assertEquals(item, 'MiserableFailure', 'append text')
|
||||
@@ -563,7 +562,7 @@ def test_append():
|
||||
|
||||
# Tests the "find" block with a variable.
|
||||
def test_find_text_simple():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
text = 'Banana'
|
||||
assertEquals(text.find('an') + 1, 2, 'find first simple')
|
||||
assertEquals(text.rfind('an') + 1, 4, 'find last simple')
|
||||
@@ -571,13 +570,13 @@ def test_find_text_simple():
|
||||
|
||||
# Creates a string for use with the find test.
|
||||
def get_fruit():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = (number_of_calls if isinstance(number_of_calls, Number) else 0) + 1
|
||||
return 'Banana'
|
||||
|
||||
# Tests the "find" block with a function call.
|
||||
def test_find_text_complex():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = 0
|
||||
assertEquals(get_fruit().find('an') + 1, 2, 'find first complex')
|
||||
check_number_of_calls('find first complex')
|
||||
@@ -603,7 +602,7 @@ def text_random_letter(text):
|
||||
|
||||
# Tests the "get letter" block with a variable.
|
||||
def test_get_text_simple():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
text = 'Blockly'
|
||||
assertEquals(text[0], 'B', 'get first simple')
|
||||
assertEquals(text[-1], 'y', 'get last simple')
|
||||
@@ -616,13 +615,13 @@ def test_get_text_simple():
|
||||
|
||||
# Creates a string for use with the get test.
|
||||
def get_Blockly():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = (number_of_calls if isinstance(number_of_calls, Number) else 0) + 1
|
||||
return 'Blockly'
|
||||
|
||||
# Tests the "get letter" block with a function call.
|
||||
def test_get_text_complex():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
text = 'Blockly'
|
||||
number_of_calls = 0
|
||||
assertEquals(get_Blockly()[0], 'B', 'get first complex')
|
||||
@@ -658,13 +657,13 @@ def test_get_text_complex():
|
||||
|
||||
# Creates a string for use with the substring test.
|
||||
def get_numbers():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = (number_of_calls if isinstance(number_of_calls, Number) else 0) + 1
|
||||
return '123456789'
|
||||
|
||||
# Tests the "get substring" block with a variable.
|
||||
def test_substring_simple():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
text = '123456789'
|
||||
assertEquals(text[1 : 3], '23', 'substring # simple')
|
||||
assertEquals(text[int((2 if True else None) - 1) : int(3 if True else None)], '23', 'substring # simple order')
|
||||
@@ -685,7 +684,7 @@ def test_substring_simple():
|
||||
|
||||
# Tests the "get substring" block with a function call.
|
||||
def test_substring_complex():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = 0
|
||||
assertEquals(get_numbers()[1 : 3], '23', 'substring # complex')
|
||||
check_number_of_calls('substring # complex')
|
||||
@@ -733,7 +732,7 @@ def test_substring_complex():
|
||||
|
||||
# Tests the "change casing" block.
|
||||
def test_case():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
text = 'Hello World'
|
||||
assertEquals(text.upper(), 'HELLO WORLD', 'uppercase')
|
||||
assertEquals((text if True else None).upper(), 'HELLO WORLD', 'uppercase order')
|
||||
@@ -746,7 +745,7 @@ def test_case():
|
||||
|
||||
# Tests the "trim" block.
|
||||
def test_trim():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
text = ' abc def '
|
||||
assertEquals(text.strip(), 'abc def', 'trim both')
|
||||
assertEquals((text if True else None).strip(), 'abc def', 'trim both order')
|
||||
@@ -757,7 +756,7 @@ def test_trim():
|
||||
|
||||
# Tests the "trim" block.
|
||||
def test_count_text():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
text = 'woolloomooloo'
|
||||
assertEquals(text.count('o'), 8, 'len 1')
|
||||
assertEquals(text.count('oo'), 4, 'len 2')
|
||||
@@ -769,7 +768,7 @@ def test_count_text():
|
||||
|
||||
# Tests the "trim" block.
|
||||
def test_text_reverse():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(''[::-1], '', 'empty string')
|
||||
assertEquals('a'[::-1], 'a', 'len 1')
|
||||
assertEquals('ab'[::-1], 'ba', 'len 2')
|
||||
@@ -777,7 +776,7 @@ def test_text_reverse():
|
||||
|
||||
# Tests the "trim" block.
|
||||
def test_replace():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals('woolloomooloo'.replace('oo', '123'), 'w123ll123m123l123', 'replace all instances 1')
|
||||
assertEquals('woolloomooloo'.replace('.oo', 'X'), 'woolloomooloo', 'literal string replacement')
|
||||
assertEquals('woolloomooloo'.replace('abc', 'X'), 'woolloomooloo', 'not found')
|
||||
@@ -786,30 +785,16 @@ def test_replace():
|
||||
assertEquals('aaaaa'.replace('a', ''), '', 'empty replacement 3')
|
||||
assertEquals(''.replace('a', 'chicken'), '', 'empty source')
|
||||
|
||||
# Tests the "multiline" block.
|
||||
def test_multiline():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals('', '', 'no text')
|
||||
assertEquals('Google', 'Google', 'simple')
|
||||
assertEquals('paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'paragraph' + '\n' +
|
||||
'with newlines' + '\n' +
|
||||
'yup', 'no compile error with newlines')
|
||||
assertEquals(('bark bark' + '\n' +
|
||||
'bark bark bark' + '\n' +
|
||||
'bark bark bark bark').count('bark'), 9, 'count with newlines')
|
||||
|
||||
# Checks that the number of calls is one in order
|
||||
# to confirm that a function was only called once.
|
||||
def check_number_of_calls2(test_name):
|
||||
global naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
test_name = str(test_name) + 'number of calls'
|
||||
assertEquals(number_of_calls, 1, test_name)
|
||||
|
||||
# Tests the "create list with" and "create empty list" blocks.
|
||||
def test_create_lists():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals([], [], 'create empty')
|
||||
assertEquals([True, 'love'], [True, 'love'], 'create items')
|
||||
assertEquals(['Eject'] * 3, ['Eject', 'Eject', 'Eject'], 'create repeated')
|
||||
@@ -817,12 +802,12 @@ def test_create_lists():
|
||||
|
||||
# Creates an empty list for use with the empty test.
|
||||
def get_empty_list():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
return []
|
||||
|
||||
# Tests the "is empty" block.
|
||||
def test_lists_empty():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(not len([0]), False, 'not empty')
|
||||
assertEquals(not len([]), True, 'empty')
|
||||
assertEquals(not len(get_empty_list()), True, 'empty complex')
|
||||
@@ -830,7 +815,7 @@ def test_lists_empty():
|
||||
|
||||
# Tests the "length" block.
|
||||
def test_lists_length():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(len([]), 0, 'zero length')
|
||||
assertEquals(len(['cat']), 1, 'one length')
|
||||
assertEquals(len(['cat', True, []]), 3, 'three length')
|
||||
@@ -843,7 +828,7 @@ def last_index(my_list, elem):
|
||||
|
||||
# Tests the "find" block with a variable.
|
||||
def test_find_lists_simple():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Alice', 'Eve', 'Bob', 'Eve']
|
||||
assertEquals(first_index(list2, 'Eve'), 2, 'find first simple')
|
||||
assertEquals(last_index(list2, 'Eve'), 4, 'find last simple')
|
||||
@@ -851,13 +836,13 @@ def test_find_lists_simple():
|
||||
|
||||
# Creates a list for use with the find test.
|
||||
def get_names():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = (number_of_calls if isinstance(number_of_calls, Number) else 0) + 1
|
||||
return ['Alice', 'Eve', 'Bob', 'Eve']
|
||||
|
||||
# Tests the "find" block with a function call.
|
||||
def test_find_lists_complex():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = 0
|
||||
assertEquals(first_index(get_names(), 'Eve'), 2, 'find first complex')
|
||||
check_number_of_calls('find first complex')
|
||||
@@ -879,7 +864,7 @@ def test_find_lists_complex():
|
||||
|
||||
# Tests the "get" block with a variable.
|
||||
def test_get_lists_simple():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Kirk', 'Spock', 'McCoy']
|
||||
assertEquals(list2[0], 'Kirk', 'get first simple')
|
||||
assertEquals(list2[-1], 'McCoy', 'get last simple')
|
||||
@@ -892,7 +877,7 @@ def test_get_lists_simple():
|
||||
|
||||
# Tests the "get" block with create list call.
|
||||
def test_get_lists_create_list():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(['Kirk', 'Spock', 'McCoy'][0], 'Kirk', 'get first create list')
|
||||
assertEquals(['Kirk', 'Spock', 'McCoy'][-1], 'McCoy', 'get last simple')
|
||||
assertEquals(first_index(['Kirk', 'Spock', 'McCoy'], random.choice(['Kirk', 'Spock', 'McCoy'])) > 0, True, 'get random simple')
|
||||
@@ -904,13 +889,13 @@ def test_get_lists_create_list():
|
||||
|
||||
# Creates a list for use with the get test.
|
||||
def get_star_wars():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = (number_of_calls if isinstance(number_of_calls, Number) else 0) + 1
|
||||
return ['Kirk', 'Spock', 'McCoy']
|
||||
|
||||
# Tests the "get" block with a function call.
|
||||
def test_get_lists_complex():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Kirk', 'Spock', 'McCoy']
|
||||
number_of_calls = 0
|
||||
assertEquals(get_star_wars()[0], 'Kirk', 'get first complex')
|
||||
@@ -950,7 +935,7 @@ def lists_remove_random_item(myList):
|
||||
|
||||
# Tests the "get and remove" block.
|
||||
def test_getRemove():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Kirk', 'Spock', 'McCoy']
|
||||
assertEquals(list2.pop(0), 'Kirk', 'getremove first')
|
||||
assertEquals(list2, ['Spock', 'McCoy'], 'getremove first list')
|
||||
@@ -985,7 +970,7 @@ def test_getRemove():
|
||||
|
||||
# Tests the "remove" block.
|
||||
def test_remove():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Kirk', 'Spock', 'McCoy']
|
||||
list2.pop(0)
|
||||
assertEquals(list2, ['Spock', 'McCoy'], 'remove first list')
|
||||
@@ -1021,7 +1006,7 @@ def test_remove():
|
||||
|
||||
# Tests the "set" block.
|
||||
def test_set():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Picard', 'Riker', 'Crusher']
|
||||
list2[0] = 'Jean-Luc'
|
||||
assertEquals(list2, ['Jean-Luc', 'Riker', 'Crusher'], 'set first list')
|
||||
@@ -1060,7 +1045,7 @@ def test_set():
|
||||
|
||||
# Tests the "insert" block.
|
||||
def test_insert():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Picard', 'Riker', 'Crusher']
|
||||
list2.insert(0, 'Data')
|
||||
assertEquals(list2, ['Data', 'Picard', 'Riker', 'Crusher'], 'insert first list')
|
||||
@@ -1099,7 +1084,7 @@ def test_insert():
|
||||
|
||||
# Tests the "get sub-list" block with a variable.
|
||||
def test_sublist_simple():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Columbia', 'Challenger', 'Discovery', 'Atlantis', 'Endeavour']
|
||||
assertEquals(list2[1 : 3], ['Challenger', 'Discovery'], 'sublist # simple')
|
||||
assertEquals(list2[int((2 if True else None) - 1) : int(3 if True else None)], ['Challenger', 'Discovery'], 'sublist # simple order')
|
||||
@@ -1124,13 +1109,13 @@ def test_sublist_simple():
|
||||
|
||||
# Creates a list for use with the sublist test.
|
||||
def get_space_shuttles():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = (number_of_calls if isinstance(number_of_calls, Number) else 0) + 1
|
||||
return ['Columbia', 'Challenger', 'Discovery', 'Atlantis', 'Endeavour']
|
||||
|
||||
# Tests the "get sub-list" block with a function call.
|
||||
def test_sublist_complex():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
number_of_calls = 0
|
||||
assertEquals(get_space_shuttles()[1 : 3], ['Challenger', 'Discovery'], 'sublist # start complex')
|
||||
check_number_of_calls('sublist # start complex')
|
||||
@@ -1178,14 +1163,14 @@ def test_sublist_complex():
|
||||
|
||||
# Tests the "join" block.
|
||||
def test_join():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Vulcan', 'Klingon', 'Borg']
|
||||
assertEquals(','.join(list2), 'Vulcan,Klingon,Borg', 'join')
|
||||
assertEquals(','.join(list2 if True else None), 'Vulcan,Klingon,Borg', 'join order')
|
||||
|
||||
# Tests the "split" block.
|
||||
def test_split():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
text = 'Vulcan,Klingon,Borg'
|
||||
assertEquals(text.split(','), ['Vulcan', 'Klingon', 'Borg'], 'split')
|
||||
assertEquals((text if True else None).split(','), ['Vulcan', 'Klingon', 'Borg'], 'split order')
|
||||
@@ -1207,78 +1192,37 @@ def lists_sort(my_list, type, reverse):
|
||||
|
||||
# Tests the "alphabetic sort" block.
|
||||
def test_sort_alphabetic():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Vulcan', 'klingon', 'Borg']
|
||||
assertEquals(lists_sort(list2, "TEXT", False), ['Borg', 'Vulcan', 'klingon'], 'sort alphabetic ascending')
|
||||
assertEquals(lists_sort(list2 if True else None, "TEXT", False), ['Borg', 'Vulcan', 'klingon'], 'sort alphabetic ascending order')
|
||||
|
||||
# Tests the "alphabetic sort ignore case" block.
|
||||
def test_sort_ignoreCase():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = ['Vulcan', 'klingon', 'Borg']
|
||||
assertEquals(lists_sort(list2, "IGNORE_CASE", False), ['Borg', 'klingon', 'Vulcan'], 'sort ignore case ascending')
|
||||
assertEquals(lists_sort(list2 if True else None, "IGNORE_CASE", False), ['Borg', 'klingon', 'Vulcan'], 'sort ignore case ascending order')
|
||||
|
||||
# Tests the "numeric sort" block.
|
||||
def test_sort_numeric():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = [8, 18, -1]
|
||||
assertEquals(lists_sort(list2, "NUMERIC", True), [18, 8, -1], 'sort numeric descending')
|
||||
assertEquals(lists_sort(list2 if True else None, "NUMERIC", True), [18, 8, -1], 'sort numeric descending order')
|
||||
|
||||
# Tests the "list reverse" block.
|
||||
def test_lists_reverse():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
list2 = [8, 18, -1, 64]
|
||||
assertEquals(list(reversed(list2)), [64, -1, 18, 8], 'reverse a copy')
|
||||
assertEquals(list2, [8, 18, -1, 64], 'reverse a copy original')
|
||||
list2 = []
|
||||
assertEquals(list(reversed(list2)), [], 'empty list')
|
||||
|
||||
# Describe this function...
|
||||
def test_colour_picker():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals('#ff6600', '#ff6600', 'static colour')
|
||||
|
||||
def colour_rgb(r, g, b):
|
||||
r = round(min(100, max(0, r)) * 2.55)
|
||||
g = round(min(100, max(0, g)) * 2.55)
|
||||
b = round(min(100, max(0, b)) * 2.55)
|
||||
return '#%02x%02x%02x' % (r, g, b)
|
||||
|
||||
# Describe this function...
|
||||
def test_rgb():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(colour_rgb(100, 40, 0), '#ff6600', 'from rgb')
|
||||
|
||||
# Describe this function...
|
||||
def test_colour_random():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
for count4 in range(100):
|
||||
item = '#%06x' % random.randint(0, 2**24 - 1)
|
||||
assertEquals(len(item), 7, 'length of random colour string: ' + str(item))
|
||||
assertEquals(item[0], '#', 'format of random colour string: ' + str(item))
|
||||
for i in range(1, 7):
|
||||
assertEquals(0 != 'abcdefABDEF0123456789'.find(item[int((i + 1) - 1)]) + 1, True, ''.join([str(x4) for x4 in ['contents of random colour string: ', item, ' at index: ', i + 1]]))
|
||||
|
||||
def colour_blend(colour1, colour2, ratio):
|
||||
r1, r2 = int(colour1[1:3], 16), int(colour2[1:3], 16)
|
||||
g1, g2 = int(colour1[3:5], 16), int(colour2[3:5], 16)
|
||||
b1, b2 = int(colour1[5:7], 16), int(colour2[5:7], 16)
|
||||
ratio = min(1, max(0, ratio))
|
||||
r = round(r1 * (1 - ratio) + r2 * ratio)
|
||||
g = round(g1 * (1 - ratio) + g2 * ratio)
|
||||
b = round(b1 * (1 - ratio) + b2 * ratio)
|
||||
return '#%02x%02x%02x' % (r, g, b)
|
||||
|
||||
# Describe this function...
|
||||
def test_blend():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(colour_blend('#ff0000', colour_rgb(100, 40, 0), 0.4), '#ff2900', 'blend')
|
||||
|
||||
# Describe this function...
|
||||
def test_procedure():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
procedure_1(8, 2)
|
||||
assertEquals(proc_z, 4, 'procedure with global')
|
||||
proc_w = False
|
||||
@@ -1290,19 +1234,19 @@ def test_procedure():
|
||||
|
||||
# Describe this function...
|
||||
def procedure_1(proc_x, proc_y):
|
||||
global test_name, naked, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
proc_z = proc_x / proc_y
|
||||
|
||||
# Describe this function...
|
||||
def procedure_2(proc_x):
|
||||
global test_name, naked, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
if proc_x:
|
||||
return
|
||||
proc_w = True
|
||||
|
||||
# Describe this function...
|
||||
def test_function():
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
assertEquals(function_1(2, 3), -1, 'function with arguments')
|
||||
assertEquals(func_z, 'side effect', 'function with side effect')
|
||||
func_a = 'unchanged'
|
||||
@@ -1314,28 +1258,28 @@ def test_function():
|
||||
|
||||
# Describe this function...
|
||||
def function_1(func_x, func_y):
|
||||
global test_name, naked, proc_x, proc_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_a, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
func_z = 'side effect'
|
||||
return func_x - func_y
|
||||
|
||||
# Describe this function...
|
||||
def function_2(func_a):
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
func_a = (func_a if isinstance(func_a, Number) else 0) + 1
|
||||
return str(func_a) + str(func_c)
|
||||
|
||||
# Describe this function...
|
||||
def function_3(func_a):
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, n, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
if func_a:
|
||||
return True
|
||||
return False
|
||||
|
||||
# Describe this function...
|
||||
def recurse(n):
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, i, loglist, changing_list, list_copy, unittestResults
|
||||
global test_name, naked, proc_x, proc_y, func_x, func_y, func_a, ok, log, count, varToChange, rand, item, text, number_of_calls, list2, proc_z, func_z, x, proc_w, func_c, if2, loglist, changing_list, list_copy, unittestResults
|
||||
if n > 0:
|
||||
text = ''.join([str(x5) for x5 in [recurse(n - 1), n, recurse(n - 1)]])
|
||||
text = ''.join([str(x4) for x4 in [recurse(n - 1), n, recurse(n - 1)]])
|
||||
else:
|
||||
text = '-'
|
||||
return text
|
||||
@@ -1414,7 +1358,6 @@ test_trim()
|
||||
test_count_text()
|
||||
test_text_reverse()
|
||||
test_replace()
|
||||
test_multiline()
|
||||
print(unittest_report())
|
||||
unittestResults = None
|
||||
|
||||
@@ -1443,15 +1386,6 @@ test_lists_reverse()
|
||||
print(unittest_report())
|
||||
unittestResults = None
|
||||
|
||||
unittestResults = []
|
||||
print('\n====================\n\nRunning suite: Colour')
|
||||
test_colour_picker()
|
||||
test_blend()
|
||||
test_rgb()
|
||||
test_colour_random()
|
||||
print(unittest_report())
|
||||
unittestResults = None
|
||||
|
||||
unittestResults = []
|
||||
print('\n====================\n\nRunning suite: Variables')
|
||||
item = 123
|
||||
|
||||
@@ -321,7 +321,6 @@ h1 {
|
||||
<block type="text_count"></block>
|
||||
<block type="text_replace"></block>
|
||||
<block type="text_reverse"></block>
|
||||
<block type="text_multiline"></block>
|
||||
</category>
|
||||
<category name="Lists" colour="260">
|
||||
<block type="lists_create_empty"></block>
|
||||
@@ -337,12 +336,6 @@ h1 {
|
||||
<block type="lists_split"></block>
|
||||
<block type="lists_reverse"></block>
|
||||
</category>
|
||||
<category name="Colour" colour="20">
|
||||
<block type="colour_picker"></block>
|
||||
<block type="colour_random"></block>
|
||||
<block type="colour_rgb"></block>
|
||||
<block type="colour_blend"></block>
|
||||
</category>
|
||||
<sep></sep>
|
||||
<category name="Variables" colour="330" custom="VARIABLE"></category>
|
||||
<category name="Functions" colour="290" custom="PROCEDURE"></category>
|
||||
@@ -364,7 +357,6 @@ h1 {
|
||||
<input type="checkbox" class="suite_checkbox" value="math.xml">Math</input><br/>
|
||||
<input type="checkbox" class="suite_checkbox" value="text.xml">Text</input><br/>
|
||||
<input type="checkbox" class="suite_checkbox" value="lists.xml">Lists</input><br/>
|
||||
<input type="checkbox" class="suite_checkbox" value="colour.xml">Colour</input><br/>
|
||||
<input type="checkbox" class="suite_checkbox" value="variables.xml">Variables</input><br/>
|
||||
<input type="checkbox" class="suite_checkbox" value="functions.xml">Functions</input><br/>
|
||||
</div>
|
||||
|
||||
@@ -46,11 +46,6 @@
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test replace"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test multiline"></mutation>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
@@ -4653,93 +4648,4 @@
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="14063">
|
||||
<field name="NAME">test multiline</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "multiline" block.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">no text</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">simple</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT">Google</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">Google</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">no compile error with newlines</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT">paragraph with newlines yup</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT">paragraph with newlines yup</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count with newlines</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_count">
|
||||
<value name="SUB">
|
||||
<block type="text">
|
||||
<field name="TEXT">bark</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TEXT">
|
||||
<block type="text_multiline">
|
||||
<field name="TEXT">bark bark bark bark bark bark bark bark bark</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">9</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</xml>
|
||||
Reference in New Issue
Block a user