How to use randomSource method in wpt

Best JavaScript code snippet using wpt

GURPS.js

Source:GURPS.js Github

copy

Full Screen

1'use strict';2TestSuite.GURPS = {};3TestSuite.GURPS.ReactionRoll = async function(testState={})4{5 TestRunner.clearResults(testState);6 var assertions = [], randomSource, actual;7 try{8 randomSource = numberGenerator.dice(6, [2,3,4]);9 actual = GURPS.ReactionRoll(-30, randomSource);10 assertions.push({Expected: 'Disastrous', Actual: actual, Description: 'Low Disastrous'});11 randomSource = numberGenerator.dice(6, [1,1,1]);12 actual = GURPS.ReactionRoll(-3, randomSource);13 assertions.push({Expected: 'Disastrous', Actual: actual, Description: 'Highest Disastrous'});14 } catch(e){assertions.push({Error: e, Description: 'Disastrous'});}15 try{16 randomSource = numberGenerator.dice(6, [1,1,1]);17 actual = GURPS.ReactionRoll(undefined, randomSource);18 assertions.push({Expected: 'Very Bad', Actual: actual, Description: 'reactionModifier defaults to 0'});19 } catch(e){assertions.push({Error: e, Description: 'reactionModifier defaults to 0'});}20 try{21 GURPS.ReactionRoll('ham');22 TestRunner.failedToThrow(assertions, 'Invalid reactionModifier');23 }24 catch(e)25 {26 assertions.push({Expected: getError(Validation.requireInteger, ['ham']),27 Actual: e, Description: 'Invalid reactionModifier'});28 }29 try{30 randomSource = numberGenerator.dice(6, [1,1,1]);31 actual = GURPS.ReactionRoll(-2, randomSource);32 assertions.push({Expected: 'Very Bad', Actual: actual, Description: 'Lowest Very Bad'});33 randomSource = numberGenerator.dice(6, [1,1,1]);34 actual = GURPS.ReactionRoll(-1, randomSource);35 assertions.push({Expected: 'Very Bad', Actual: actual, Description: 'Mid Very Bad'});36 randomSource = numberGenerator.dice(6, [1,1,1]);37 actual = GURPS.ReactionRoll(0, randomSource);38 assertions.push({Expected: 'Very Bad', Actual: actual, Description: 'Highest Very Bad'});39 } catch(e){assertions.push({Error: e, Description: 'Very Bad'});}40 try{41 randomSource = numberGenerator.dice(6, [1,1,1]);42 actual = GURPS.ReactionRoll(1, randomSource);43 assertions.push({Expected: 'Bad', Actual: actual, Description: 'Lowest Bad'});44 randomSource = numberGenerator.dice(6, [1,1,1]);45 actual = GURPS.ReactionRoll(2, randomSource);46 assertions.push({Expected: 'Bad', Actual: actual, Description: 'Mid Bad'});47 randomSource = numberGenerator.dice(6, [1,1,1]);48 actual = GURPS.ReactionRoll(3, randomSource);49 assertions.push({Expected: 'Bad', Actual: actual, Description: 'Highest Bad'});50 } catch(e){assertions.push({Error: e, Description: 'Bad'});}51 try{52 randomSource = numberGenerator.dice(6, [1,2,3]);53 actual = GURPS.ReactionRoll(1, randomSource);54 assertions.push({Expected: 'Poor', Actual: actual, Description: 'Lowest Poor'});55 randomSource = numberGenerator.dice(6, [1,1,6]);56 actual = GURPS.ReactionRoll(0, randomSource);57 assertions.push({Expected: 'Poor', Actual: actual, Description: 'Mid Poor'});58 randomSource = numberGenerator.dice(6, [1,2,6]);59 actual = GURPS.ReactionRoll(0, randomSource);60 assertions.push({Expected: 'Poor', Actual: actual, Description: 'Highest Poor'});61 } catch(e){assertions.push({Error: e, Description: 'Poor'});}62 try{63 randomSource = numberGenerator.dice(6, [1,3,6]);64 actual = GURPS.ReactionRoll(0, randomSource);65 assertions.push({Expected: 'Neutral', Actual: actual, Description: 'Lowest Neutral'});66 randomSource = numberGenerator.dice(6, [1,4,6]);67 actual = GURPS.ReactionRoll(0, randomSource);68 assertions.push({Expected: 'Neutral', Actual: actual, Description: 'Mid Neutral'});69 randomSource = numberGenerator.dice(6, [1,5,6]);70 actual = GURPS.ReactionRoll(0, randomSource);71 assertions.push({Expected: 'Neutral', Actual: actual, Description: 'Highest Neutral'});72 } catch(e){assertions.push({Error: e, Description: 'Neutral'});}73 try{74 randomSource = numberGenerator.dice(6, [1,6,6]);75 actual = GURPS.ReactionRoll(0, randomSource);76 assertions.push({Expected: 'Good', Actual: actual, Description: 'Lowest Good'});77 randomSource = numberGenerator.dice(6, [2,6,6]);78 actual = GURPS.ReactionRoll(0, randomSource);79 assertions.push({Expected: 'Good', Actual: actual, Description: 'Mid Good'});80 randomSource = numberGenerator.dice(6, [3,6,6]);81 actual = GURPS.ReactionRoll(0, randomSource);82 assertions.push({Expected: 'Good', Actual: actual, Description: 'Highest Good'});83 } catch(e){assertions.push({Error: e, Description: 'Good'});}84 try{85 randomSource = numberGenerator.dice(6, [4,6,6]);86 actual = GURPS.ReactionRoll(0, randomSource);87 assertions.push({Expected: 'Very Good', Actual: actual, Description: 'Lowest Very Good'});88 randomSource = numberGenerator.dice(6, [5,6,6]);89 actual = GURPS.ReactionRoll(0, randomSource);90 assertions.push({Expected: 'Very Good', Actual: actual, Description: 'Mid Very Good'});91 randomSource = numberGenerator.dice(6, [6,6,6]);92 actual = GURPS.ReactionRoll(0, randomSource);93 assertions.push({Expected: 'Very Good', Actual: actual, Description: 'Highest Very Good'});94 } catch(e){assertions.push({Error: e, Description: 'Very Good'});}95 try{96 randomSource = numberGenerator.dice(6, [6,6,6]);97 actual = GURPS.ReactionRoll(1, randomSource);98 assertions.push({Expected: 'Excellent', Actual: actual, Description: 'Lowest Excellent'});99 randomSource = numberGenerator.dice(6, [1,2,3]);100 actual = GURPS.ReactionRoll(20, randomSource);101 assertions.push({Expected: 'Excellent', Actual: actual, Description: 'High Excellent'});102 } catch(e){assertions.push({Error: e, Description: 'Excellent'});}103 return TestRunner.displayResults('GURPS GURPS.ReactionRoll', assertions, testState);104};105TestSuite.GURPS.SuccessRoll = async function(testState={})106{107 TestRunner.clearResults(testState);108 var assertions = [], randomSource, actual, expected;109 try{110 randomSource = numberGenerator.dice(6, [1,4,5]);111 actual = GURPS.SuccessRoll(11, randomSource);112 expected = {success: true, critical: false, margin: 1};113 assertions.push({Expected: expected, Actual: actual, Description: 'Happy path'});114 } catch(e){assertions.push({Error: e, Description: 'Happy path'});}115 try{116 GURPS.SuccessRoll('ham');117 TestRunner.failedToThrow(assertions, 'Invalid effectiveSkill');118 }119 catch(e)120 {121 assertions.push({Expected: getError(Validation.requireInteger, ['ham']),122 Actual: e, Description: 'Invalid effectiveSkill'});123 }124 try{125 GURPS.SuccessRoll(-2);126 assertions.push({Expected: 'Didn\'t throw', Actual: 'Didn\'t throw', Description: 'Allows negative effectiveSkill'});127 } catch(e){assertions.push({Error: e, Description: 'Allows negative effectiveSkill'});}128 try{129 randomSource = numberGenerator.dice(6, [1,4,5]);130 actual = GURPS.SuccessRoll(10, randomSource);131 expected = {success: true, critical: false, margin: 0};132 assertions.push({Expected: expected, Actual: actual, Description: 'Margin 0 is a success'});133 } catch(e){assertions.push({Error: e, Description: 'Margin 0 is a success'});}134 try{135 randomSource = numberGenerator.dice(6, [1,4,5]);136 actual = GURPS.SuccessRoll(9, randomSource);137 expected = {success: false, critical: false, margin: 1};138 assertions.push({Expected: expected, Actual: actual, Description: 'Margin is absolute value'});139 } catch(e){assertions.push({Error: e, Description: 'Margin is absolute value'});}140 try{141 randomSource = numberGenerator.dice(6, [1,1,1]);142 actual = GURPS.SuccessRoll(-10, randomSource);143 expected = {success: true, critical: true};144 assertions.push({Expected: expected, Actual: actual, Description: 'Crit success sum 3 trumps low effectiveSkill'});145 randomSource = numberGenerator.dice(6, [1,1,2]);146 actual = GURPS.SuccessRoll(2, randomSource);147 expected = {success: true, critical: true};148 assertions.push({Expected: expected, Actual: actual, Description: 'Crit success sum 4 trumps low effectiveSkill'});149 } catch(e){assertions.push({Error: e, Description: 'Crit success sum 3-4 trumps low effectiveSkill'});}150 try{151 randomSource = numberGenerator.dice(6, [1,1,3]);152 actual = GURPS.SuccessRoll(4, randomSource);153 expected = {success: false, critical: false, margin: 1};154 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 5 failure'});155 randomSource = numberGenerator.dice(6, [1,1,3]);156 actual = GURPS.SuccessRoll(5, randomSource);157 expected = {success: true, critical: false, margin: 0};158 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 5 success'});159 randomSource = numberGenerator.dice(6, [1,1,3]);160 actual = GURPS.SuccessRoll(15, randomSource);161 expected = {success: true, critical: true};162 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 5 critical success with 15'});163 randomSource = numberGenerator.dice(6, [1,1,3]);164 actual = GURPS.SuccessRoll(17, randomSource);165 expected = {success: true, critical: true};166 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 5 critical success with 15+'});167 } catch(e){assertions.push({Error: e, Description: 'Rolled sum 5'});}168 try{169 randomSource = numberGenerator.dice(6, [1,1,4]);170 actual = GURPS.SuccessRoll(4, randomSource);171 expected = {success: false, critical: false, margin: 2};172 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 6 failure'});173 randomSource = numberGenerator.dice(6, [1,1,4]);174 actual = GURPS.SuccessRoll(7, randomSource);175 expected = {success: true, critical: false, margin: 1};176 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 6 success'});177 randomSource = numberGenerator.dice(6, [1,1,4]);178 actual = GURPS.SuccessRoll(16, randomSource);179 expected = {success: true, critical: true};180 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 6 critical success with 16'});181 randomSource = numberGenerator.dice(6, [1,1,4]);182 actual = GURPS.SuccessRoll(17, randomSource);183 expected = {success: true, critical: true};184 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 6 critical success with 16+'});185 } catch(e){assertions.push({Error: e, Description: 'Rolled Sum 6'});}186 try{187 randomSource = numberGenerator.dice(6, [6,6,6]);188 actual = GURPS.SuccessRoll(20, randomSource);189 expected = {success: false, critical: true};190 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 18 Crit failure trumps high effectiveSkill'});191 } catch(e){assertions.push({Error: e, Description: 'Sum 18 Crit failure trumps high effectiveSkill'});}192 try{193 randomSource = numberGenerator.dice(6, [6,6,5]);194 actual = GURPS.SuccessRoll(10, randomSource);195 expected = {success: false, critical: true};196 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 17 critical failure with 15-'});197 randomSource = numberGenerator.dice(6, [6,6,5]);198 actual = GURPS.SuccessRoll(15, randomSource);199 expected = {success: false, critical: true};200 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 17 critical failure with 15'});201 randomSource = numberGenerator.dice(6, [6,6,5]);202 actual = GURPS.SuccessRoll(16, randomSource);203 expected = {success: false, critical: false};204 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 17 failure normal'});205 randomSource = numberGenerator.dice(6, [6,6,5]);206 actual = GURPS.SuccessRoll(17, randomSource);207 expected = {success: false, critical: false};208 assertions.push({Expected: expected, Actual: actual, Description: 'Sum 17 always a failure'});209 } catch(e){assertions.push({Error: e, Description: 'Rolled Sum 17'});}210 try{211 randomSource = numberGenerator.dice(6, [6,6,4]);212 actual = GURPS.SuccessRoll(6, randomSource);213 expected = {success: false, critical: true};214 assertions.push({Expected: expected, Actual: actual, Description: '10 more than effectiveSkill is critical failure: effectiveSkill 6'});215 randomSource = numberGenerator.dice(6, [4,6,4]);216 actual = GURPS.SuccessRoll(3, randomSource);217 expected = {success: false, critical: true};218 assertions.push({Expected: expected, Actual: actual, Description: '10 more than effectiveSkill is critical failure: effectiveSkill 3'});219 } catch(e){assertions.push({Error: e, Description: '10 more than skill is critical failure'});}220 return TestRunner.displayResults('GURPS GURPS.SuccessRoll', assertions, testState);221};222TestSuite.GURPS._noCritSuccessRoll = async function(testState={})223{224 TestRunner.clearResults(testState);225 var assertions = [], randomSource, actual, expected;226 try{227 randomSource = numberGenerator.dice(6, [1,1,1]);228 actual = GURPS._noCritSuccessRoll(5, randomSource);229 expected = {success: true, margin: 2};230 assertions.push({Expected: expected, Actual: actual, Description: 'Happy path: success'});231 } catch(e){assertions.push({Error: e, Description: 'Happy path'});}232 try{233 randomSource = numberGenerator.dice(6, [6,6,6]);234 actual = GURPS._noCritSuccessRoll(10, randomSource);235 expected = {success: false, margin: -8};236 assertions.push({Expected: expected, Actual: actual, Description: 'Happy path: failure'});237 } catch(e){assertions.push({Error: e, Description: 'Happy path'});}238 try{239 randomSource = numberGenerator.dice(6, [1,4,5]);240 actual = GURPS._noCritSuccessRoll(10, randomSource);241 expected = {success: true, margin: 0};242 assertions.push({Expected: expected, Actual: actual, Description: 'Margin 0 is a success'});243 } catch(e){assertions.push({Error: e, Description: 'Margin 0 is a success'});}244 return TestRunner.displayResults('GURPS GURPS._noCritSuccessRoll', assertions, testState);245};246TestSuite.GURPS.QuickContestedSuccessRoll = async function(testState={})247{248 TestRunner.clearResults(testState);249 var assertions = [], randomSource, actual, actualStringValue, expected;250 try{251 randomSource = numberGenerator.dice(6, [4,1,1, 5,4,1]); //sums 6, 10252 actual = GURPS.QuickContestedSuccessRoll(7, 9, randomSource); //margins 1, -1253 actualStringValue = actual.toString();254 delete actual.toString;255 expected = {winner: 'Character 1', winnerSucceeded: true, loserSucceeded: false, margin: 2};256 assertions.push({Expected: expected, Actual: actual, Description: 'Happy path: return value. character 1 wins'});257 assertions.push({Expected: GURPS.QuickContestedSuccessRoll.Stringifier(expected), Actual: actualStringValue, Description: 'Happy path: string value. character 1 wins'});258 } catch(e){assertions.push({Error: e, Description: 'Happy path'});}259 try{260 GURPS.QuickContestedSuccessRoll('ham');261 TestRunner.failedToThrow(assertions, 'Invalid effectiveSkill1');262 }263 catch(e)264 {265 assertions.push({Expected: getError(Validation.requireInteger, ['ham']),266 Actual: e, Description: 'Invalid effectiveSkill1'});267 }268 try{269 GURPS.QuickContestedSuccessRoll(2, 'pork');270 TestRunner.failedToThrow(assertions, 'Invalid effectiveSkill2');271 }272 catch(e)273 {274 assertions.push({Expected: getError(Validation.requireInteger, ['pork']),275 Actual: e, Description: 'Invalid effectiveSkill2'});276 }277 try{278 randomSource = numberGenerator.dice(6, [5,4,1, 4,1,1]); //sums 10, 6279 actual = GURPS.QuickContestedSuccessRoll(8, 6, randomSource); //margins -2, 0280 delete actual.toString;281 expected = {winner: 'Character 2', winnerSucceeded: true, loserSucceeded: false, margin: 2};282 assertions.push({Expected: expected, Actual: actual, Description: 'Character 2 wins'});283 } catch(e){assertions.push({Error: e, Description: 'Character 2 wins'});}284 try{285 randomSource = numberGenerator.dice(6, [1,1,1, 1,1,1]); //sums 3, 3286 actual = GURPS.QuickContestedSuccessRoll(5, 4, randomSource); //margins 2, 1287 delete actual.toString;288 expected = {winner: 'Character 1', winnerSucceeded: true, loserSucceeded: true, margin: 1};289 assertions.push({Expected: expected, Actual: actual, Description: 'Both succeed. Character 1 wins'});290 } catch(e){assertions.push({Error: e, Description: 'Both succeed. Character 1 wins'});}291 try{292 randomSource = numberGenerator.dice(6, [6,6,6, 6,6,6]); //sums 18, 18293 actual = GURPS.QuickContestedSuccessRoll(10, 12, randomSource); //margins -8, -6294 delete actual.toString;295 expected = {winner: 'Character 2', winnerSucceeded: false, loserSucceeded: false, margin: 2};296 assertions.push({Expected: expected, Actual: actual, Description: 'Both failed. Character 2 wins'});297 } catch(e){assertions.push({Error: e, Description: 'Both failed. Character 2 wins'});}298 try{299 randomSource = numberGenerator.dice(6, [1,1,1, 1,1,1]); //sums 3, 3300 actual = GURPS.QuickContestedSuccessRoll(5, 5, randomSource); //margins 2, 2301 actualStringValue = actual.toString();302 delete actual.toString;303 expected = {winner: 'Tie', winnerSucceeded: true, loserSucceeded: true, margin: 0};304 assertions.push({Expected: expected, Actual: actual, Description: 'Both succeed. Tie. return value'});305 assertions.push({Expected: GURPS.QuickContestedSuccessRoll.Stringifier(expected), Actual: actualStringValue, Description: 'Both succeed. Tie. string value'});306 } catch(e){assertions.push({Error: e, Description: 'Both succeed. Tie'});}307 try{308 randomSource = numberGenerator.dice(6, [5,4,1, 5,4,1]); //sums 10, 10309 actual = GURPS.QuickContestedSuccessRoll(5, 5, randomSource); //margins 5, 5310 delete actual.toString;311 expected = {winner: 'Tie', winnerSucceeded: false, loserSucceeded: false, margin: 0};312 assertions.push({Expected: expected, Actual: actual, Description: 'Both failed. Tie'});313 } catch(e){assertions.push({Error: e, Description: 'Both failed. Tie'});}314 return TestRunner.displayResults('GURPS GURPS.QuickContestedSuccessRoll', assertions, testState);315};316TestSuite.GURPS.QuickContestedSuccessRoll_Stringifier = async function(testState={})317{318 TestRunner.clearResults(testState);319 var assertions = [], input, actual, expected;320 try{321 input = {winner: 'Character 1', winnerSucceeded: true, loserSucceeded: false, margin: 10};322 actual = GURPS.QuickContestedSuccessRoll.Stringifier(input);323 expected = 'Character 1 succeeded by 10.';324 assertions.push({Expected: expected, Actual: actual, Description: 'Character 1 succeeded'});325 } catch(e){assertions.push({Error: e, Description: 'Character 1 succeeded'});}326 try{327 input = {winner: 'Character 2', winnerSucceeded: true, loserSucceeded: false, margin: 2};328 actual = GURPS.QuickContestedSuccessRoll.Stringifier(input);329 expected = 'Character 2 succeeded by 2.';330 assertions.push({Expected: expected, Actual: actual, Description: 'Character 2 succeeded'});331 } catch(e){assertions.push({Error: e, Description: 'Character 2 succeeded'});}332 try{333 input = {winner: 'Character 1', winnerSucceeded: false, loserSucceeded: false, margin: 4};334 actual = GURPS.QuickContestedSuccessRoll.Stringifier(input);335 expected = 'Character 1 was 4 points closer.';336 assertions.push({Expected: expected, Actual: actual, Description: 'Character 1 was closer'});337 } catch(e){assertions.push({Error: e, Description: 'Character 1 was closer'});}338 try{339 input = {winner: 'Character 2', winnerSucceeded: false, loserSucceeded: false, margin: 2};340 actual = GURPS.QuickContestedSuccessRoll.Stringifier(input);341 expected = 'Character 2 was 2 points closer.';342 assertions.push({Expected: expected, Actual: actual, Description: 'Character 2 was closer'});343 } catch(e){assertions.push({Error: e, Description: 'Character 2 was closer'});}344 try{345 input = {winner: 'Tie', winnerSucceeded: true, loserSucceeded: true, margin: 0};346 actual = GURPS.QuickContestedSuccessRoll.Stringifier(input);347 expected = 'Tie: both succeeded by the same amount.';348 assertions.push({Expected: expected, Actual: actual, Description: 'Tie: both succeeded.'});349 } catch(e){assertions.push({Error: e, Description: 'Tie: both succeeded'});}350 try{351 input = {winner: 'Tie', winnerSucceeded: false, loserSucceeded: false, margin: 0};352 actual = GURPS.QuickContestedSuccessRoll.Stringifier(input);353 expected = 'Tie: both failed by the same amount.';354 assertions.push({Expected: expected, Actual: actual, Description: 'Tie: both failed.'});355 } catch(e){assertions.push({Error: e, Description: 'Tie: both failed'});}356 return TestRunner.displayResults('GURPS GURPS.QuickContestedSuccessRoll.Stringifier', assertions, testState);357};358TestSuite.GURPS.RegularContestedSuccessRoll = async function(testState={})359{360 TestRunner.clearResults(testState);361 var assertions = [], randomSource, actual, expected;362 try{363 randomSource = numberGenerator.dice(6, [4,1,1, 5,4,1]); //sums 6, 10364 actual = GURPS.RegularContestedSuccessRoll(7, 9, randomSource); //pass, fail365 expected = {winner: 'Character 1', success: true};366 assertions.push({Expected: expected, Actual: actual, Description: 'Happy path: character 1 wins'});367 } catch(e){assertions.push({Error: e, Description: 'Happy path'});}368 try{369 GURPS.RegularContestedSuccessRoll('ham');370 TestRunner.failedToThrow(assertions, 'Invalid effectiveSkill1');371 }372 catch(e)373 {374 assertions.push({Expected: getError(Validation.requireInteger, ['ham']),375 Actual: e, Description: 'Invalid effectiveSkill1'});376 }377 try{378 GURPS.RegularContestedSuccessRoll(2, 'pork');379 TestRunner.failedToThrow(assertions, 'Invalid effectiveSkill2');380 }381 catch(e)382 {383 assertions.push({Expected: getError(Validation.requireInteger, ['pork']),384 Actual: e, Description: 'Invalid effectiveSkill2'});385 }386 try{387 randomSource = numberGenerator.dice(6, [5,5,4, 5,5,3]); //sums 14, 13388 actual = GURPS.RegularContestedSuccessRoll(18, 16, randomSource); //reduced to 14, 12389 expected = {winner: 'Character 1', success: true};390 assertions.push({Expected: expected, Actual: actual, Description: 'Reduced character 1 wins'});391 } catch(e){assertions.push({Error: e, Description: 'Reduced character 1 wins'});}392 try{393 randomSource = numberGenerator.dice(6, [5,5,6, 5,5,4]); //sums 16, 14394 actual = GURPS.RegularContestedSuccessRoll(15, 20, randomSource); //reduced to 9, 14395 expected = {winner: 'Character 2', success: true};396 assertions.push({Expected: expected, Actual: actual, Description: 'Reduced character 2 wins'});397 } catch(e){assertions.push({Error: e, Description: 'Reduced character 2 wins'});}398 try{399 randomSource = numberGenerator.dice(6, [5,4,1, 4,1,1]); //sums 10, 6400 actual = GURPS.RegularContestedSuccessRoll(8, 6, randomSource); //fail, pass401 expected = {winner: 'Character 2', success: true};402 assertions.push({Expected: expected, Actual: actual, Description: 'Character 2 wins'});403 } catch(e){assertions.push({Error: e, Description: 'Character 2 wins'});}404 try{405 randomSource = numberGenerator.dice(6, [1,1,1, 1,1,1]); //sums 3, 3406 actual = GURPS.RegularContestedSuccessRoll(5, 6, randomSource);407 expected = {winner: 'Tie', success: true};408 assertions.push({Expected: expected, Actual: actual, Description: 'Tie: passed'});409 } catch(e){assertions.push({Error: e, Description: 'Tie: passed'});}410 try{411 randomSource = numberGenerator.dice(6, [5,4,1, 5,4,1]); //sums 10, 10412 actual = GURPS.RegularContestedSuccessRoll(5, 6, randomSource);413 expected = {winner: 'Tie', success: false};414 assertions.push({Expected: expected, Actual: actual, Description: 'Tie: failed'});415 } catch(e){assertions.push({Error: e, Description: 'Tie: failed'});}416 return TestRunner.displayResults('GURPS GURPS.RegularContestedSuccessRoll', assertions, testState);417};418TestSuite.GURPS._parseDamageString = async function(testState={})419{420 TestRunner.clearResults(testState);421 var assertions = [], randomSource, actual;422 try{423 randomSource = numberGenerator.dice(6, [3]);424 actual = GURPS._parseDamageString('1d+2')(randomSource);425 assertions.push({Expected: 5, Actual: actual, Description: 'Happy path'});426 } catch(e){assertions.push({Error: e, Description: 'Happy path'});}427 try{428 GURPS._parseDamageString('2d10');429 TestRunner.failedToThrow(assertions, 'Invalid damageString');430 }431 catch(e)432 {433 assertions.push({Expected: new Error('Expected #d (and optional +# etc). Found: 2d10'),434 Actual: e, Description: 'Invalid damageString'});435 }436 try{437 randomSource = numberGenerator.dice(6, [4,6]);438 actual = GURPS._parseDamageString('2d6-1')(randomSource);439 assertions.push({Expected: 9, Actual: actual, Description: '2d6-1'});440 } catch(e){assertions.push({Error: e, Description: '2d6-1'});}441 try{442 randomSource = numberGenerator.dice(6, [4]);443 actual = GURPS._parseDamageString('1d')(randomSource);444 assertions.push({Expected: 4, Actual: actual, Description: '1d'});445 } catch(e){assertions.push({Error: e, Description: '1d'});}446 try{447 randomSource = numberGenerator.dice(6, [1]);448 actual = GURPS._parseDamageString('1DX3')(randomSource);449 assertions.push({Expected: 3, Actual: actual, Description: 'Ignores case'});450 } catch(e){assertions.push({Error: e, Description: 'Ignores case'});}451 try{452 randomSource = numberGenerator.dice(6, [1]);453 actual = GURPS._parseDamageString('1dx2')(randomSource);454 assertions.push({Expected: 2, Actual: actual, Description: 'Lowercase x'});455 } catch(e){assertions.push({Error: e, Description: 'Lowercase x'});}456 try{457 randomSource = numberGenerator.dice(6, [6,4]);458 actual = GURPS._parseDamageString('2d*4')(randomSource);459 assertions.push({Expected: 40, Actual: actual, Description: 'Allows *'});460 } catch(e){assertions.push({Error: e, Description: 'Allows *'});}461 return TestRunner.displayResults('GURPS GURPS._parseDamageString', assertions, testState);462};463TestSuite.GURPS.RandomHitLocation = async function(testState={})464{465 TestRunner.clearResults(testState);466 var assertions = [], randomSource;467 try{468 randomSource = numberGenerator.dice(6, [6,5,1, 6,6,6]); //sums 12, 18469 assertions.push({Expected: 'Far Leg', Actual: GURPS.RandomHitLocation.roll(randomSource), Description: 'Happy path: exact'});470 assertions.push({Expected: 'Vital Organs', Actual: GURPS.RandomHitLocation.roll(randomSource), Description: 'Happy path: max'});471 } catch(e){assertions.push({Error: e, Description: 'Happy path'});}472 try{473 randomSource = numberGenerator([{dieSides: 6, values: [1,1,5]}, {dieSides: 2, values: [1]}]);474 assertions.push({Expected: 'Left Hand', Actual: GURPS.RandomHitLocation.roll(randomSource), Description: '7 is nested'});475 randomSource = numberGenerator([{dieSides: 6, values: [6,6,3]}, {dieSides: 2, values: [2]}]);476 assertions.push({Expected: 'Right Foot', Actual: GURPS.RandomHitLocation.roll(randomSource), Description: '15 is nested'});477 } catch(e){assertions.push({Error: e, Description: 'nested'});}478 return TestRunner.displayResults('GURPS GURPS.RandomHitLocation', assertions, testState);...

Full Screen

Full Screen

ScriptMapping.test.ts

Source:ScriptMapping.test.ts Github

copy

Full Screen

1import { strictEqual } from "assert";2import { GeneratorOptions, IGeneratorSettings } from "@manuth/extended-yo-generator";3import { Package } from "@manuth/package-json-editor";4import { ScriptMapping } from "../../../NPMPackaging/Scripts/ScriptMapping";5import { TestContext } from "../../TestContext";6import { TestScriptTransformer } from "./TestScriptTransformer";7/**8 * Registers tests for the {@link ScriptMapping `ScriptMapping<TSettings, TOptions>`} class.9 */10export function ScriptMappingTests(): void11{12 suite(13 nameof(ScriptMapping),14 () =>15 {16 let context = TestContext.Default;17 let npmPackage: Package;18 let scriptMapping: ScriptMapping<IGeneratorSettings, GeneratorOptions>;19 let randomSource: string;20 let randomDestination: string;21 let randomScript: string;22 setup(23 async function()24 {25 this.timeout(30 * 1000);26 npmPackage = new Package();27 randomSource = context.RandomString;28 randomDestination = context.RandomString;29 randomScript = context.RandomString;30 npmPackage.Scripts.Add(randomSource, randomScript);31 scriptMapping = new ScriptMapping(32 await context.Generator,33 npmPackage,34 {35 Source: randomSource,36 Destination: randomDestination37 });38 });39 suite(40 nameof(ScriptMapping.constructor),41 () =>42 {43 test(44 "Checking whether passing a string constructs a script-mapping for copying the specified script…",45 async () =>46 {47 scriptMapping = new ScriptMapping(await context.Generator, npmPackage, randomSource);48 strictEqual(scriptMapping.Destination, scriptMapping.Source);49 strictEqual(scriptMapping.Source, randomSource);50 });51 test(52 "Checking whether passing options constructs a proper script-mapping…",53 async () =>54 {55 strictEqual(scriptMapping.Source, randomSource);56 strictEqual(scriptMapping.Destination, randomDestination);57 });58 });59 suite(60 nameof<ScriptMapping<any, any>>((scriptMapping) => scriptMapping.Processor),61 () =>62 {63 test(64 "Checking whether scripts are loaded from the source-package correctly…",65 async () =>66 {67 strictEqual(await scriptMapping.Processor(), randomScript);68 });69 test(70 "Checking whether scripts are not being transformed by default…",71 async () =>72 {73 strictEqual(await scriptMapping.Processor(), randomScript);74 });75 test(76 "Checking whether custom transformers can be passed…",77 async () =>78 {79 let index = context.Random.integer(1, randomScript.length - 1);80 let transformer: TestScriptTransformer = (script: string): string => script.substring(index);81 scriptMapping = new ScriptMapping(82 await context.Generator,83 npmPackage,84 {85 Source: randomSource,86 Destination: randomDestination,87 Processor: async (script) => transformer(script)88 });89 strictEqual(await scriptMapping.Processor(), transformer(randomScript));90 });91 });92 });...

Full Screen

Full Screen

random.spec.js

Source:random.spec.js Github

copy

Full Screen

...22 it('does not call randomSource when called with an upper bound of 1', () => {23 expect(subject.getInt(1)).toBe(0);24 expect(randomSource).not.toHaveBeenCalled();25 });26 it('returns the result of randomSource(1) when upper bound is 2^8', () => {27 let randomValues = [123];28 randomSource.mockImplementation(n => randomValues.splice(0, n));29 expect(subject.getInt(Math.pow(2, 8))).toBe(123);30 });31 it('returns the integer value of randomSource(4) when upper bound is 2^32', () => {32 testCase([123, 45, 67, 89], 123*256*256*256 + 45*256*256 + 67*256 + 89);33 testCase([0, 0, 0, 0], 0);34 testCase([1, 0, 0, 0], Math.pow(2, 24));35 testCase([255, 255, 255, 255], Math.pow(2, 32) - 1);36 function testCase(randomValues, expected) {37 randomSource.mockImplementation(n => randomValues.splice(0, n));38 expect(subject.getInt(Math.pow(2, 32))).toBe(expected);39 }40 });41 it('returns the value of randomSource modulo the upper bound', () => {42 let randomValues = [123];43 randomSource.mockImplementation(n => randomValues.splice(0, n));44 expect(subject.getInt(100)).toBe(23);45 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3 console.log(data);4 test.getTestResults(data.data.testId, function(err, data) {5 console.log(data);6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5 api.getTestResults(data.data.testId, function (err, data) {6 if (err) return console.error(err);7 console.log(data);8 });9});10### runTest(url, options, callback)11### getTestResults(testId, callback)12### getLocations(callback)13### getTesters(callback)14### getTestersAtLocation(location, callback)15### getTestStatus(testId, callback)16### getTestStatusPrivate(testId, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.randomSource(function(err, response) {3 if (err) {4 console.log(err);5 } else {6 console.log(response);7 }8});9var wptools = require('wptools');10wptools.randomSource(function(err, response) {11 if (err) {12 console.log(err);13 } else {14 console.log(response);15 }16});17var wptools = require('wptools');18wptools.randomSource(function(err, response) {19 if (err) {20 console.log(err);21 } else {22 console.log(response);23 }24});25var wptools = require('wptools');26wptools.randomSource(function(err, response) {27 if (err) {28 console.log(err);29 } else {30 console.log(response);31 }32});33var wptools = require('wptools');34wptools.randomSource(function(err, response) {35 if (

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful