Browse Source

fix: update to crystal 1.0.0

master
Arthur POULET 8 months ago
parent
commit
d85b7f5b6e
Signed by: Sceptique GPG Key ID: C108A668349EE601
  1. 16
      Makefile
  2. 2
      README.md
  3. 4
      shard.yml
  4. 8
      spec/rollable/dice.cr
  5. 2
      spec/rollable/die.cr
  6. 2
      spec/rollable/roll.cr
  7. 10
      src/rollable/dice.cr
  8. 10
      src/rollable/die.cr
  9. 2
      src/rollable/is_rollable.cr
  10. 8
      src/rollable/roll.cr

16
Makefile

@ -1,24 +1,16 @@
NAME=`ls -d src/*/ | cut -f2 -d'/'`
all: deps_opt build
all: deps_opt test
run:
crystal run src/$(NAME).cr
build:
crystal build src/$(NAME).cr --stats
release:
crystal build src/$(NAME).cr --stats --release
test:
crystal spec
deps:
crystal deps install
shards install
deps_update:
crystal deps update
shards update
deps_opt:
@[ -d lib/ ] || make deps
doc:
crystal docs
clean:
rm $(NAME)
.PHONY: all run build release test deps deps_update clean doc
.PHONY: all run build release test deps deps_update doc

2
README.md

@ -2,7 +2,7 @@
Roll and parse dices
Works with crystal v0.23.0
Works with crystal v1.0.0
## Installation [![travis](https://travis-ci.org/Nephos/crystal_rollable.svg)](https://travis-ci.org/Nephos/crystal_rollable)

4
shard.yml

@ -1,7 +1,7 @@
name: rollable
version: 0.1.4
version: 1.0.0
authors:
- Arthur Poulet <arthur.poulet@mailoo.org>
- Arthur Poulet <arthur.poulet@sceptique.eu>
license: MIT

8
spec/rollable/dice.cr

@ -5,7 +5,7 @@ describe Rollable::Dice do
d.min.should eq 2
d.max.should eq 40
d.average.should eq 21
expect_raises { Rollable::Dice.new 1001, 20 }
expect_raises(Exception) { Rollable::Dice.new 1001, 20 }
end
it "details" do
@ -47,9 +47,9 @@ describe Rollable::Dice do
end
it "parse (error)" do
expect_raises { Rollable::Dice.parse("yolo") }
expect_raises { Rollable::Dice.parse("1d6+1", true) }
expect_raises { Rollable::Dice.parse("--1d4") }
expect_raises(Exception) { Rollable::Dice.parse("yolo") }
expect_raises(Exception) { Rollable::Dice.parse("1d6+1", true) }
expect_raises(Exception) { Rollable::Dice.parse("--1d4") }
end
it "consume" do

2
spec/rollable/die.cr

@ -4,7 +4,7 @@ describe Rollable::Die do
Rollable::Die.new(10..20).should be_a(Rollable::Die)
Rollable::Die.new(20).should be_a(Rollable::Die)
Rollable::Die.new(20, true).should be_a(Rollable::Die)
expect_raises { Rollable::Die.new(1001) }
expect_raises(Exception) { Rollable::Die.new(1001) }
end
it "min, max, average" do

2
spec/rollable/roll.cr

@ -58,7 +58,7 @@ describe Rollable::Roll do
end
it "parse (error)" do
expect_raises { Rollable::Roll.parse("yolo") }
expect_raises(Exception) { Rollable::Roll.parse("yolo") }
Rollable::Roll.parse("yolo") { |_| true } rescue fail("must be catch in block")
end

10
src/rollable/dice.cr

@ -115,8 +115,14 @@ class Rollable::Dice < Rollable::IsRollable
end
{% end %}
def <=>(right : Dice)
average != right.average ? average - right.average <=> 0 : max != right.max ? max - right.max <=> 0 : min - right.min <=> 0
def <=>(right : Dice) : Int32
if average != right.average
average - right.average > 0 ? 1 : -1
elsif max != right.max
max - right.max <=> 0
else
min - right.min <=> 0
end
end
end

10
src/rollable/die.cr

@ -149,8 +149,14 @@ class Rollable::Die < Rollable::IsRollable
end
{% end %}
def <=>(right : Die)
average != right.average ? average - right.average <=> 0 : max != right.max ? max - right.max <=> 0 : min - right.min <=> 0
def <=>(right : Die) : Int32
if average != right.average
average - right.average > 0 ? 1 : -1
elsif max != right.max
max - right.max <=> 0
else
min - right.min <=> 0
end
end
end
#

2
src/rollable/is_rollable.cr

@ -1,6 +1,6 @@
abstract class Rollable::IsRollable
abstract def min : Int32
abstract def max : Int32
abstract def average : Int32
abstract def average : Float64
abstract def test : Int32
end

8
src/rollable/roll.cr

@ -80,7 +80,13 @@ class Rollable::Roll < Rollable::IsRollable
{% end %}
def <=>(right : Roll) : Int32
average != right.average ? average - right.average <=> 0 : max != right.max ? max - right.max <=> 0 : min - right.min <=> 0
if average != right.average
average - right.average > 0 ? 1 : -1
elsif max != right.max
max - right.max <=> 0
else
min - right.min <=> 0
end
end
def order!

Loading…
Cancel
Save