Roll dice (eg Asphodice) and show outcomes https://rpg.bertieb.org/dice-roller/
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

98 řádky
2.9 KiB

  1. import { Asphodice } from "../dice";
  2. import { expect } from 'chai';
  3. import 'mocha';
  4. let asphodice = new Asphodice;
  5. const testCandidates = [
  6. { dice: [ 6, 6, 6 ], aboveCutOff: true, belowCutOff: false,
  7. reroll: false, cancelled: [6,6,6] },
  8. { dice: [ 2, 2, 2 ], aboveCutOff: false, belowCutOff: true,
  9. reroll: false, cacncelled: [2,2,2] },
  10. { dice: [ 1 ], aboveCutOff: false, belowCutOff: true,
  11. reroll: true, cacncelled: [1] },
  12. ];
  13. describe("allAboveCutOff() says are all above cutoff correctly", function() {
  14. const tests = [
  15. { dice: [ 6, 6, 6 ], expected: true },
  16. { dice: [ 2, 2, 2 ], expected: false },
  17. { dice: [ 1 ], expected: false },
  18. { dice: [ 10 ], expected: true },
  19. { dice: [ 6, 10, 6, 9 ], expected: true}
  20. ];
  21. tests.forEach(({dice, expected}) => {
  22. it(`correctly determines ${dice} are above cutoff`, function () {
  23. const result = asphodice.allAboveCutOff(dice);
  24. expect(result).to.equal(expected);
  25. });
  26. });
  27. testCandidates.forEach( ({dice, aboveCutOff}) => {
  28. it(`allAboveCutOff() says ${dice} → ${aboveCutOff}`, function() {
  29. const result = asphodice.allAboveCutOff(dice);
  30. expect(result).to.equal(aboveCutOff);
  31. });
  32. });
  33. });
  34. describe("Are all below cutoff?", function() {
  35. const tests = [
  36. { dice: [ 6, 6, 6 ], expected: false },
  37. { dice: [ 2, 2, 2 ], expected: true },
  38. { dice: [ 1 ], expected: true },
  39. { dice: [ 10 ], expected: false },
  40. { dice: [ 6, 10, 6, 9 ], expected: false },
  41. { dice: [ 6, 1, 6, 9 ], expected: false }
  42. ];
  43. tests.forEach(({dice, expected}) => {
  44. it(`correctly determines ${dice} are above cutoff`, function () {
  45. const result = asphodice.allBelowCutOff(dice);
  46. expect(result).to.equal(expected);
  47. });
  48. });
  49. });
  50. // TODO: single dice behaviour
  51. describe("Does it need a re-roll?", function() {
  52. const tests = [
  53. { dice: [ 6, 6, 6 ], expected: false },
  54. { dice: [ 2, 2, 2 ], expected: false },
  55. { dice: [ 6, 10, 6, 9 ], expected: false },
  56. { dice: [ 6, 1, 6, 9 ], expected: true },
  57. { dice: [ 10, 1, 2], expected: false },
  58. { dice: [ 10, 10, 1, 1, 1, 6], expected: true },
  59. { dice: [ 10, 10, 1, 1, 1, 2], expected: false },
  60. ];
  61. tests.forEach(({dice, expected}) => {
  62. it(`correctly determines ${dice} needs a re-roll`, function () {
  63. const result = asphodice.rerollNeeded(dice);
  64. expect(result).to.equal(expected);
  65. });
  66. });
  67. });
  68. describe("cancelRerollDice() filters correctly", function() {
  69. const tests = [
  70. { dice: [ 6, 6, 6 ], out: [6,6,6] },
  71. { dice: [ 2, 2, 2 ], out: [2,2,2] },
  72. { dice: [ 6, 10, 6, 9 ], out: [6, 10, 6, 9] },
  73. { dice: [ 6, 1, 6, 9 ], out: [ 6, 1, 6, 9 ] },
  74. { dice: [ 10, 1, 2], out: [2] },
  75. { dice: [ 10, 10, 1, 1, 1, 6], out: [1,6] },
  76. { dice: [ 10, 10, 1, 1, 1, 2], out: [1,2] },
  77. ];
  78. tests.forEach(({dice, out}) => {
  79. it(`correctly filters ${dice} to ${out}`, function () {
  80. const result = asphodice.cancelRerollDice(dice);
  81. expect(result.sort()).to.deep.equal(out.sort());
  82. });
  83. });
  84. });