Changeset View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Formation.js
- This file was added.
Engine.LoadComponentScript("interfaces/Timer.js"); | |||||
Engine.LoadComponentScript("interfaces/Formation.js"); | |||||
Engine.LoadComponentScript("Formation.js"); | |||||
const entity_id = 5; | |||||
AddMock(SYSTEM_ENTITY, IID_Timer, { | |||||
"SetInterval": () => {}, | |||||
"SetTimeout": () => {}, | |||||
}); | |||||
const formationTemplate = { | |||||
"RequiredMemberCount" : 2, | |||||
Lint: key-spacing: Extra space after key 'RequiredMemberCount'. | |||||
"DisabledTooltip": "", | |||||
Done Inline ActionsCan someone tell me how I need to format these strings so that it actually works? marder: Can someone tell me how I need to format these strings so that it actually works? | |||||
"SpeedMultiplier": 1, | |||||
"FormationShape": "square", | |||||
"MaxTurningAngle": 0, | |||||
"SortingClasses": "Hero Champion Cavalry Melee Ranged", | |||||
"SortingOrder": "fillToTheCenter", | |||||
"ShiftRows": false, | |||||
"UnitSeparationWidthMultiplier": 1, | |||||
"UnitSeparationDepthMultiplier": 1, | |||||
"WidthDepthRatio": 1, | |||||
"Sloppiness": 0 | |||||
}; | |||||
Done Inline ActionsInline this pls Silier: Inline this pls | |||||
Not Done Inline ActionsYou can mock the timer outside of setting the entity up. Freagarach: You can mock the timer outside of setting the entity up. | |||||
const cmpFormation = ConstructComponent(entity_id, "Formation", formationTemplate); | |||||
const testingAngles = []; | |||||
for (let i = 0; i < 179; i++) { | |||||
Lint: brace-rules/brace-on-same-line Opening curly brace appears on the same line as controlling statement. Lint: brace-rules/brace-on-same-line: Opening curly brace appears on the same line as controlling statement. | |||||
testingAngles.push(i * Math.PI / 180); | |||||
} | |||||
Not Done Inline ActionsWhy var? Freagarach: Why `var`? | |||||
TS_ASSERT(testingAngles.every(x => !cmpFormation.AreAnglesSimilar(0, x))); | |||||
Not Done Inline ActionsTo me it seems strange that cmpFormation.AreAnglesSimilar(0, 0) returns false. Freagarach: To me it seems strange that `cmpFormation.AreAnglesSimilar(0, 0)` returns `false`. | |||||
TS_ASSERT(testingAngles.every(x => !cmpFormation.AreAnglesSimilar(0, -x))); | |||||
cmpFormation.maxTurningAngle = Math.PI; | |||||
TS_ASSERT(testingAngles.every(x => cmpFormation.AreAnglesSimilar(0, x))); | |||||
TS_ASSERT(testingAngles.every(x => cmpFormation.AreAnglesSimilar(0, -x))); | |||||
Done Inline Actionscould it be possible that this doesn't work? marder: could it be possible that this doesn't work? | |||||
Not Done Inline ActionsYou test that at least one angle is not the similar, but you still don't know which one it is. So it might count x == 0 as not similar, while we don't expect that? Freagarach: You test that at least one angle is not the similar, but you still don't know which one it is. | |||||
Not Done Inline ActionsThis one _is_ correct. Freagarach: This one _is_ correct. | |||||
Not Done Inline Actionsthis.maxTurningAngle is what you need to match. :) Freagarach: `this.maxTurningAngle` is what you need to match. :) | |||||
Done Inline ActionsI thought I test that _every_ angle is not similar. So the test fails if at least one is similar, i.e. if AreAnglesSimilar(0, x) is true at some point, or to rephrase it, if the difference of any two tested angles is smaller than 0. And from testing in the browser console : let a = 0; let b = 0; let c = 0; let d = Math.abs(a - b) % (2 * Math.PI); console.log(d < c || d > 2 * Math.PI - c) gives false, marder: I thought I test that _every_ angle is not similar. So the test fails if at least one is… | |||||
Not Done Inline ActionsTS_ASSERT_EQUALS(testingAngles.every(x => { warn(uneval(x)); return cmpFormation.AreAnglesSimilar(0, x); }), false); results in only 0 printed. Freagarach: ```
TS_ASSERT_EQUALS(testingAngles.every(x => {
warn(uneval(x));
return cmpFormation. |
Extra space after key 'RequiredMemberCount'.