-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjava_test.rb
More file actions
115 lines (97 loc) · 2.87 KB
/
java_test.rb
File metadata and controls
115 lines (97 loc) · 2.87 KB
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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'test_helper'
class JavaTest < Minitest::Test
def test_new
time = new Time()
assert_instance_of Time, time
time = new Time(2014, 3, 1)
assert_equal Time.new(2014, 3, 1), time
end
def test_void
assert_correct_type :void, nil
assert_wrong_type :void, "not void"
end
def test_byte
assert_correct_type :byte, 127
assert_correct_type :byte, -128
assert_wrong_type :byte, 128
assert_wrong_type :byte, -129
assert_wrong_type :byte, "not byte"
assert_wrong_type :byte, nil
end
def test_short
assert_correct_type :short, 32767
assert_correct_type :short, -32768
assert_wrong_type :short, 32768
assert_wrong_type :short, -32769
assert_wrong_type :short, "not short"
assert_wrong_type :short, nil
end
def test_int
assert_correct_type :int, 2147483647
assert_correct_type :int, -2147483648
assert_wrong_type :int, 2147483648
assert_wrong_type :int, -2147483649
assert_wrong_type :int, "not int"
assert_wrong_type :int, nil
end
def test_long
assert_correct_type :long, 9223372036854775807
assert_correct_type :long, -9223372036854775808
assert_wrong_type :long, 9223372036854775808
assert_wrong_type :long, -9223372036854775809
assert_wrong_type :long, "not long"
assert_wrong_type :long, nil
end
def test_float
assert_correct_type :float, 1.0
assert_correct_type :float, Math::PI
assert_wrong_type :float, 1
assert_wrong_type :float, "not float"
assert_wrong_type :float, nil
end
def test_double
assert_correct_type :double, 1.0
assert_correct_type :double, Math::PI
assert_wrong_type :double, 1
assert_wrong_type :double, "not double"
assert_wrong_type :double, nil
end
def test_bool
assert_correct_type :bool, true
assert_correct_type :bool, false
assert_wrong_type :bool, "not bool"
assert_wrong_type :bool, nil
end
def test_char
assert_correct_type :char, 'a'
assert_correct_type :char, '☃'
assert_correct_type :char, '☃'
assert_wrong_type :char, 1
assert_wrong_type :char, "not char"
assert_wrong_type :char, nil
end
def test_user_type
Object.const_set 'UserType', Class.new
user_type = new UserType()
Type.define_new(:UserType, UserType)
assert_correct_type :UserType, user_type
assert_wrong_type :UserType, 1
assert_wrong_type :UserType, "not UserType"
assert_wrong_type :UserType, nil
end
private
def define_test_method(type, val)
klass = Class.new.class_eval <<-RUBY_CODE
public #{type} def call
ObjectSpace._id2ref(#{val.__id__})
end
RUBY_CODE
klass.new
end
def assert_correct_type(type, val)
assert_equal val, define_test_method(type, val).call
end
def assert_wrong_type(type, val)
assert_raises(TypeError) { define_test_method(type, val).call }
end
end