From 14cc1f5de9ad44887a913b3638a9403c661f11a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 26 Oct 2023 21:15:40 +0200 Subject: FLNBotRules : fix and spec dbg(msg, ret) --- lib/colonial_twilight/fln_bot_rules.rb | 9 ++++----- spec/fln_bot_rules_spec.rb | 16 ++++++++++++++-- 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 -- cgit v1.1-2-g2b99