blob: d4e17a46b1cbd4e47afb4a01c0f26b533b7e470a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#! /usr/bin/ruby
def ri(s)
r=s.to_s.reverse
if r =~ /([0-9]+)-$/
r='-' + $1
end
r=Integer(r)
b=[r].pack('l').unpack('l')[0]
if b != r
return 0
end
return r
end
require 'test/unit'
class TestRi < Test::Unit::TestCase
def test_ex1
assert_equal(4321,ri(1234),'example 1')
end
def test_ex2
assert_equal(-4321,ri(-1234),'example 2')
end
def test_ex3
assert_equal(0,ri(1231230512),'example 3')
end
end
|