User talk:TedSwippet/Interactive calculator

Inlining documentation
Did you know that via Documentation content can also be fed directly as text. For example:

--Peculiar Investor 18:39, 26 January 2021 (UTC)
 * I didn't, but I do now! Incorporated. Thanks. --TedSwippet 11:27, 27 January 2021 (UTC)

A few basic feature tests
 (function {  if (!('calc_persistent' in window)) {    document.write(" No calculator found on this page!\n ");    return;  }  var persistent = window.calc_persistent;  for (var prefix in persistent) {    if (!(prefix == 'counter'))      break;  }

var setup = function(values) { for (var id in values) { var element = document.getElementById(prefix + id); element.value = values[id]; } };

var execute = function { calc_v1.calculate(prefix, 'twr'); var element = document.getElementById(prefix + 'result'); return element.value; };

var passed = 0, failed = 0; var record = function(values, result, expect) { if (result == expect) { passed++; var outcome = 'PASS'; } else { failed++; var outcome = 'FAIL'; }   document.write('Test:' + JSON.stringify(values)                   + ', result:' + result + ', expect:' + expect                   + ', ' + outcome + '\n'); };

var run_test = function(values, expect) { setup(values); record(values, execute, expect); };

document.write(' '); run_test({l1tw: 0, l2tw: 30, yield: 1.74, ter: 0.03}, '0.5130%'); run_test({l1tw: 15, l2tw: 0, yield: 1.74, ter: 0.07}, '0.2610%'); run_test({l1tw: 3.9, l2tw: 30, yield: 2, ter: 0.08}, '0.6306%'); run_test({l1tw: 10.3, l2tw: 0, yield: 2, ter: 0.22}, '0.2060%'); run_test({l1tw: 0, l2tw: 0, yield: 0, ter: 0.1},     'Error!'); var tested = passed + failed; document.write('Tested:' + tested + ', passed:' + passed + ', failed:' + failed + '\n'); document.write(' '); var t = 'Tested!'; setup({l1tw: t, l2tw: t, yield: t, ter: t, result: t}); }); --TedSwippet 11:56, 30 January 2021 (UTC)