Tutorial: Testron Examples: with different input objects

Testron Examples: with different input objects

Testron through different objects with JSON structure

Select a way to parse a "question-battery":

Constructor.   Object.   String.
//CONSTRUCTOR
var test = new testron.Test(
  {container: "divUI", markerContainer: "divMarker", 
  stopOnSuccess: false, digits: 2, precision: 2}
);
if (testron) {
  var question1 = test.createQuestion({num: 1, solution: 2, txt: "Question 1 ???"});
  var answer1A = question1.createAnswer({name: "A", txt: "Answer A"});
  var answer1B = question1.createAnswer({name: "B", txt: "Answer B"});
  var answer1C = question1.createAnswer({name: "C", txt: "Answer C"});
  
  var question2 = test.createQuestion({num: 2, solution: 3, txt: "Question 2 ???"});
  var answer2A = question2.createAnswer({name: "A", txt: "Answer A"});
  var answer2B = question2.createAnswer({name: "B", txt: "Answer B"});
  var answer2C = question2.createAnswer({name: "C", txt: "Answer C"});
  
  var question3 = test.createQuestion({num: 3, solution: 3, txt: "Question 3 ???"});
  var answer3A = question3.createAnswer({name: "A", txt: "Answer A"});
  var answer3B = question3.createAnswer({name: "B", txt: "Answer B"});
  var answer3C = question3.createAnswer({name: "C", txt: "Answer C"});
  
  var question4 = test.createQuestion({num: 4, solution: 1, txt: "Question 4 ???"});
  var answer4A = question4.createAnswer({name: "A", txt: "Answer A"});
  var answer4B = question4.createAnswer({name: "B", txt: "Answer B"});
  var answer4C = question4.createAnswer({name: "C", txt: "Answer C"});

  var container = document.getElementById("contUI");
  container.appendChild(test.toHtml());
  var marker = test.createMarker();
  if (marker) { container2.appendChild(marker.toHtml()); }
  //START
  test.emitMarker();
}
              
//WITH JS OBJECT (JSON STRUCTURE)
/** Javascript Object (with JSON structure) is valid to creation test of 'testron' type */
tests = {
  testrons: [
    {
      conf: {
        className:"testron test-80",container:"container",markerContainer:"container2",
        remove:true,markerRemove:true,nQ:4,nA:12,digits:2,precision:2,
        stopOnSuccess:true,charset:"utf-8"
      },
      questions: [
        {
          conf: {
            num:1,nA:3,solution:2,charset:"utf-8",
            txt:"How many electrical magnitudes has the \"Ohm's Law\" ?"
          },
          answers: [
            {name:"A",charset:"utf-8",txt:"One (❶)"},
            {name:"B",charset:"utf-8",txt:"Three (❸)"},
            {name:"C",charset:"utf-8",txt:"Zero (❍)"}
          ]
        },
        {
          conf: {
            num:2,nA:3,solution:3,charset:"utf-8",
            txt:"What is the real direction of electrical current ?"
          },
          answers: [
            {name:"A",charset:"utf-8",txt:"Positive to Negative (⊕ → ⊖)"},
            {name:"B",charset:"utf-8",txt:"It depends on whether AC or DC (⇔)"},
            {name:"C",charset:"utf-8",txt:"Negative to Positive (⊖ ← ⊕)"}
          ]
        },
        {
          conf: {
            num:3,nA:3,solution:3,charset:"utf-8",
            txt:"What is the correct formulation to represent the \"Ohm's Law\"?"
          },
          answers: [
            {name:"A",charset:"utf-8",txt:"V = I / R"},
            {name:"B",charset:"utf-8",txt:"I = V * R"},
            {name:"C",charset:"utf-8",txt:"V = I * R"}
          ]
        },
        {
          conf: {
            num:4,nA:3,solution:1,charset:"utf-8",
            txt:"in a DC circuit to which is doubled the load Resistance, what happens to the Potence ?"
          },
          answers: [
            {name:"A",charset:"utf-8",txt:"It is decremented until ¼"},
            {name:"B",charset:"utf-8",txt:"It is incremented on double"},
            {name:"C",charset:"utf-8",txt:"It remains constant as it is not affected by resistance"}
          ]
        }
      ]
    }
  ]
};
              
