This repository has been archived on 2021-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
DiscordRP/test/lib/test_dice.rb

34 lines
800 B
Ruby

# encoding: utf-8
require_relative "../base"
require_relative "../../src/lib/dice"
class DiceTest < Test::Unit::TestCase
def test_base
r = Roll::Dice.parse("15d22")
assert_equal "15d22", r.to_s
assert_nil r.result
r.roll!
assert r.result
assert r.result.size == 15
assert r.result.to_i <= 15 * 22
assert r.result.to_i >= 22
end
def test_parsing
assert_equal "15", Roll::Dice.parse("15").to_s
assert_equal "15", Roll::Dice.parse("15d1").to_s
assert_equal "15d2", Roll::Dice.parse("15d2").to_s
assert_equal "15d21", Roll::Dice.parse(" 15D21").to_s
end
def test_fixed
r = Roll::Dice.parse("15")
assert_equal "15", r.to_s
r.roll!
assert r.result
assert_equal 1, r.result.size
assert_equal 15, r.result.to_i
end
end