diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2026-03-15 10:39:22 +0100 |
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2026-03-15 10:39:22 +0100 |
| commit | 4ce3bd5f717e62fef61acbb17eb0214477d52dab (patch) | |
| tree | 3d06e8445b0bd888d3a97a9a0d7d419908e0a0eb | |
| parent | d326a04fd39524c5a1e3e6ed1efc36221ba5f686 (diff) | |
| download | colonial-twilight-4ce3bd5f717e62fef61acbb17eb0214477d52dab.zip colonial-twilight-4ce3bd5f717e62fef61acbb17eb0214477d52dab.tar.gz | |
Track : add min? && max?
| -rw-r--r-- | lib/colonial_twilight/board/spaces.rb | 8 | ||||
| -rw-r--r-- | spec/spaces_spec.rb | 15 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/colonial_twilight/board/spaces.rb b/lib/colonial_twilight/board/spaces.rb index 786a975..343fcaa 100644 --- a/lib/colonial_twilight/board/spaces.rb +++ b/lib/colonial_twilight/board/spaces.rb @@ -12,6 +12,14 @@ module ColonialTwilight @name = name end + def max? + @v == @max + end + + def min? + @v.zero? + end + def shift(val) @v += val raise "out of track #{@v}" if @v.negative? || @v > @max diff --git a/spec/spaces_spec.rb b/spec/spaces_spec.rb index 1f2726f..a07a098 100644 --- a/spec/spaces_spec.rb +++ b/spec/spaces_spec.rb @@ -5,7 +5,7 @@ require './lib/colonial_twilight/board/spaces' describe ColonialTwilight::Track do before do - @t = ColonialTwilight::Track.new(10) + @t = ColonialTwilight::Track.new(10, 'Fake') end it 'initialize' do @@ -29,6 +29,19 @@ describe ColonialTwilight::Track do expect(@t.shift(3)).to eq 3 expect(@t.data).to eq 3 end + + it 'min? && max?' do + expect(@t.v).to eq 0 + expect(@t.min?).to be(true) + expect(@t.max?).to be(false) + expect(@t.clamp(5)).to eq 5 + expect(@t.min?).to be(false) + expect(@t.max?).to be(false) + expect(@t.clamp(12)).to eq 10 + expect(@t.v).to eq 10 + expect(@t.min?).to be(false) + expect(@t.max?).to be(true) + end end describe ColonialTwilight::Sector do |