//WITH JS IMPORTED OBJECT
Import in Header-HTML section a test file with a questions-battery, eg:
  <script src="js/test3-star-wars.js"> </script>
and type a script:
  tests = starWars; //here "starWars" is the defined variable in imported file.
  //TESTRON
  tests = testron.parseTestrons(tests, conf);
              
//WITH JSON OBJECT
{ "testrons": 
  [
    {
      "conf": {"className":"testron test-80", "container":"container", "markerContainer":"container2", 
               "remove":true, "markerRemove":true, "nQ":4, "nA":12, "digits":2, "precision":2, 
               "stopOnSuccess":true, "charset":"utf-8"},
      "questions": [
        {
          "conf": {"num":1, "nA":3, "solution":2, "charset":"utf-8", 
                   "txt":"¿ Cómo se llamaba el caballo de 'Don Quijote' ?"},
          "answers": [
            {"name":"A", "charset":"utf-8", "txt":"Babiera"},
            {"name":"B", "charset":"utf-8", "txt":"Rocinante"},
            {"name":"C", "charset":"utf-8", "txt":"No tenía dinero p'a caballo, iba en burro"}
          ]
        },
        {
          "conf": {"num":2, "nA":3, "solution":3, "charset":"utf-8", 
                   "txt":"¿ De qué color era el caballo blanco de Santiago ?"},
          "answers": [
            {"name":"A", "charset":"utf-8", "txt":"Azul"},
            {"name":"B", "charset":"utf-8", "txt":"transparente"},
            {"name":"C", "charset":"utf-8", "txt":"Blancoooooooo !!!"}
          ]
        },
        {
          "conf": {"num":3, "nA":3, "solution":3, "charset":"utf-8", 
                   "txt":"¿ Cómo se llamaba el famoso caballo del 'Cid Campeador' ?"},
          "answers": [
            {"name":"A", "charset":"utf-8", "txt":"Rocinante"},
            {"name":"B", "charset":"utf-8", "txt":"Atila"},
            {"name":"C", "charset":"utf-8", "txt":"Babieca"}
          ]
        },
        {
          "conf": {"num":4, "nA":3, "solution":1, "charset":"utf-8", 
                   "txt":"¿ Cuántas patas tiene un caballito pequeño ?"},
          "answers": [
            {"name":"A", "charset":"utf-8", "txt":"si es de mar, ninguna"},
            {"name":"B", "charset":"utf-8", "txt":"depende de lo pequeño que sea"},
            {"name":"C", "charset":"utf-8", "txt":"infinitas"}
          ]
        }
      ]
    }
  ]
}
              
//WITH STRING (JSON STRUCTURE)
var tests = '{"testrons": [ {"conf": {"className": "test-80", "markerContainer": "divMarker", ';
    tests += '"stopOnSuccess": true, "digits": 2, "precision": 2}, ';
    tests += '"questions": [ {"conf": {"num": 1, "solution": 2, "txt": "Question 1 ???"}, "answers": [';
    tests += '{"name": "A", "txt": "Answer A"}, {"name": "B", "txt": "Answer B"}, {"name": "C", "txt": "Answer C"}';
    tests += ']}, {"conf": {"num": 2, "solution": 3, "txt": "Question 2 ???"}, "answers": [';
    tests += '{"name": "A", "txt": "Answer A"}, {"name": "B", "txt": "Answer B"}, {"name": "C", "txt": "Answer C"}';
    tests += ']}, {"conf": {"num": 3, "solution": 3, "txt": "Question 3 ???"}, "answers": [';
    tests += '{"name": "A", "txt": "Answer A"}, {"name": "B", "txt": "Answer B"}, {"name": "C", "txt": "Answer C"}';
    tests += ']}, {"conf": {"num": 4, "solution": 1, "txt": "Question 4 ???"}, "answers": [';
    tests += '{"name": "A", "txt": "Answer A"}, {"name": "B", "txt": "Answer B"}, {"name": "C", "txt": "Answer C"}';
    tests += ']}]}, {"another": "test"}]}';
    
    var ts = testron.parseTestrons(tests, {container: "divUI"});
              
SUCCESSED: UPDATE-MARKER -> [FINISH || NEXT] -> OK -> CLICK , FAILURE: UPDATE-MARKER -> FAIL -> CLICK


...

...



based on the 'Doctron template'   by
Δ