tabletop-companion/test/services/dice_roller_test.rb

39 lines
821 B
Ruby
Raw Normal View History

2024-06-11 13:55:39 +00:00
# frozen_string_literal: true
require "test_helper"
class DiceRollerTest < ActiveSupport::TestCase
test "correctly validates strings" do
valid_strings = [
"2d6",
"12",
"self",
2024-07-08 14:08:17 +00:00
"1d12",
"1d20+self",
"8+1D8-self",
2024-06-11 13:55:39 +00:00
]
invalid_strings = [
"+",
"sel+10",
2024-07-08 14:08:17 +00:00
"1d8++13",
2024-06-11 13:55:39 +00:00
]
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
2024-07-08 14:08:17 +00:00
assert (1..6).include? DiceRoller.new("1d6").roll
2024-06-11 13:55:39 +00:00
assert (2..12).include? DiceRoller.new("2d6").roll
2024-07-08 14:08:17 +00:00
assert (11..30).include? DiceRoller.new("1d20+self", stat: stats(:strength)).roll
2024-06-11 13:55:39 +00:00
end
end
end