~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to test/ruby/test_marshal.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/unit'
 
2
dir = File.dirname(File.expand_path(__FILE__))
 
3
orgpath = $:.dup
 
4
begin
 
5
  $:.push(dir)
 
6
  require 'marshaltestlib'
 
7
ensure
 
8
  $:.replace(orgpath)
 
9
end
 
10
 
 
11
class TestMarshal < Test::Unit::TestCase
 
12
  include MarshalTestLib
 
13
 
 
14
  def encode(o)
 
15
    Marshal.dump(o)
 
16
  end
 
17
 
 
18
  def decode(s)
 
19
    Marshal.load(s)
 
20
  end
 
21
 
 
22
  def fact(n)
 
23
    return 1 if n == 0
 
24
    f = 1
 
25
    while n>0
 
26
      f *= n
 
27
      n -= 1
 
28
    end
 
29
    return f
 
30
  end
 
31
 
 
32
  StrClone=String.clone;
 
33
 
 
34
  def test_marshal
 
35
    $x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)]
 
36
    $y = Marshal.dump($x)
 
37
    assert_equal($x, Marshal.load($y))
 
38
 
 
39
    assert_instance_of(StrClone, Marshal.load(Marshal.dump(StrClone.new("abc"))))
 
40
 
 
41
    [[1,2,3,4], [81, 2, 118, 3146]].each { |w,x,y,z|
 
42
      a = (x.to_f + y.to_f / z.to_f) * Math.exp(w.to_f / (x.to_f + y.to_f / z.to_f))
 
43
      ma = Marshal.dump(a)
 
44
      b = Marshal.load(ma)
 
45
      assert_equal(a, b)
 
46
    }
 
47
  end
 
48
end