OSDN Git Service

Refactor ChessClockWithLeastZero
authorDaigo Moriwaki <daigo@debian.org>
Sat, 17 Jan 2015 00:39:29 +0000 (09:39 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 17 Jan 2015 00:39:29 +0000 (09:39 +0900)
shogi_server/time_clock.rb
test/TC_time_clock.rb

index 1198042..52a747d 100644 (file)
@@ -127,19 +127,7 @@ class ChessClockWithLeastZero < ChessClock
 
   def time_duration(mytime, start_time, end_time)
     t = end_time - start_time
-    if @byoyomi > 0
-      # If the remaining thinking time covers the duration t, floor it.
-      if mytime + @byoyomi - t > 0
-        t = t.floor
-      else
-        t = t.ceil
-      end
-    else
-      # Thinking time only
-      t = t.floor
-    end
-
-    return t
+    return t.floor
   end
 
   def to_s
index 9ae5bef..aa98ae7 100644 (file)
@@ -76,7 +76,7 @@ class TestChessClockWithLeastZero < Test::Unit::TestCase
     assert_equal(0, tc.time_duration(100, 100.1, 100.9))  # 0.8
     assert_equal(1, tc.time_duration(100, 100, 101))      # 1
     assert_equal(1, tc.time_duration(100, 100.1, 101.9))  # 1.8
-    assert_equal(1, tc.time_duration(1,    100,   101))    # 1
+    assert_equal(1, tc.time_duration(1,    100,   101))   # 1
     assert_equal(2, tc.time_duration(100, 100.1, 102.9))  # 2.8
     assert_equal(2, tc.time_duration(100, 100, 102))      # 2
   end