Double_X

DoubleX RMMV Skill Progress Unit Test v100a

Dec 3rd, 2019
346
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.  *    ## Plugin Info
  3.  *----------------------------------------------------------------------------
  4.  *    # Plugin Name
  5.  *      DoubleX RMMV Skill Progress Unit Test
  6.  *----------------------------------------------------------------------------
  7.  *    # Introduction
  8.  *    1. This plugin performs some rudimetary invariants checking for the
  9.  *       implementations of DoubleX RMMV Skill Progress, and some elementary
  10.  *       value validity checking for the parameters/configurations/notetags of
  11.  *       DoubleX RMMV Skill Progress
  12.  *    2. You can setup how this plugin displays the failed test messages with
  13.  *       their stacktraces
  14.  *----------------------------------------------------------------------------
  15.  *    # Terms Of Use
  16.  *      1. Commercial use's always allowed and crediting me's always optional.
  17.  *      2. You shall keep this plugin's Plugin Info part's contents intact.
  18.  *      3. You shalln't claim that this plugin's written by anyone other than
  19.  *         DoubleX or my aliases. I always reserve the right to deny you from
  20.  *         using any of my plugins anymore if you've violated this.
  21.  *      4. If you repost this plugin directly(rather than just linking back),
  22.  *         you shall inform me of these direct repostings. I always reserve
  23.  *         the right to request you to edit those direct repostings.
  24.  *      5. CC BY 4.0, except those conflicting with any of the above, applies
  25.  *         to this plugin, unless you've my permissions not needing follow so.
  26.  *      6. I always reserve the right to deny you from using this plugin
  27.  *         anymore if you've violated any of the above.
  28.  *----------------------------------------------------------------------------
  29.  *    # Prerequisites
  30.  *      Plugins:
  31.  *      1. DoubleX RMMV Skill Progress
  32.  *      Abilities:
  33.  *      1. Nothing special for most ordinary cases
  34.  *      2. Little RMMV plugin development proficiency to fully utilize this
  35.  *----------------------------------------------------------------------------
  36.  *    # Author Notes
  37.  *      1. Using this plugin might lead to noticeable performance penalties
  38.  *----------------------------------------------------------------------------
  39.  *    # Links
  40.  *      DoubleX RMMV Skill Progress:
  41.  *      1. https://pastebin.com/6XdtFJYD
  42.  *      This plugin:
  43.  *      1. https://pastebin.com/NzQVER8u
  44.  *----------------------------------------------------------------------------
  45.  *    # Instructions
  46.  *      1. Place this plugin right below DoubleX RMMV Skill Progress
  47.  *----------------------------------------------------------------------------
  48.  *    # Author
  49.  *      DoubleX
  50.  *----------------------------------------------------------------------------
  51.  *    # Changelog
  52.  *      v1.00a(GMT 1000 4-Dec-2019):
  53.  *      1. 1st version of this plugin finished
  54.  *============================================================================*/
  55. /*:
  56.  * @plugindesc Lets you run some unit tests for DoubleX RMMV Skill Progress
  57.  * This plugin's entirely optional and is mainly for debuggers/developers
  58.  * @author DoubleX
  59.  *
  60.  *============================================================================
  61.  */
  62.  
  63. var DoubleX_RMMV = DoubleX_RMMV || {};
  64. DoubleX_RMMV["Skill Progress Unit Test"] = "v1.00a";
  65.  
  66. /*============================================================================
  67.  *    ## Plugin Configurations
  68.  *       You only need to edit this part as it's about what this plugin does
  69.  *----------------------------------------------------------------------------*/
  70.  
  71. DoubleX_RMMV.Skill_Progress_Unit_Test = {
  72.  
  73.     /**
  74.      * Shows the failed parameter test with its value, condition and error
  75.      * Hotspot/No-op
  76.      * @since v1.00a @version v1.00a
  77.      * @param {*} val - The actual parameter value
  78.      * @param {String} param - The parameter being tested
  79.      * @param {String} cond - The parameter validity condition description
  80.      */
  81.     showFailMsg: function(val, param, cond) {
  82.         try { x; } catch (err) {
  83.             console.warn([
  84.                 "The " + param + " in DoubleX RMMV Skill Progress has value:",
  85.                 val,
  86.                 "Which isn't valid because:",
  87.                 cond,
  88.                 "The source is shown by this stacktrace:",
  89.                 err.stack
  90.             ].join("\n"));
  91.         }
  92.     } // showFailMsg
  93.  
  94. }; // DoubleX_RMMV.Skill_Progress
  95.  
  96. /*============================================================================
  97.  *    ## Plugin Implementations
  98.  *       You need not edit this part as it's about how this plugin works
  99.  *----------------------------------------------------------------------------
  100.  *    # Plugin Support Info:
  101.  *      1. Prerequisites
  102.  *         - Basic knowledge on what unit tests do
  103.  *         - Some RMMV plugin development proficiency to fully comprehend this
  104.  *----------------------------------------------------------------------------*/
  105.  
  106. if (DoubleX_RMMV["Skill Progress"]) {
  107.  
  108. /*----------------------------------------------------------------------------*/
  109.  
  110. (function(SP, SPUT) {
  111.  
  112.     "use strict";
  113.  
  114.     // Stores all the original parameter/configuration/notetag functions
  115.     SPUT.orig = { params: {}, cfgs: {}, notes: {} };
  116.     //
  117.  
  118.     // Stores all the parameter/configuration/notetag function unit tests
  119.     SPUT.unitTest = {
  120.         // Stores all the parameter function unit tests
  121.         params: {
  122.             isEnabled: "checkBool",
  123.             condNotePriority: "checkArrayDataType",
  124.             condNoteChainingRule: "checkChainBoolRule",
  125.             defaultMax: "checkPositiveNum",
  126.             maxNotePriority: "checkArrayDataType",
  127.             maxNoteChainingRule: "checkChainNumRule",
  128.             defaultUseGain: "checkNum",
  129.             useGainNotePriority: "checkArrayDataType",
  130.             useGainNoteChainingRule: "checkChainNumRule",
  131.             defaultHitGain: "checkNum",
  132.             hitGainNotePriority: "checkArrayDataType",
  133.             hitGainNoteChainingRule: "checkChainNumRule",
  134.             nextNotePriority: "checkArrayDataType",
  135.             nextNoteChainingRule: "checkChainListRule",
  136.             defaultKeepCurrent: "checkBool",
  137.             keepCurrentNotePriority: "checkArrayDataType",
  138.             keepCurrentNoteChainingRule: "checkChainBoolRule",
  139.             // There's no need to test this parameter as it returns nothing
  140.             willEnd: "",
  141.             //
  142.             willEndNotePriority: "checkArrayDataType",
  143.             willEndNoteChainingRule: "checkChainListRule",
  144.             // There's no need to test this parameter as it returns nothing
  145.             didEnd: "",
  146.             //
  147.             didEndNotePriority: "checkArrayDataType",
  148.             didEndNoteChainingRule: "checkChainListRule",
  149.             cmdLineH: "checkPositiveNum",
  150.             cmdFontSize: "checkPositiveNum",
  151.             cmdPadding: "checkNonnegativeNum",
  152.             cmdTextPadding: "checkNonnegativeNum",
  153.             cmdBackOpacity: "checkOpacity",
  154.             cmdTranslucentOpacity: "checkOpacity",
  155.             cmdSpacing: "checkNonnegativeNum",
  156.             cmdWinW: "checkPositiveNum",
  157.             cmdWinH: "checkPositiveNum",
  158.             cmdWinX: "checkNum",
  159.             cmdWinY: "checkNum",
  160.             cmdView: "checkString",
  161.             cmdUse: "checkString",
  162.             statLineH: "checkPositiveNum",
  163.             statFontSize: "checkPositiveNum",
  164.             statPadding: "checkNonnegativeNum",
  165.             statTextPadding: "checkNonnegativeNum",
  166.             statBackOpacity: "checkOpacity",
  167.             statTranslucentOpacity: "checkOpacity",
  168.             statSpacing: "checkNonnegativeNum",
  169.             statWinW: "checkPositiveNum",
  170.             statWinH: "checkPositiveNum",
  171.             statWinX: "checkNum",
  172.             statWinY: "checkNum",
  173.             condLineH: "checkPositiveNum",
  174.             condFontSize: "checkPositiveNum",
  175.             condPadding: "checkNonnegativeNum",
  176.             condTextPadding: "checkNonnegativeNum",
  177.             condBackOpacity: "checkOpacity",
  178.             condTranslucentOpacity: "checkOpacity",
  179.             condSpacing: "checkNonnegativeNum",
  180.             condWinW: "checkPositiveNum",
  181.             condWinH: "checkPositiveNum",
  182.             condWinX: "checkNum",
  183.             condWinY: "checkNum",
  184.             nextLineH: "checkPositiveNum",
  185.             nextFontSize: "checkPositiveNum",
  186.             nextPadding: "checkNonnegativeNum",
  187.             nextTextPadding: "checkNonnegativeNum",
  188.             nextBackOpacity: "checkOpacity",
  189.             nextTranslucentOpacity: "checkOpacity",
  190.             nextSpacing: "checkNonnegativeNum",
  191.             nextWinW: "checkPositiveNum",
  192.             nextWinH: "checkPositiveNum",
  193.             nextWinX: "checkNum",
  194.             nextWinY: "checkNum",
  195.             varIds: "checkIdVarArrayNoteFactorObj",
  196.             switchIds: "checkIdSwitchArrayNoteFactorObj"
  197.         }, // params
  198.         // Stores all the configuration function unit tests
  199.         cfgs: {
  200.           // There's no need to test this parameter as it returns nothing
  201.           drawStat: ""
  202.           //
  203.         }, // cfgs
  204.         //
  205.         notes: {}, // Stores all the notetag function unit tests
  206.         // Stores all the notetag type result unit tests
  207.         noteTypes: {
  208.             cond: "checkArray",
  209.             max: "checkPositiveNumArray",
  210.             useGain: "checkNumArray",
  211.             hitGain: "checkNumArray",
  212.             next: "checkIdSkillArray",
  213.             keepCurrent: "checkArray",
  214.             // There's no need to test these parameters as they return nothing
  215.             willEnd: "",
  216.             didEnd: ""
  217.             //
  218.         },
  219.         //
  220.         // Stores all the chained notetag type result unit tests
  221.         chainedNoteTypes: {
  222.             cond: "checkBoolObj",
  223.             max: "checkPositiveNum",
  224.             useGain: "checkNum",
  225.             hitGain: "checkNum",
  226.             next: "checkIdSkillArray",
  227.             keepCurrent: "checkBool",
  228.             // There's no need to test these parameters as they return nothing
  229.             willEnd: "",
  230.             didEnd: ""
  231.             //
  232.         }
  233.         //
  234.     }; // SPUT.unitTest
  235.  
  236.     // There's no need to test this parameter as it's always valid
  237.     var notes = SPUT.unitTest.notes, checkFunc = new Function("val", "");
  238.     //
  239.     Object.keys(SP.notes).forEach(function(note) { notes[note] = checkFunc; });
  240.  
  241.     // Stores all the unit test value validity checks
  242.     SPUT.checkFuncs = {
  243.  
  244.         /**
  245.          * Hotspot/Pure Function
  246.          * @param {*} val - The actual parameter value
  247.          * @param {String} param - The parameter being tested
  248.          * @returns {Boolean} The check result
  249.          * @since v1.00a @version v1.00a
  250.          */
  251.         checkArray: function(val, param) {
  252.             if (Array.isArray(val)) return true;
  253.             return SPUT.showFailMsg(val, param, "It should be an Array!");
  254.         }, // checkArray
  255.  
  256.         /**
  257.          * Hotspot/No-op
  258.          * @param {*} val - The actual parameter value
  259.          * @param {String} param - The parameter being tested
  260.          * @since v1.00a @version v1.00a
  261.          */
  262.         checkArrayDataType: function(val, param) {
  263.             SPUT.checkFuncs.checkArrayVals(val, param,
  264.                     ["states", "armors", "weapons", "currentClass", "actor"]);
  265.         }, // checkArrayDataType
  266.  
  267.         /**
  268.          * Hotspot/No-op
  269.          * @param {*} val - The actual parameter value
  270.          * @param {String} param - The parameter being tested
  271.          * @param {[]} vals - The list of valid primitive values
  272.          * @since v1.00a @version v1.00a
  273.          */
  274.         checkArrayVals: function(val, param, vals) {
  275.             if (!SPUT.checkFuncs.checkArray(val, param)) return;
  276.             var cond = [
  277.                 "These elements should be within " + vals + ":"
  278.             ].concat(val.map(function(v, i) {
  279.                 return vals.indexOf(v) >= 0 ? "" : v + " with index " + i;
  280.             }).filter(function(m) { return m; }));
  281.             if (cond.length <= 1) return;
  282.             SPUT.showFailMsg(JSON.stringify(val), param, cond.join("\n"));
  283.         }, // checkArrayVals
  284.  
  285.         /**
  286.          * Hotspot/No-op
  287.          * @param {*} val - The actual parameter value
  288.          * @param {String} param - The parameter being tested
  289.          * @since v1.00a @version v1.00a
  290.          */
  291.         checkBool: function(val, param) {
  292.             if (val === !!val) return;
  293.             SPUT.showFailMsg(val, param, "It should be a Boolean!");
  294.         }, // checkBool
  295.  
  296.         /**
  297.          * Hotspot/No-op
  298.          * @param {*} val - The actual parameter value
  299.          * @param {String} param - The parameter being tested
  300.          * @since v1.00a @version v1.00a
  301.          */
  302.         checkBoolObj: function(val, param) {
  303.             if (!SPUT.checkFuncs.checkObj(val, param)) return;
  304.             Object.keys(val).forEach(function(key) {
  305.                 SPUT.checkFuncs.checkBool(val[key], JSON.stringify({
  306.                     param: param,
  307.                     key: key
  308.                 }));
  309.             });
  310.         }, // checkBoolObj
  311.  
  312.         /**
  313.          * Hotspot/No-op
  314.          * @param {*} val - The actual parameter value
  315.          * @param {String} param - The parameter being tested
  316.          * @since v1.00a @version v1.00a
  317.          */
  318.         checkChainBoolRule: function(val, param) {
  319.             SPUT.checkFuncs.checkVal(
  320.                     val, param, ["first", "every", "last", "some"]);
  321.         }, // checkChainBoolRule
  322.  
  323.         /**
  324.          * Hotspot/No-op
  325.          * @param {*} val - The actual parameter value
  326.          * @param {String} param - The parameter being tested
  327.          * @since v1.00a @version v1.00a
  328.          */
  329.         checkChainListRule: function(val, param) {
  330.             SPUT.checkFuncs.checkVal(val, param, Object.keys(
  331.                     SP.Game_SkillProgressRules._RUN_CHAINING_RULES));
  332.         }, // checkChainListRule
  333.  
  334.         /**
  335.          * Hotspot/No-op
  336.          * @param {*} val - The actual parameter value
  337.          * @param {String} param - The parameter being tested
  338.          * @since v1.00a @version v1.00a
  339.          */
  340.         checkChainNumRule: function(val, param) {
  341.             SPUT.checkFuncs.checkVal(val, param,
  342.                     ["first", "+", "-", "*", "/", "%", "=", "last"]);
  343.         }, // checkChainNumRule
  344.  
  345.         /**
  346.          * Hotspot/No-op
  347.          * @param {*} val - The actual parameter value
  348.          * @param {String} param - The parameter being tested
  349.          * @param {[{}]} data - The list of data to check the id array
  350.          * @param {String} type - The data container name
  351.          * @since v1.00a @version v1.00a
  352.          */
  353.         checkIdDataArray: function(val, param, data, type) {
  354.             if (!SPUT.checkFuncs.checkArray(val, param)) return;
  355.             var cond = [
  356.                 "These elements should be a valid " + type + " id :"
  357.             ].concat(val.map(function(v, i) {
  358.                 var d = data[v];
  359.                 return d || d === false ? "" : v + " with index " + i;
  360.             }).filter(function(m) { return m; }));
  361.             if (cond.length <= 1) return;
  362.             SPUT.showFailMsg(JSON.stringify(val), param, cond.join("\n"));
  363.         }, // checkIdDataArray
  364.  
  365.         /**
  366.          * Hotspot/No-op
  367.          * @param {*} val - The actual parameter value
  368.          * @param {String} param - The parameter being tested
  369.          * @param {[{}]} data - The list of data to check the id array
  370.          * @param {String} type - The data container name
  371.          * @since v1.00a @version v1.00a
  372.          */
  373.         checkIdGameArrayNoteFactorObj: function(val, param, data, type) {
  374.             if (Array.isArray(val)) {
  375.                 return SPUT.checkFuncs.checkIdDataArray(val, param, data, type);
  376.             }
  377.             if (!SPUT.checkFuncs.checkObj(val, param)) return;
  378.             var ids = Object.keys(val);
  379.             SPUT.checkFuncs.checkIdDataArray(ids.map(function(id) {
  380.                 return +id;
  381.             }), param, data, type);
  382.             var _SP = SP.Game_SkillProgressCache;
  383.             var notes = _SP._NOTES, factors = _SP._FACTORS;
  384.             ids.forEach(function(id) {
  385.                 var noteFactors = ids[id];
  386.                 SPUT.checkFuncs.checkArrayVals(noteFactors.notes, param, notes);
  387.                 SPUT.checkFuncs.checkArrayVals(
  388.                         noteFactors.factors, param, factors);
  389.             });
  390.         }, // checkIdGameArrayNoteFactorObj
  391.  
  392.         /**
  393.          * Hotspot/No-op
  394.          * @param {*} val - The actual parameter value
  395.          * @param {String} param - The parameter being tested
  396.          * @since v1.00a @version v1.00a
  397.          */
  398.         checkIdSkillArray: function(val, param) {
  399.             SPUT.checkFuncs.checkIdDataArray(
  400.                     val, param, $dataSkills, "skill");
  401.         }, // checkIdSkillArray
  402.  
  403.         /**
  404.          * Hotspot/No-op
  405.          * @param {*} val - The actual parameter value
  406.          * @param {String} param - The parameter being tested
  407.          * @since v1.00a @version v1.00a
  408.          */
  409.         checkIdSwitchArrayNoteFactorObj: function(val, param) {
  410.             SPUT.checkFuncs.checkIdGameArrayNoteFactorObj(
  411.                     val, param, $gameSwitches._data, "switch");
  412.         }, // checkIdSwitchArrayNoteFactorObj
  413.  
  414.         /**
  415.          * Hotspot/No-op
  416.          * @param {*} val - The actual parameter value
  417.          * @param {String} param - The parameter being tested
  418.          * @since v1.00a @version v1.00a
  419.          */
  420.         checkIdVarArrayNoteFactorObj: function(val, param) {
  421.             SPUT.checkFuncs.checkIdGameArrayNoteFactorObj(
  422.                     val, param, $gameVariables._data, "variable");
  423.         }, // checkIdVarArrayNoteFactorObj
  424.  
  425.         /**
  426.          * Hotspot/No-op
  427.          * @param {*} val - The actual parameter value
  428.          * @param {String} param - The parameter being tested
  429.          * @since v1.00a @version v1.00a
  430.          */
  431.         checkNonnegativeNum: function(val, param) {
  432.             if (isNaN(val) || val < 0) SPUT.showFailMsg(
  433.                     val, param, "It should be a nonnegative Number!");
  434.         }, // checkNonnegativeNum
  435.  
  436.         /**
  437.          * Hotspot/No-op
  438.          * @param {*} val - The actual parameter value
  439.          * @param {String} param - The parameter being tested
  440.          * @since v1.00a @version v1.00a
  441.          */
  442.         checkNum: function(val, param) {
  443.             if (!isNaN(val)) return;
  444.             SPUT.showFailMsg(val, param, "It should be a Number!");
  445.         }, // checkNum
  446.  
  447.         /**
  448.          * Hotspot/No-op
  449.          * @param {*} val - The actual parameter value
  450.          * @param {String} param - The parameter being tested
  451.          * @since v1.00a @version v1.00a
  452.          */
  453.         checkNumArray: function(val, param) {
  454.             if (!SPUT.checkFuncs.checkArray(val, param)) return;
  455.             val.forEach(function(v, i) {
  456.                 SPUT.checkFuncs.checkNum(v,
  457.                         JSON.stringify({ array: val, index: i, param: param }));
  458.             });
  459.         }, // checkNumArray
  460.  
  461.         /**
  462.          * Hotspot/No-op
  463.          * @param {*} val - The actual parameter value
  464.          * @param {String} param - The parameter being tested
  465.          * @returns {Boolean} The check result
  466.          * @since v1.00a @version v1.00a
  467.          */
  468.         checkObj: function(val, param) {
  469.             if (val === Object(val)) return true;
  470.             return SPUT.showFailMsg(val, param, "It should be an Object!");
  471.         }, // checkObj
  472.  
  473.         /**
  474.          * Hotspot/No-op
  475.          * @param {*} val - The actual parameter value
  476.          * @param {String} param - The parameter being tested
  477.          * @since v1.00a @version v1.00a
  478.          */
  479.         checkOpacity: function(val, param) {
  480.               if (isNaN(val) || val < 0 && val > 255) SPUT.showFailMsg(val,
  481.                       param, "It should be a Number ranging from 0 to 255!");
  482.         }, // checkOpacity
  483.  
  484.         /**
  485.          * Hotspot/No-op
  486.          * @param {*} val - The actual parameter value
  487.          * @param {String} param - The parameter being tested
  488.          * @since v1.00a @version v1.00a
  489.          */
  490.         checkPositiveNum: function(val, param) {
  491.             if (!isNaN(val) && val > 0) return;
  492.             SPUT.showFailMsg(val, param, "It should be a positive Number!");
  493.         }, // checkPositiveNum
  494.  
  495.         /**
  496.          * Hotspot/No-op
  497.          * @param {*} val - The actual parameter value
  498.          * @param {String} param - The parameter being tested
  499.          * @since v1.00a @version v1.00a
  500.          */
  501.         checkPositiveNumArray: function(val, param) {
  502.             if (!SPUT.checkFuncs.checkArray(val, param)) return;
  503.             val.forEach(function(v, i) {
  504.                 SPUT.checkFuncs.checkPositiveNum(v,
  505.                         JSON.stringify({ array: val, index: i, param: param }));
  506.             });
  507.         }, // checkPositiveNumArray
  508.  
  509.         /**
  510.          * Hotspot/No-op
  511.          * @param {*} val - The actual parameter value
  512.          * @param {String} param - The parameter being tested
  513.          * @since v1.00a @version v1.00a
  514.          */
  515.         checkString: function(val, param) {
  516.             if (typeof val === "string" || val instanceof String) return;
  517.             SPUT.showFailMsg(val, param, "It should be a String!");
  518.         }, // checkString
  519.  
  520.         /**
  521.          * Hotspot/No-op
  522.          * @param {*} val - The actual parameter value
  523.          * @param {String} param - The parameter being tested
  524.          * @param {[*]} vals - The list of valid values
  525.          * @since v1.00a @version v1.00a
  526.          */
  527.         checkVal: function(val, param, vals) {
  528.             if (vals.indexOf(val) >= 0) return;
  529.             SPUT.showFailMsg(val, param, "It should be within " + vals + "!");
  530.         } // checkVal
  531.  
  532.     }; // SPUT.checkFuncs
  533.     //
  534.  
  535.     /**
  536.      * Pure function
  537.      * @param {String} type - The parameter/configuration/notetag indicator
  538.      * @param {String} param - The parameter being tested
  539.      * @param {(*, String)} checkFunc - The function checking the actual value
  540.      * @returns {() -> *} The function returning the original result
  541.      * @since v1.00a @version v1.00a
  542.      */
  543.     SPUT.unitTestFunc = function(type, param, checkFunc) {
  544.         /**
  545.          * The this pointer refers to that of the original function counterpart
  546.          * Nullipotent
  547.          * @author DoubleX
  548.          * @returns {*} The requested result
  549.          * @since v1.00a
  550.          * @version v1.00a
  551.          */
  552.         return function() {
  553.             // It's possible that SPUT.orig[type][param] will change on the fly
  554.             var val = SPUT.orig[type][param].apply(this, arguments);
  555.             //
  556.             // Added to test the parameter/configuration/notetag value validity
  557.             checkFunc(val, type + "." + param);
  558.             //
  559.             return val;
  560.         };
  561.  
  562.     }; // SPUT.unitTestFunc
  563.  
  564. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  565.  
  566. /*----------------------------------------------------------------------------
  567.  *    # Edit class: DataManager
  568.  *      - Extends all parameter/configuration/notetag functions upon load game
  569.  *----------------------------------------------------------------------------*/
  570.  
  571. (function(SP, SPUT) {
  572.  
  573.     "use strict";
  574.  
  575.     SP.DataManager.unitTest = { orig: {}, new: {} };
  576.     var _SP = SP.DataManager.new;
  577.     var _DM = SP.DataManager.unitTest.orig, _UT = SP.DataManager.unitTest.new;
  578.  
  579.     _DM._extractFuncContent = _SP._extractFuncContent;
  580.     _SP._extractFuncContent = function(funcType, content) {
  581.     // v1.00a - v1.00a; Extended
  582.         _DM._extractFuncContent.apply(this, arguments);
  583.         // Added to unit test the value validity of param/cfg/note functions
  584.         _UT._extractFuncContent.call(this, funcType, content);
  585.         //
  586.     }; // _SP._extractFuncContent
  587.  
  588.     /**
  589.      * The this pointer is DataManager
  590.      * @param {String} funcType - The parameter/configuration/notetag label
  591.      * @param {String} content - The name of the stored function content
  592.      * @since v1.00a @version v1.00a
  593.      */
  594.     _UT._extractFuncContent = function(funcType, content) {
  595.         // This function should be so stable that it shouldn't be changed later
  596.         var checkFunc = SPUT.checkFuncs[SPUT.unitTest[funcType][content]];
  597.         //
  598.         if (!checkFunc) return;
  599.         SPUT.orig[funcType][content] = SP[funcType][content];
  600.         // Using partial application here would erase the function context
  601.         SP[funcType][content] = SPUT.unitTestFunc(funcType, content, checkFunc);
  602.         //
  603.     }; // _UT._extractFuncContent
  604.  
  605. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  606.  
  607. /*----------------------------------------------------------------------------
  608.  *    # Edit class: Game_System
  609.  *      - Extends all parameter/configuration/notetag functions upon load game
  610.  *----------------------------------------------------------------------------*/
  611.  
  612. (function(SP, SPUT) {
  613.  
  614.     "use strict";
  615.  
  616.     SP.Game_System.unitTest = { orig: {}, new: {} };
  617.     var _SP = SP.Game_System.new;
  618.     var _GS = SP.Game_System.unitTest.orig, _UT = SP.Game_System.unitTest.new;
  619.  
  620.     _GS._storeParam = _SP._storeParam;
  621.     _SP._storeParam = function(params, param) { // v1.00a - v1.00a; Extended
  622.         // Added to prevent storing the extended parameter function contents
  623.         if (SPUT.orig.params[param]) return;
  624.         //
  625.         _GS._storeParam.apply(this, arguments);
  626.         // Added to unit test the value validity of all parameter functions
  627.         _UT._storeCfg.call(this, "params", param);
  628.         //
  629.     }; // _SP._storeParam
  630.  
  631.     _GS._storeCfg = _SP._storeCfg;
  632.     _SP._storeCfg = function(cfgType, cfg) { // v1.00a - v1.00a; Extended
  633.         // Edited to prevent storing the extended cfg/note function contents
  634.         if (SPUT.orig[cfgType][cfg]) return;
  635.         //
  636.         _GS._storeCfg.apply(this, arguments);
  637.         // Added to unit test the value validity of all cfg/note functions
  638.         _UT._storeCfg.call(this, cfgType, cfg);
  639.         //
  640.     }; // _SP._storeCfg
  641.  
  642.     /**
  643.      * The this pointer is Game_Actor.prototype
  644.      * @param {String} cfgType - The configuration type label
  645.      * @param {String} cfg - The name of the configuration
  646.      * @since v1.00a @version v1.00a
  647.      */
  648.     _UT._storeCfg = function(cfgType, cfg) {
  649.         // This function should be so stable that it shouldn't be changed later
  650.         var checkFunc = SPUT.checkFuncs[SPUT.unitTest[cfgType][cfg]];
  651.         //
  652.         if (!checkFunc) return;
  653.         SPUT.orig[cfgType][cfg] = SP[cfgType][cfg];
  654.         // Using partial application here would erase the function context
  655.         SP[cfgType][cfg] = SPUT.unitTestFunc(cfgType, cfg, checkFunc);
  656.         //
  657.     }; // _UT._storeCfg
  658.  
  659. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  660.  
  661. /*----------------------------------------------------------------------------
  662.  *    # Edit class: Game_Actor
  663.  *      - Unit tests all the nontrivial non-tautological class invariants
  664.  *----------------------------------------------------------------------------*/
  665.  
  666. (function(SP, SPUT) {
  667.  
  668.     "use strict";
  669.  
  670.     SP.Game_Actor.unitTest = { orig: {}, new: {} };
  671.     var _SP = SP.Game_Actor.new, $ = Game_Actor.prototype;
  672.     var _GA = SP.Game_Actor.unitTest.orig, _UT = SP.Game_Actor.unitTest.new;
  673.  
  674.     // Only interfaces will have their argument invariants checked
  675.     Object.keys(_SP._RESULT_FUNCS).concat([
  676.         "onUseGainSkillProgress",
  677.         "onHitGainSkillProgress"
  678.     ]).forEach(function(func) {
  679.         _GA[func] = $[func];
  680.         _UT[func] = $[func] = function(skillId, target, value) {
  681.         // v1.00a - v1.00a; Extended
  682.             var result = _GA[func].apply(this, arguments);
  683.             // Added to check whether the skillId and value arguments are valid
  684.             SPUT.checkFuncs.checkIdSkillArray(
  685.                     [skillId], "_GA." + func + " skillId");
  686.             if (value) SPUT.checkFuncs.checkNum(
  687.                     value, "_GA." + func + " value");
  688.             //
  689.             return result;
  690.         }; // $[func]
  691.     });
  692.  
  693.     ["current", "can", "is"].forEach(function(f) {
  694.         var func = f + "SkillProgress";
  695.         _GA[func] = $[func];
  696.         _UT[func] = $[func] = function(skillId) { // v1.00a - v1.00a; Extended
  697.             var result = _GA[func].apply(this, arguments);
  698.             // Added to check whether the skillId argument is a valid skill id
  699.             SPUT.checkFuncs.checkIdSkillArray(
  700.                     [skillId], "_GA." + func + " skillId");
  701.             //
  702.             return result;
  703.         }; // $[func]
  704.     });
  705.  
  706.     _GA.setCurrentSkillProgress = $.setCurrentSkillProgress;
  707.     _UT.setCurrentSkillProgress = $.setCurrentSkillProgress = function(skillId, value) {
  708.      // v1.00a - v1.00a; Extended
  709.         _GA.setCurrentSkillProgress.apply(this, arguments);
  710.         // Added to check whether the skillId and value arguments are valid
  711.         SPUT.checkFuncs.checkIdSkillArray(
  712.                 [skillId], "_GA.setCurrentSkillProgress skillId");
  713.         SPUT.checkFuncs.checkNonnegativeNum(
  714.                 value, "_GA.setCurrentSkillProgress value");
  715.         //
  716.     }; // $.setCurrentSkillProgress
  717.     //
  718.  
  719.     _GA._progressSkill = _SP._progressSkill;
  720.     _SP._progressSkill = function(skillId) { // v1.00a - v1.00a; Extended
  721.         _GA._progressSkill.apply(this, arguments);
  722.         // Added to unit test class invariants involving this function
  723.         _UT._checkProgressSkill.call(this, skillId);
  724.         //
  725.     }; // _SP._progressSkill
  726.  
  727.     /**
  728.      * The this pointer is Game_Actor.prototype
  729.      * No-op
  730.      * @param {Id} skillId - The id of the skill involved
  731.      * @since v1.00a @version v1.00a
  732.      */
  733.     _UT._checkProgressSkill = function(skillId) {
  734.         // It's reasonable to assume that nextSkillProgress won't be random
  735.         var next = this.nextSkillProgress(skillId).filter(function(id) {
  736.             return !this.isLearnedSkill(id);
  737.         }, this);
  738.         //
  739.         if (next.length > 0) SPUT.showFailMsg(JSON.stringify({
  740.             skillId: skillId,
  741.             nextSkillProgress: nextSkillProgress
  742.         }), "_GA._progressSkill", "They should be learnt!");
  743.         // It's reasonable to assume that isKeepSkillProgress won't be random
  744.         var isKeep = this.isKeepSkillProgress(skillId);
  745.         //
  746.         if (isKeep !== this.isLearnedSkill(skillId)) {
  747.             SPUT.showFailMsg(JSON.stringify({
  748.                 skillId: skillId,
  749.                 isKeepSkillProgress: isKeepSkillProgress
  750.             }), "_GA._progressSkill",
  751.                     isKeep ? "It should be kept" : "It should be forgotten!");
  752.         }
  753.         if (this._skillProgress.isEnded[skillId]) return;
  754.         SPUT.showFailMsg("isEnded", "_GA._progressSkill", "It should be true!");
  755.     }; // _UT._checkProgressSkill
  756.  
  757. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  758.  
  759. /*----------------------------------------------------------------------------
  760.  *    # Edit class: Game_SkillProgressNotes
  761.  *      - Unit tests the chained note results to ensure proper chainings
  762.  *----------------------------------------------------------------------------*/
  763.  
  764.  (function(SP, SPUT) {
  765.  
  766.      "use strict";
  767.  
  768.      var GSPN = SP.Game_SkillProgressNotes.unitTest = { orig: {}, new: {} };
  769.      var $ = Game_SkillProgressNotes.prototype;
  770.      var _GSPN = GSPN.orig, _UT = GSPN.new;
  771.  
  772.     // Only interfaces will have their argument invariants checked
  773.     _GSPN.result = $.result;
  774.     _UT.result = $.result = function(note, skillId, target, value) {
  775.     // v1.00a - v1.00a; Extended
  776.         var result = _GSPN.result.apply(this, arguments);
  777.         // Added to check whether the arguments except target are valid
  778.         SPUT.checkFuncs.checkVal(
  779.                 note, "_GSPN.result note", SP.Game_SkillProgressCache._NOTES);
  780.         SPUT.checkFuncs.checkIdSkillArray([skillId], "_GSPN.result skillId");
  781.         if (value) SPUT.checkFuncs.checkNum(value, "_GSPN.result value");
  782.         //
  783.         return result;
  784.     }; // $.result
  785.  
  786.     _GSPN.run = $.run;
  787.     _UT.run = $.run = function(notes, skillId) {
  788.     // v1.00a - v1.00a; Extended
  789.         _GSPN.run.apply(this, arguments);
  790.         // Added to check whether the notes and skillId arguments are valid
  791.         SPUT.checkFuncs.checkArrayVals(
  792.                 notes, "_GSPN.run notes", SP.Game_SkillProgressCache._NOTES);
  793.         SPUT.checkFuncs.checkIdSkillArray([skillId], "_GSPN.run skillId");
  794.         //
  795.     }; // $.run
  796.     //
  797.  
  798.     _GSPN._uncachedResult = $._uncachedResult;
  799.     _UT._uncachedResult = $._uncachedResult = function(note, skillId, target, value) {
  800.     // v1.00a - v1.00a; Extended
  801.         var result = _GSPN._uncachedResult.apply(this, arguments);
  802.         // Added to unit test the chained result of this note type
  803.         _UT._checkUncachedResult.call(
  804.                 this, note, skillId, target, value, result);
  805.         //
  806.         return result;
  807.     }; // $._uncachedResult
  808.  
  809.     /**
  810.      * @since v1.00a @version v1.00a
  811.      * @param {String} note - The note to have its end result retrieved
  812.      * @param {Id} skillId - The id of the skill involved
  813.      * @param {Game_Battler?} target - The target hit by the skill involved
  814.      * @param {Number?} value - The damage of the hit involved
  815.      * @param {*} result - The result from all effective notetags involved
  816.      */
  817.     _UT._checkUncachedResult = function(note, skillId, target, value, result) {
  818.         var func = SPUT.checkFuncs[SPUT.unitTest.chainedNoteTypes[note]];
  819.         if (func) func(result, JSON.stringify({
  820.             note: note,
  821.             skillId: skillId,
  822.             target: target ? target.name() : "No target",
  823.             hitDamage: value || "No hit"
  824.         }));
  825.     }; // _UT._checkUncachedResult
  826.  
  827. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  828.  
  829. /*----------------------------------------------------------------------------
  830.  *    # Edit class: Game_SkillProgressPairs
  831.  *      - Unit tests all data notetags to pinpoint the data with faulty notes
  832.  *----------------------------------------------------------------------------*/
  833.  
  834.  (function(SP, SPUT) {
  835.  
  836.      "use strict";
  837.  
  838.      var GSPP = SP.Game_SkillProgressPairs.unitTest = { orig: {}, new: {} };
  839.      var $ = Game_SkillProgressPairs.prototype;
  840.      var _GSPP = GSPP.orig, _UT = GSPP.new;
  841.  
  842.     _GSPP.run = $.run;
  843.     _UT.run = $.run = function(skillId, note, datum, target, value) {
  844.     // v1.00a - v1.00a; Extended
  845.         var results = _GSPP.run.apply(this, arguments);
  846.         // Added to unit test the notetag result of this datum
  847.         _UT._checkRun.call(this, skillId, note, datum, target, value, results);
  848.         //
  849.         return results;
  850.     }; // $.run
  851.  
  852.     /**
  853.      * @since v1.00a @version v1.00a
  854.      * @param {Id} skillId - The id of the skill involved
  855.      * @param {String} note - The note to have its contents run
  856.      * @param {{*}} datum - The datum having the note to have its contents run
  857.      * @param {Game_Battler?} target - The target hit by the skill involved
  858.      * @param {Number?} value - The damage of the hit involved
  859.      * @param {[*]} results - The result of the notetag function involved
  860.      */
  861.     _UT._checkRun = function(skillId, note, datum, target, value, results) {
  862.         var func = SPUT.checkFuncs[SPUT.unitTest.noteTypes[note]];
  863.         if (func) func(results, JSON.stringify({
  864.             skillId: skillId,
  865.             note: note,
  866.             dataId: datum ? datum.id : "No datum",
  867.             dataName: datum ? datum.name : "No datum",
  868.             target: target ? target.name() : "No target",
  869.             hitDamage: value || "No hit"
  870.         }));
  871.     }; // _UT._checkRun
  872.  
  873. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  874.  
  875. /*----------------------------------------------------------------------------
  876.  *    # Edit class: Window_SkillProgressStat/Cond/Next
  877.  *      - Unit tests all the interface argument invariants
  878.  *----------------------------------------------------------------------------*/
  879.  
  880. (function(SP, SPUT) {
  881.  
  882.     "use strict";
  883.  
  884.     var classes = {
  885.         Window_SkillProgressStat: Window_SkillProgressStat.prototype,
  886.         Window_SkillProgressCond: Window_SkillProgressCond.prototype,
  887.         Window_SkillProgressNext: Window_SkillProgressNext.prototype
  888.     };
  889.     Object.keys(classes).forEach(function(klass) {
  890.  
  891.         SP[klass] = { unitTest: { orig: {}, new: {} } };
  892.         var WSP = SP[klass].unitTest, $ = classes[klass];
  893.         var _WSP = WSP.orig, _UT = WSP.new;
  894.  
  895.         _WSP.setup = $.setup;
  896.         _UT.setup = $.setup = function(skillId) { // v1.00a - v1.00a; Extended
  897.             _WSP.setup.apply(this, arguments);
  898.             // Added to check whether the skillId argument is a valid skill id
  899.             SPUT.checkFuncs.checkIdSkillArray([skillId], klass + ".setup");
  900.             //
  901.         }; // $.setup
  902.  
  903.     });
  904.  
  905. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  906.  
  907. /*----------------------------------------------------------------------------*/
  908.  
  909. } else {
  910.     alert("To use Skill Progress Unit Test, place it below Skill Progress.");
  911. } // if (DoubleX_RMMV["Skill Progress"])
  912.  
  913. /*============================================================================*/
RAW Paste Data