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