tabletop-companion/test/services/dice_roller_test.rb

39 lines
815 B
Ruby

# frozen_string_literal: true
require "test_helper"
class DiceRollerTest < ActiveSupport::TestCase
test "correctly validates strings" do
valid_strings = [
"2d6",
"12",
"self",
"d12",
"d20+self",
"8+D8-self",
]
invalid_strings = [
"+",
"sel+10",
"d8++13",
]
valid_strings.each do |roll_command|
assert DiceRoller.new(roll_command).valid?
end
invalid_strings.each do |roll_command|
assert_not DiceRoller.new(roll_command).valid?
end
end
test "rolls appropriate results" do
100.times do
assert (1..6).include? DiceRoller.new("d6").roll
assert (2..12).include? DiceRoller.new("2d6").roll
assert (11..30).include? DiceRoller.new("d20+self", stat: stats(:strength)).roll
end
end
end