OSDN Git Service

[shogi-server] Addressed Ruby incompatibility on ShogiServer::Usi::alphabetToDan.
authorDaigo Moriwaki <daigo@debian.org>
Tue, 23 Dec 2014 08:35:04 +0000 (17:35 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Tue, 23 Dec 2014 08:35:04 +0000 (17:35 +0900)
  It (and usiToCsa.rb) did not work with Ruby 1.9.3. This issue has now been fixed.
  Thanks to Hiraoka-san for debugging.

changelog
shogi_server/usi.rb
test/TC_usi.rb

index 5fa7fb7..2058b80 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,11 @@
+2014-12-23  Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - Addressed Ruby incompatibility on ShogiServer::Usi::alphabetToDan.
+           It (and usiToCsa.rb) did not work with Ruby 1.9.3. This issue
+           has now been fixed.
+           Thanks to Hiraoka-san for debugging.
+
 2014-11-24  Daigo Moriwaki <daigo at debian dot org>
 
        * Ruby 2.0:
index 39ca24e..788bd4f 100644 (file)
@@ -28,7 +28,10 @@ module ShogiServer # for a namespace
       # i -> 9
       def alphabetToDan(s)
         if RUBY_VERSION >= "1.9.1"
-          return s.bytes[0]-96
+          # String.bytes is incompatible:
+          #  - Ruby 1.9.3 String.bytes returns Enumerator
+          #  - Ruby 2.1.0 String.bytes returns [Integer]
+          return s.each_byte.next-96
         else
           return s[0]-96
         end
index 8dbe045..a102f92 100644 (file)
@@ -102,4 +102,10 @@ EOB
 
     assert_equal(usi_moves, cu.usi_moves)
   end
+
+  def test_alphabetToDan
+    assert_equal(1, ShogiServer::Usi::alphabetToDan("axxx"))
+    assert_equal(2, ShogiServer::Usi::alphabetToDan("bxxx"))
+    assert_equal(9, ShogiServer::Usi::alphabetToDan("ixxx"))
+  end
 end