summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/colonial_twilight/fln_bot_rules.rb9
-rw-r--r--spec/fln_bot_rules_spec.rb16
2 files changed, 18 insertions, 7 deletions
diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb
index 43d5abf..eb06af6 100644
--- a/lib/colonial_twilight/fln_bot_rules.rb
+++ b/lib/colonial_twilight/fln_bot_rules.rb
@@ -6,11 +6,10 @@ module ColonialTwilight
def dbg(msg, ret)
return if @debug.zero?
- s = case @debug
- when 1 then " #{msg} : YES" if ret
- else " #{msg} : #{ret ? 'YES' : 'NO'}"
- end
- puts s unless @debug == 666
+ case @debug
+ when 1 then puts " #{msg} : YES" if ret
+ else puts " #{msg} : #{ret ? 'YES' : 'NO'}"
+ end
end
def pass?(board = @board)
diff --git a/spec/fln_bot_rules_spec.rb b/spec/fln_bot_rules_spec.rb
index 1881f39..c21d339 100644
--- a/spec/fln_bot_rules_spec.rb
+++ b/spec/fln_bot_rules_spec.rb
@@ -6,10 +6,10 @@ require './spec/mock_board'
class FLNRulesImpl
include ColonialTwilight::FLNBotRules
attr_reader :board
- attr_writer :limited_op_only, :first_eligible, :will_be_next_first_eligible
+ attr_writer :debug, :limited_op_only, :first_eligible, :will_be_next_first_eligible
def initialize
- @debug = 666
+ @debug = 0
@board = Board.new
@limited_op_only = true
@first_eligible = true
@@ -44,6 +44,18 @@ describe ColonialTwilight::FLNBotRules do
@board = @rules.board
end
+ describe 'Debug' do
+ it 'level 1' do
+ @rules.debug = 1
+ expect { @rules.dbg('msg', true) }.to output(" msg : YES\n").to_stdout
+ end
+
+ it 'level 2' do
+ @rules.debug = 2
+ expect { @rules.dbg('msg', false) }.to output(" msg : NO\n").to_stdout
+ end
+ end
+
describe 'Pass' do
it 'pass? no resources' do
expect(@rules.pass?).to be true