PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/ruby/primitive_types_runme.rb

#
Ruby | 98 lines | 66 code | 22 blank | 10 comment | 30 complexity | d891ba8ebbcff0396250f06f72b1f19c MD5 | raw file
 1#!/usr/bin/env ruby
 2#
 3# Put description here
 4#
 5# 
 6# 
 7# 
 8#
 9
10require 'swig_assert'
11
12require 'primitive_types'
13
14include Primitive_types
15
16
17raise RuntimeError if val_uchar(255) != 255
18
19fail = 0
20begin
21  val_uchar(-1)
22rescue RangeError
23  fail = 1
24end
25
26fail = 0
27begin
28  val_uchar(256)
29rescue RangeError
30  fail = 1
31end
32
33raise RuntimeError if fail != 1
34
35fail = 0
36begin
37  val_uchar(256.0)
38rescue TypeError
39  fail = 1
40end
41
42raise RuntimeError if fail != 1
43
44fail = 0
45begin
46  val_uchar("caca")
47rescue TypeError
48  fail = 1
49end
50
51raise RuntimeError if fail != 1
52
53# Test a number which won't fit in a 32 bit integer and is represented
54# as a FIXNUM by Ruby.
55raise RuntimeError if val_double(51767811298) != 51767811298
56
57raise RuntimeError if val_double_2(1.0) != 4.0
58raise RuntimeError if val_double_2(1) != 4
59raise RuntimeError if val_double_2(1,1) != 2
60
61fail = 0
62begin
63  val_double_2("1.0",1.0)
64rescue 
65  fail = 1
66end
67raise RuntimeError if fail != 1
68
69
70fail = 0
71begin
72  val_double_2(1.0,"1.0")
73rescue 
74  fail = 1
75end
76raise RuntimeError if fail != 1
77
78
79raise RuntimeError if val_float_2(1.0) != 4.0
80raise RuntimeError if val_float_2(1) != 4
81raise RuntimeError if val_float_2(1,1) != 2
82
83fail = 0
84begin
85  val_float_2("1.0",1.0)
86rescue 
87  fail = 1
88end
89raise RuntimeError if fail != 1
90
91
92fail = 0
93begin
94  val_float_2(1.0,"1.0")
95rescue 
96  fail = 1
97end
98raise RuntimeError if fail != 1
99