OSDN Git Service

Fix #35795: A time consumed could be -1 201512-timeclock
authorDaigo Moriwaki <daigo@debian.org>
Fri, 27 Nov 2015 14:40:28 +0000 (23:40 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Fri, 27 Nov 2015 14:40:28 +0000 (23:40 +0900)
* [shogi-server] shogi_server/time_clock.rb:
  - A time consumed could be -1.
    * The start time of a move is captured after sending a move to a
      player of the next turn at the end of the giant lock
    * The end time of the move is captured at the exact time when the
      server receives it before the giant lock
    Therefore, end_time < start_time is possible when a player returns a
    move instantly.
    Thanks to Tomoyuki Kaneko for reporting this issue.
    (Closes: #35795)

changelog
shogi_server/time_clock.rb
test/TC_time_clock.rb

index 2364fec..aae3085 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,16 @@
+2015-11-27  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server] shogi_server/time_clock.rb:
+         - A time consumed could be -1.
+           * The start time of a move is captured after sending a move to a
+             player of the next turn at the end of the giant lock
+           * The end time of the move is captured at the exact time when the
+             server receives it before the giant lock
+           Therefore, end_time < start_time is possible when a player returns a
+           move instantly.
+           Thanks to Tomoyuki Kaneko for reporting this issue.
+           (Closes: #35795)
+
 2015-02-14  Daigo Moriwaki <daigo at debian dot org>
 
        * util/statistics.rb:
index 52a747d..06ac229 100644 (file)
@@ -125,11 +125,6 @@ class ChessClockWithLeastZero < ChessClock
     super
   end
 
-  def time_duration(mytime, start_time, end_time)
-    t = end_time - start_time
-    return t.floor
-  end
-
   def to_s
     return "ChessClockWithLeastZero: LeastTimePerMove %d; TotalTime %d; Byoyomi %d" % [@least_time_per_move, @total_time, @byoyomi]
   end
index aa98ae7..215fef4 100644 (file)
@@ -79,6 +79,8 @@ class TestChessClockWithLeastZero < Test::Unit::TestCase
     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
+
+    assert_equal(0, tc.time_duration(100, 100, 99.9))     # -0.1
   end
 
   def test_time_duration_over_thinking_time