Roll dice (eg Asphodice) and show outcomes https://rpg.bertieb.org/dice-roller/
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

test-dice.spec.ts 2.9 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. });