From 9da721b2ccc7e3e77fedbcbcbff3a3826a20e683 Mon Sep 17 00:00:00 2001 From: bjoluc Date: Thu, 6 Jan 2022 13:11:58 +0100 Subject: [PATCH] some aesthetic changes to the testing examples --- basic-testing/index.html | 70 +++++++++++---------------------- testing-with-jasmine/index.html | 40 ++++++++----------- testing-with-jasmine/tests.js | 22 ++++++----- 3 files changed, 52 insertions(+), 80 deletions(-) diff --git a/basic-testing/index.html b/basic-testing/index.html index dbd0cb1..5ac3ac1 100644 --- a/basic-testing/index.html +++ b/basic-testing/index.html @@ -45,7 +45,7 @@ task: "instructions-check", }, on_finish: (data) => { - data.correct = data.response == jsPsych.timelineVariable("answer"); + data.correct = data.response === jsPsych.timelineVariable("answer"); }, }, ], @@ -68,22 +68,14 @@ ], conditional_function: () => { const ic_data = jsPsych.data.get().filter({ task: "instructions-check" }).last(2); - return !ic_data.select("correct").all((value) => { - return value == true; - }); + return !ic_data.select("correct").all(Boolean); }, }; const instructions_loop = { timeline: [instructions, instruction_check, instructions_check_fail], - loop_function: (data) => { - return !data - .filter({ task: "instructions-check" }) - .select("correct") - .all((value) => { - return value == true; - }); - }, + loop_function: (data) => + !data.filter({ task: "instructions-check" }).select("correct").all(Boolean), }; const pre_task_start = { @@ -105,9 +97,7 @@ }, { type: jsPsychHtmlKeyboardResponse, - stimulus: () => { - return `

${jsPsych.timelineVariable("number")}

`; - }, + stimulus: () => `

${jsPsych.timelineVariable("number")}

`, choices: ["a", "l"], data: { digit: jsPsych.timelineVariable("number"), @@ -141,42 +131,28 @@ // check that there are an equal number of all trial types const all_equal = [ - data.filter({ parity: "odd", magnitude: "small" }).count(), - data.filter({ parity: "odd", magnitude: "large" }).count(), - data.filter({ parity: "even", magnitude: "small" }).count(), - data.filter({ parity: "even", magnitude: "large" }).count(), - ].every((value, i, array) => { - return value === array[0]; - }); + { parity: "odd", magnitude: "small" }, + { parity: "odd", magnitude: "large" }, + { parity: "even", magnitude: "small" }, + { parity: "even", magnitude: "large" }, + ] + .map((properties) => data.filter(properties).count()) + .every((value, i, array) => value === array[0]); - if (all_equal) { - test_results += "

✔️ Equal number of all trial types

"; - } else { - test_results += "

❌ Unequal number of all trial types

"; - } + test_results += all_equal + ? "

✔️ Equal number of all trial types

" + : "

❌ Unequal number of all trial types

"; - // check that answering the instructions incorrectly causes a loop + // check whether answering the instructions incorrectly causes a loop const looped = data.filter({ task: "instructions-check" }).count() > 2; - if ( - !data - .filter({ task: "instructions-check" }) - .first(2) - .select("correct") - .all((x) => { - return x == true; - }) - ) { - if (looped) { - test_results += "

✔️ Instructions looped on check fail

"; - } else { - test_results += "

❌ Instructions did not loop on check fail

"; - } + if (!data.filter({ task: "instructions-check" }).first(2).select("correct").all(Boolean)) { + test_results += looped + ? "

✔️ Instructions looped on check fail

" + : "

❌ Instructions did not loop on check fail

"; } else { - if (!looped) { - test_results += "

✔️ Instructions did not loop on check pass

"; - } else { - test_results += "

❌ Instructions looped on check pass

"; - } + test_results += looped + ? "

❌ Instructions looped on check pass

" + : "

✔️ Instructions did not loop on check pass

"; } jsPsych.getDisplayElement().innerHTML = test_results; diff --git a/testing-with-jasmine/index.html b/testing-with-jasmine/index.html index 5538ca6..2d8e0ab 100644 --- a/testing-with-jasmine/index.html +++ b/testing-with-jasmine/index.html @@ -3,15 +3,12 @@ - - - - + + + + - +