Class: TestPython

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
ext/rpy/test.rb

Instance Method Summary collapse

Instance Method Details

#test_benchmarkObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'ext/rpy/test.rb', line 29

def test_benchmark
  Py.start

  py_result = ""
  iterations = 100
  real_times = []

  iterations.times do
    timer = Time.now
    py_result = Py.run( %Q(_rpython_result = {'hello':1,'world':2}), :serialize => 'yaml')
    real_times << Time.now - timer
  end
  total = 0
  average = 0.0
  n = 0
  variance = 0.0
  real_times.each do|time|
    n = n + 1
    delta = time - average
    average = average + (delta/n)
    variance = variance + delta * (time - average)
    total += time 
  end

  variance /= n 

  puts "total: #{total} seconds, average: #{average} seconds, variance: #{variance} seconds"

  result = YAML.load( py_result )
  assert_equal 1, result['hello']
  assert_equal 2, result['world']


  Py.stop
end

#test_python_no_returnObject


7
8
9
10
11
12
13
14
15
# File 'ext/rpy/test.rb', line 7

def test_python_no_return
  Py.start # starts the python interperter

  output = "hello world"

  Py.run( %Q(print "#{output}"), {} )

  Py.stop # stops the interperter
end

#test_python_yaml_returnObject


17
18
19
20
21
22
23
24
25
26
# File 'ext/rpy/test.rb', line 17

def test_python_yaml_return
  Py.start

  result = YAML.load( Py.run( %Q(_rpython_result = {'hello':1,'world':2}), :serialize => 'yaml') )

  assert_equal 1, result['hello']
  assert_equal 2, result['world']

  Py.stop
end