Skip to content

Commit b458f94

Browse files
authored
Add JRuby minimum ci (#418)
1 parent 6177f46 commit b458f94

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

.github/workflows/jruby_test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: JRuby-test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
13+
jobs:
14+
host:
15+
name: ${{ matrix.ruby }}
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
ruby:
21+
- jruby
22+
- jruby-head
23+
24+
steps:
25+
- uses: actions/checkout@v5
26+
27+
- name: Set up Ruby
28+
uses: ruby/setup-ruby@v1
29+
with:
30+
ruby-version: ${{ matrix.ruby }}
31+
32+
- run: bundle install
33+
34+
- run: rake compile
35+
36+
- run: rake test TEST=test/bigdecimal/test_jruby.rb
37+
38+
- run: rake build
39+
40+
- run: gem install pkg/*.gem

test/bigdecimal/test_jruby.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: false
2+
require_relative 'helper'
3+
require 'bigdecimal/math'
4+
5+
class TestJRuby < Test::Unit::TestCase
6+
# JRuby uses its own native BigDecimal implementation
7+
# but uses the same BigMath module as CRuby.
8+
# These are test to ensure BigMath works correctly with JRuby's BigDecimal.
9+
# Also run on CRuby to ensure compatibility.
10+
11+
N = 20
12+
13+
def test_sqrt
14+
sqrt2 = BigDecimal(2).sqrt(N)
15+
assert_in_delta(Math.sqrt(2), sqrt2)
16+
assert_in_delta(2, sqrt2 * sqrt2)
17+
end
18+
19+
def test_exp
20+
assert_in_delta(Math.exp(2), BigMath.exp(BigDecimal(2), N))
21+
assert_in_delta(Math.exp(2), BigMath.exp(2, N))
22+
assert_in_delta(Math.exp(2.5), BigMath.exp(2.5, N))
23+
assert_in_delta(Math.exp(2.5), BigMath.exp(2.5r, N))
24+
end
25+
26+
def test_log
27+
assert_in_delta(Math.log(2), BigMath.log(BigDecimal(2), N))
28+
assert_in_delta(Math.log(2), BigMath.log(2, N))
29+
assert_in_delta(Math.log(2.5), BigMath.log(2.5, N))
30+
assert_in_delta(Math.log(2.5), BigMath.log(2.5r, N))
31+
end
32+
33+
def test_power
34+
x = BigDecimal(2)
35+
expected = 2 ** 2.5
36+
assert_in_delta(expected, x ** BigDecimal('2.5'))
37+
assert_in_delta(expected, x.sqrt(N) ** 5)
38+
# assert_in_delta(expected, x ** 2.5)
39+
assert_in_delta(expected, x ** 2.5r)
40+
assert_in_delta(expected, x.power(BigDecimal('2.5'), N))
41+
# assert_in_delta(expected, x.power(2.5, N))
42+
assert_in_delta(expected, x.sqrt(N).power(5, N))
43+
assert_in_delta(expected, x.power(2.5r, N))
44+
end
45+
46+
def test_bigmath
47+
assert_in_delta(Math.sqrt(2), BigMath.sqrt(BigDecimal(2), N))
48+
assert_in_delta(Math.sin(1), BigMath.sin(BigDecimal(1), N))
49+
assert_in_delta(Math.cos(1), BigMath.cos(BigDecimal(1), N))
50+
assert_in_delta(Math.atan(1), BigMath.atan(BigDecimal(1), N))
51+
assert_in_delta(Math::PI, BigMath.PI(N))
52+
assert_in_delta(Math::E, BigMath.E(N))
53+
end
54+
end

0 commit comments

Comments
 (0)