forked from jruby/jruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] fixnum/float ops (JRuby specific) tests
for jrubyGH-5938
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'test/unit' | ||
|
||
class TestGH5939 < Test::Unit::TestCase | ||
|
||
class Primitive | ||
|
||
def _value | ||
@__value ||= 0 | ||
end | ||
|
||
def +(other) | ||
_value + other | ||
end | ||
|
||
def ==(other) | ||
other == _value | ||
end | ||
|
||
end | ||
|
||
class Klass; end | ||
|
||
def test_op_indy_regression | ||
threads = [] | ||
30.times do | ||
threads << Thread.start do | ||
begin | ||
i = Klass.new | ||
|
||
def i.version; Primitive.new end | ||
|
||
assert_equal 10, plus_10(i.version) | ||
assert_false i.version == 5 | ||
assert_true 0 == i.version | ||
|
||
true | ||
rescue java.lang.Exception => ex | ||
warn("#{__method__} FAILED WITH: #{ex}") | ||
raise ex | ||
end | ||
end | ||
end | ||
|
||
threads.each &:join | ||
threads.each do |thread| | ||
assert thread.value # should not raise (if thread raised an exception) | ||
end | ||
|
||
end | ||
|
||
def plus_10(version) | ||
version + 10 | ||
end | ||
private :plus_10 | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'test/unit' | ||
|
||
class TestGH5939 < Test::Unit::TestCase | ||
|
||
class Primitive | ||
|
||
def _value | ||
@__value ||= 0.0 | ||
end | ||
|
||
def +(other) | ||
_value + other | ||
end | ||
|
||
def ==(other) | ||
other == _value | ||
end | ||
|
||
def to_f | ||
_value.to_f | ||
end | ||
|
||
end | ||
|
||
def test_op_indy_regression | ||
threads = [] | ||
30.times do | ||
threads << Thread.start do | ||
begin | ||
i = Object.new | ||
|
||
def i.version; @version ||= Primitive.new end | ||
|
||
assert_equal 11.0, i.version + 11.0 | ||
|
||
assert_false i.version == 5.0 | ||
assert_true 0.0 == i.version | ||
|
||
true | ||
rescue java.lang.Exception => ex | ||
warn("#{__method__} FAILED WITH: #{ex}") | ||
raise ex | ||
end | ||
end | ||
end | ||
|
||
threads.each &:join | ||
threads.each do |thread| | ||
assert thread.value # should not raise (if thread raised an exception) | ||
end | ||
|
||
end | ||
|
||
end |