Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigMath.exp and log missing #1186

Closed
headius opened this issue Oct 29, 2013 · 19 comments
Closed

BigMath.exp and log missing #1186

headius opened this issue Oct 29, 2013 · 19 comments
Assignees
Labels
Milestone

Comments

@headius
Copy link
Member

headius commented Oct 29, 2013

Need to implement these.

@ghost ghost assigned BanzaiMan Oct 29, 2013
@petervandenabeele
Copy link
Contributor

Taking a stab at it ... (far from sure this will work out though).

@petervandenabeele
Copy link
Contributor

Kind of stuck on this ...

➜  jruby git:(gh-1186_BigMath_log_exp) mvn -e -Ptest
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] JRuby
[INFO] JRuby Core
[INFO] JRuby Ext
[INFO] JRuby OpenSSL
[INFO] JRuby Readline
[INFO] JRuby Ripper
[INFO] JRuby Integration Tests
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building JRuby 9000.dev
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ jruby-parent ---
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building JRuby Core 9000.dev
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ jruby-core ---
[INFO] 
[INFO] --- properties-maven-plugin:1.0-alpha-2:read-project-properties (properties) @ jruby-core ---
[WARNING] Ignoring missing properties file: /Users/peter_v/Documents/data/projects/jruby/jruby/core/../build.properties
[INFO] 
[INFO] --- buildnumber-maven-plugin:1.2:create (jruby-revision) @ jruby-core ---
[INFO] Checking for local modifications: skipped.
[INFO] Updating project files from SCM: skipped.
[INFO] ShortRevision tag detected. The value is '7'.
[INFO] Executing: /bin/sh -c cd /Users/peter_v/Documents/data/projects/jruby/jruby/core && git rev-parse --verify --short=7 HEAD
[INFO] Working directory: /Users/peter_v/Documents/data/projects/jruby/jruby/core
[INFO] Storing buildNumber: b6a8fd0 at timestamp: 1383079513172
[INFO] ShortRevision tag detected. The value is '7'.
[INFO] Executing: /bin/sh -c cd /Users/peter_v/Documents/data/projects/jruby/jruby/core && git rev-parse --verify --short=7 HEAD
[INFO] Working directory: /Users/peter_v/Documents/data/projects/jruby/jruby/core
[INFO] Storing buildScmBranch: UNKNOWN
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jruby-core ---
[INFO] Using 'utf-8' encoding to copy filtered resources.
[INFO] Copying 41 resources
[INFO] Copying 1 resource
[INFO] Copying 1 resource to /Users/peter_v/Documents/data/projects/jruby/jruby/core/src/main/java
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (anno) @ jruby-core ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jruby-core ---
[INFO] Compiling 1 source file to /Users/peter_v/Documents/data/projects/jruby/jruby/core/target/classes
[INFO] 
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-populators) @ jruby-core ---
[INFO] Source directory: /Users/peter_v/Documents/data/projects/jruby/jruby/core/target/generated-sources added.
[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:exec (invoker-generator) @ jruby-core ---
/Users/peter_v/Documents/data/projects/jruby/jruby/core/target/generated-sources/annotated_classes.txt - not found. skip generator.
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (populators) @ jruby-core ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (eclipse-hack) @ jruby-core ---
[INFO] Not compiling main sources
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ jruby-core ---
[INFO] Using 'utf-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/peter_v/Documents/data/projects/jruby/jruby/core/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ jruby-core ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ jruby-core ---
[INFO] Surefire report directory: /Users/peter_v/Documents/data/projects/jruby/jruby/core/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.jruby.embed.internal.ConcurrentLocalContextProviderTest
Running org.jruby.embed.internal.BiVariableMapTest
Running org.jruby.embed.jsr223.JRubyEngineFactoryTest
Running org.jruby.embed.internal.SingleThreadLocalContextProviderTest
Running org.jruby.embed.jsr223.JRubyCompiledScriptTest
Running org.jruby.embed.bsf.JRubyEngineTest
Running org.jruby.embed.ConstantCompilationTest
Running org.jruby.embed.internal.ThreadSafeLocalContextProviderTest
Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.391 sec - in org.jruby.embed.jsr223.JRubyEngineFactoryTest
Running org.jruby.embed.jsr223.JRubyEngineTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.962 sec - in org.jruby.embed.internal.SingleThreadLocalContextProviderTest
Running org.jruby.embed.ReaderInputStreamTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.382 sec - in org.jruby.embed.internal.ConcurrentLocalContextProviderTest
Running org.jruby.embed.ScriptingContainerTest
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 9.726 sec - in org.jruby.embed.internal.ThreadSafeLocalContextProviderTest
Running org.jruby.embed.util.SystemPropertyCatcherTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.285 sec - in org.jruby.embed.util.SystemPropertyCatcherTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.51 sec - in org.jruby.embed.ConstantCompilationTest
Running org.jruby.test.MainTestSuite
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.826 sec - in org.jruby.embed.jsr223.JRubyCompiledScriptTest
Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 17.716 sec - in org.jruby.embed.bsf.JRubyEngineTest
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 19.573 sec - in org.jruby.embed.internal.BiVariableMapTest
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 13.881 sec - in org.jruby.embed.ReaderInputStreamTest
Tests run: 25, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 20.787 sec - in org.jruby.embed.jsr223.JRubyEngineTest
Tests run: 91, Failures: 4, Errors: 0, Skipped: 0, Time elapsed: 84.645 sec <<< FAILURE! - in org.jruby.embed.ScriptingContainerTest
testRunScriptlet_String(org.jruby.embed.ScriptingContainerTest)  Time elapsed: 0.255 sec  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[?????! ??]JRuby> but was:<[?????! ??]JRuby>
    at org.junit.Assert.assertEquals(Assert.java:115)
    at org.junit.Assert.assertEquals(Assert.java:144)
    at org.jruby.embed.ScriptingContainerTest.testRunScriptlet_String(ScriptingContainerTest.java:713)

testRunScriptlet_PathType_String(org.jruby.embed.ScriptingContainerTest)  Time elapsed: 0.776 sec  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[??? >> ?????? >> ?? >> ???? >> ????????? >> ??????]: 6 in total> but was:<[??? >> ?????? >> ?? >> ???? >> ????????? >> ??????]: 6 in total>
    at org.junit.Assert.assertEquals(Assert.java:115)
    at org.junit.Assert.assertEquals(Assert.java:144)
    at org.jruby.embed.ScriptingContainerTest.testRunScriptlet_PathType_String(ScriptingContainerTest.java:845)

testParse_3args_2(org.jruby.embed.ScriptingContainerTest)  Time elapsed: 0.166 sec  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[?? >> ?? >> ?? >> ?? >> ?? >> ?? >> ??? >> ???]: 8 in total> but was:<[?? >> ?? >> ?? >> ?? >> ?? >> ?? >> ??? >> ???]: 8 in total>
    at org.junit.Assert.assertEquals(Assert.java:115)
    at org.junit.Assert.assertEquals(Assert.java:144)
    at org.jruby.embed.ScriptingContainerTest.testParse_3args_2(ScriptingContainerTest.java:616)

testCallMethod_4args_1(org.jruby.embed.ScriptingContainerTest)  Time elapsed: 0.19 sec  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[Hello >> ???????????? >> ????? >> ??]: 4 in total> but was:<[?? >> ????? >> ???????????? >> Hello]: 4 in total>
    at org.junit.Assert.assertEquals(Assert.java:115)
    at org.junit.Assert.assertEquals(Assert.java:144)
    at org.jruby.embed.ScriptingContainerTest.testCallMethod_4args_1(ScriptingContainerTest.java:973)

Tests run: 36, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 97.762 sec <<< FAILURE! - in org.jruby.test.MainTestSuite
testPrintErrorShouldOnlyPrintErrorMessageWhenBacktraceIsNil(org.jruby.test.TestRuby)  Time elapsed: 32.117 sec  <<< ERROR!
java.lang.OutOfMemoryError: Java heap space
    at java.util.HashMap.resize(HashMap.java:462)
    at java.util.HashMap.addEntry(HashMap.java:755)
    at java.util.HashMap.put(HashMap.java:385)
    at org.jruby.Ruby.addBoundMethod(Ruby.java:2798)
    at org.jruby.gen.org$jruby$RubyThread$POPULATOR.populate(org$jruby$RubyThread$POPULATOR.java:141)
    at org.jruby.RubyModule.defineAnnotatedMethodsIndividually(RubyModule.java:775)
    at org.jruby.RubyModule.defineAnnotatedMethods(RubyModule.java:649)
    at org.jruby.RubyThread.createThreadClass(RubyThread.java:290)
    at org.jruby.Ruby.initCore(Ruby.java:1329)
    at org.jruby.Ruby.bootstrap(Ruby.java:1223)
    at org.jruby.Ruby.init(Ruby.java:1154)
    at org.jruby.Ruby.newInstance(Ruby.java:276)
    at org.jruby.test.TestRuby.testPrintErrorShouldOnlyPrintErrorMessageWhenBacktraceIsNil(TestRuby.java:179)

testPrintErrorWithStringBacktrace(org.jruby.test.TestRuby)  Time elapsed: 7.555 sec  <<< ERROR!
java.lang.OutOfMemoryError: Java heap space

org.jruby.test.MainTestSuite  Time elapsed: 8.069 sec  <<< ERROR!
java.lang.OutOfMemoryError: Java heap space


Results :

Failed tests: 
  ScriptingContainerTest.testRunScriptlet_String:713 expected:<[?????! ??]JRuby> but was:<[?????! ??]JRuby>
  ScriptingContainerTest.testRunScriptlet_PathType_String:845 expected:<[??? >> ?????? >> ?? >> ???? >> ????????? >> ??????]: 6 in total> but was:<[??? >> ?????? >> ?? >> ???? >> ????????? >> ??????]: 6 in total>
  ScriptingContainerTest.testParse_3args_2:616 expected:<[?? >> ?? >> ?? >> ?? >> ?? >> ?? >> ??? >> ???]: 8 in total> but was:<[?? >> ?? >> ?? >> ?? >> ?? >> ?? >> ??? >> ???]: 8 in total>
  ScriptingContainerTest.testCallMethod_4args_1:973 expected:<[Hello >> ???????????? >> ????? >> ??]: 4 in total> but was:<[?? >> ????? >> ???????????? >> Hello]: 4 in total>

Tests in error: 
  TestRuby.testPrintErrorShouldOnlyPrintErrorMessageWhenBacktraceIsNil:179 ? OutOfMemory
  TestRuby.testPrintErrorWithStringBacktrace ? OutOfMemory Java heap space
  JUnit4Provider.org.jruby.test.MainTestSuite ? OutOfMemory Java heap space

Tests run: 221, Failures: 4, Errors: 3, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] JRuby ............................................. SUCCESS [0.371s]
[INFO] JRuby Core ........................................ FAILURE [1:53.669s]
[INFO] JRuby Ext ......................................... SKIPPED
[INFO] JRuby OpenSSL ..................................... SKIPPED
[INFO] JRuby Readline .................................... SKIPPED
[INFO] JRuby Ripper ...................................... SKIPPED
[INFO] JRuby Integration Tests ........................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:54.441s
[INFO] Finished at: Tue Oct 29 21:47:06 CET 2013
[INFO] Final Memory: 9M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test (default-test) on project jruby-core: There are test failures.
[ERROR] 
[ERROR] Please refer to /Users/peter_v/Documents/data/projects/jruby/jruby/core/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test (default-test) on project jruby-core: There are test failures.

Please refer to /Users/peter_v/Documents/data/projects/jruby/jruby/core/target/surefire-reports for the individual test results.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to /Users/peter_v/Documents/data/projects/jruby/jruby/core/target/surefire-reports for the individual test results.
    at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:82)
    at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:169)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:777)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:645)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :jruby-core
➜  jruby git:(gh-1186_BigMath_log_exp) rake -T
rake aborted!
cannot load such file -- ant
/Users/peter_v/Documents/data/projects/jruby/jruby/rakelib/commands.rake:2:in `<top (required)>'
/Users/peter_v/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/Users/peter_v/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
(See full trace by running task with --trace)
➜  jruby git:(gh-1186_BigMath_log_exp) which ant
/usr/bin/ant

➜  jruby git:(gh-1186_BigMath_log_exp) git status
# On branch gh-1186_BigMath_log_exp
nothing to commit, working directory clean

➜  jruby git:(gh-1186_BigMath_log_exp) git log -2 | cat
commit b6a8fd015bc7aa5a125156bb7de3be00461fcb83
Merge: 1da1ca6 24ace8b
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Tue Oct 29 11:17:37 2013 -0500

    Sync up unit test changes with 1.7.

    Merge branch 'jruby-1_7'

    Conflicts:
        core/pom.xml
        core/src/test/java/org/jruby/embed/ReaderInputStreamTest.java
        core/src/test/java/org/jruby/embed/ScriptingContainerTest.java

commit 24ace8be113595c3d32b489bd4bdeb86d1e1c511
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Tue Oct 29 11:04:24 2013 -0500

    Get unit tests running green.

@headius
Copy link
Member Author

headius commented Oct 29, 2013

Bleh, sorry for the trouble.

Just run the following to get set up with the gems you need:

mvn clean package
bin/jruby -S gem install rspec rake minitest minitest-excludes jruby-launcher

Then rake test:mri should work. We are working to improve this bootstrapping process.

@petervandenabeele
Copy link
Contributor

OK thanks for this advice on twitter.

@headius : @peter_v Yeah you want rake; do "mvn -Ptest to install gems and run unit tests, then rake test:mri hits the MRI tests.

That worked. It took me a while to figure out to deactive rvm with rvm use system ... but now it works, with just 1 test failing :-)

➜  jruby git:(gh-1186_BigMath_log_exp) rvm use system
Now using system ruby.

➜  jruby git:(gh-1186_BigMath_log_exp) bin/jruby -S gem install rspec rake minitest minitest-excludes jruby-launcher
...
10 gems installed

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ bin/jruby -S rake test:mri                                                   
/Users/peter_v/Documents/data/projects/jruby/jruby/bin/jruby -I"lib" -X-C -J-ea -I test/mri -I test/mri/ruby -r ./test/mri_test_env.rb -r minitest/excludes -I"/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared" "/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared/rake/rake_test_loader.rb" ...
...

Finished tests in 147.977000s, 36.9044 tests/s, 5925.0086 assertions/s.

  1) Failure:
TestTranscode#test_shift_jis [/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_transcode.rb:1243]:
[Encoding::UndefinedConversionError] exception expected, not
Class: <Encoding::InvalidByteSequenceError>
Message: <"\"\"\\xEF\"\" on Shift_JIS">
---Backtrace---
org/jruby/RubyString.java:6040:in `encode'
/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_transcode.rb:1243:in `test_shift_jis'
---------------

5461 tests, 876765 assertions, 1 failures, 0 errors, 9 skips

ruby -v: jruby 9000.dev (2.1.0.dev) 2013-10-29 b6a8fd0 on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]
rake aborted!
1

Tasks: TOP => test:mri => test:mri:int
(See full trace by running task with --trace)

@petervandenabeele
Copy link
Contributor

A next issue is how to run a single test and get a newly added module function in the module properly loaded ...

With this dummy implementation:

➜  bigdecimal git:(gh-1186_BigMath_log_exp) ✗ pwd             
/Users/peter_v/data/projects/jruby/jruby/lib/ruby/2.1/bigdecimal

➜  bigdecimal git:(gh-1186_BigMath_log_exp) ✗ tail -5 math.rb 
  #
  def log(x, prec)
    10
  end
end

The test on rake test:mri behaves as expected (incorrect value 10 and should be 0), but limiting the test to only the affected test file does not seem to "load" my newly defined function ? (with undefined methodlog' for BigMath:Module`).

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ bin/jruby -S rake test:mri                           
/Users/peter_v/Documents/data/projects/jruby/jruby/bin/jruby -I"lib" -X-C -J-ea -I test/mri -I test/mri/ruby -r ./test/mri_test_env.rb -r minitest/excludes -I"/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared" "/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared/rake/rake_test_loader.rb" "test/mri/ruby/test_alias.rb" "test/mri/ruby/test_array.rb" "test/mri/ruby/test_assignment.rb" "test/mri/ruby/test_autoload.rb" "test/mri/ruby/test_basicinstructions.rb" "test/mri/ruby/test_beginendblock.rb" "test/mri/ruby/test_bignum.rb" "test/mri/ruby/test_call.rb" "test/mri/ruby/test_case.rb" "test/mri/ruby/test_class.rb" "test/mri/ruby/test_clone.rb" "test/mri/ruby/test_comparable.rb" "test/mri/ruby/test_complex.rb" "test/mri/ruby/test_complex2.rb" "test/mri/ruby/test_complexrational.rb" "test/mri/ruby/test_condition.rb" "test/mri/ruby/test_const.rb" "test/mri/ruby/test_continuation.rb" "test/mri/ruby/test_defined.rb" "test/mri/ruby/test_dir.rb" "test/mri/ruby/test_dir_m17n.rb" "test/mri/ruby/test_econv.rb" "test/mri/ruby/test_encoding.rb" "test/mri/ruby/test_enum.rb" "test/mri/ruby/test_enumerator.rb" "test/mri/ruby/test_env.rb" "test/mri/ruby/test_eval.rb" "test/mri/ruby/test_exception.rb" "test/mri/ruby/test_file.rb" "test/mri/ruby/test_file_exhaustive.rb" "test/mri/ruby/test_fixnum.rb" "test/mri/ruby/test_flip.rb" "test/mri/ruby/test_float.rb" "test/mri/ruby/test_fnmatch.rb" "test/mri/ruby/test_gc.rb" "test/mri/ruby/test_hash.rb" "test/mri/ruby/test_ifunless.rb" "test/mri/ruby/test_integer.rb" "test/mri/ruby/test_integer_comb.rb" "test/mri/ruby/test_io.rb" "test/mri/ruby/test_io_m17n.rb" "test/mri/ruby/test_iterator.rb" "test/mri/ruby/test_lambda.rb" "test/mri/ruby/test_literal.rb" "test/mri/ruby/test_m17n.rb" "test/mri/ruby/test_m17n_comb.rb" "test/mri/ruby/test_marshal.rb" "test/mri/ruby/test_math.rb" "test/mri/ruby/test_metaclass.rb" "test/mri/ruby/test_method.rb" "test/mri/ruby/test_mixed_unicode_escapes.rb" "test/mri/ruby/test_module.rb" "test/mri/ruby/test_notimp.rb" "test/mri/ruby/test_numeric.rb" "test/mri/ruby/test_object.rb" "test/mri/ruby/test_objectspace.rb" "test/mri/ruby/test_optimization.rb" "test/mri/ruby/test_pack.rb" "test/mri/ruby/test_parse.rb" "test/mri/ruby/test_path.rb" "test/mri/ruby/test_pipe.rb" "test/mri/ruby/test_primitive.rb" "test/mri/ruby/test_proc.rb" "test/mri/ruby/test_rand.rb" "test/mri/ruby/test_range.rb" "test/mri/ruby/test_rational.rb" "test/mri/ruby/test_rational2.rb" "test/mri/ruby/test_readpartial.rb" "test/mri/ruby/test_regexp.rb" "test/mri/ruby/test_require.rb" "test/mri/ruby/test_rubyoptions.rb" "test/mri/ruby/test_settracefunc.rb" "test/mri/ruby/test_signal.rb" "test/mri/ruby/test_sleep.rb" "test/mri/ruby/test_sprintf.rb" "test/mri/ruby/test_sprintf_comb.rb" "test/mri/ruby/test_string.rb" "test/mri/ruby/test_stringchar.rb" "test/mri/ruby/test_struct.rb" "test/mri/ruby/test_super.rb" "test/mri/ruby/test_symbol.rb" "test/mri/ruby/test_syntax.rb" "test/mri/ruby/test_system.rb" "test/mri/ruby/test_thread.rb" "test/mri/ruby/test_time.rb" "test/mri/ruby/test_time_tz.rb" "test/mri/ruby/test_trace.rb" "test/mri/ruby/test_transcode.rb" "test/mri/ruby/test_undef.rb" "test/mri/ruby/test_unicode_escape.rb" "test/mri/ruby/test_variable.rb" "test/mri/ruby/test_whileuntil.rb" "test/mri/ruby/test_yield.rb" "test/mri/test_pp.rb" "test/mri/test_cmath.rb" "test/mri/test_delegate.rb" "test/mri/test_find.rb" "test/mri/test_ipaddr.rb" "test/mri/test_open3.rb" "test/mri/test_pp.rb" "test/mri/test_prettyprint.rb" "test/mri/test_prime.rb" "test/mri/test_pstore.rb" "test/mri/test_pty.rb" "test/mri/test_securerandom.rb" "test/mri/test_set.rb" "test/mri/test_shellwords.rb" "test/mri/test_singleton.rb" "test/mri/test_syslog.rb" "test/mri/test_tempfile.rb" "test/mri/test_time.rb" "test/mri/test_timeout.rb" "test/mri/test_tsort.rb" "test/mri/base64/test_base64.rb" "test/mri/benchmark/test_benchmark.rb" "test/mri/bigdecimal/test_bigdecimal.rb" "test/mri/bigdecimal/test_bigdecimal_util.rb" "test/mri/bigdecimal/test_bigmath.rb" "test/mri/cgi/test_cgi_cookie.rb" "test/mri/cgi/test_cgi_core.rb" "test/mri/cgi/test_cgi_header.rb" "test/mri/cgi/test_cgi_modruby.rb" "test/mri/cgi/test_cgi_multipart.rb" "test/mri/cgi/test_cgi_session.rb" "test/mri/cgi/test_cgi_tag_helper.rb" "test/mri/cgi/test_cgi_util.rb" "test/mri/coverage/test_coverage.rb" "test/mri/csv/test_csv_parsing.rb" "test/mri/csv/test_csv_writing.rb" "test/mri/csv/test_data_converters.rb" "test/mri/csv/test_encodings.rb" "test/mri/csv/test_features.rb" "test/mri/csv/test_headers.rb" "test/mri/csv/test_interface.rb" "test/mri/csv/test_row.rb" "test/mri/csv/test_table.rb" "test/mri/date/test_date.rb" "test/mri/date/test_date_arith.rb" "test/mri/date/test_date_attr.rb" "test/mri/date/test_date_base.rb" "test/mri/date/test_date_compat.rb" "test/mri/date/test_date_conv.rb" "test/mri/date/test_date_marshal.rb" "test/mri/date/test_date_new.rb" "test/mri/date/test_date_parse.rb" "test/mri/date/test_date_strftime.rb" "test/mri/date/test_date_strptime.rb" "test/mri/date/test_date_parse.rb" "test/mri/date/test_switch_hitter.rb" "test/mri/digest/test_digest.rb" "test/mri/digest/test_digest_extend.rb" "test/mri/digest/test_digest_hmac.rb" "test/mri/erb/test_erb.rb" "test/mri/erb/test_erb_m17n.rb" "test/mri/etc/test_etc.rb" "test/mri/fileutils/test_dryrun.rb" "test/mri/fileutils/test_fileutils.rb" "test/mri/fileutils/test_nowrite.rb" "test/mri/fileutils/test_verbose.rb" "test/mri/json/test_json.rb" "test/mri/json/test_json_addition.rb" "test/mri/json/test_json_encoding.rb" "test/mri/json/test_json_fixtures.rb" "test/mri/json/test_json_generate.rb" "test/mri/json/test_json_generic_object.rb" "test/mri/json/test_json_string_matching.rb" "test/mri/json/test_json_unicode.rb" "test/mri/logger/test_logger.rb" "test/mri/matrix/test_matrix.rb" "test/mri/matrix/test_vector.rb" "test/mri/monitor/test_monitor.rb" "test/mri/nkf/test_kconv.rb" "test/mri/nkf/test_nkf.rb" "test/mri/openssl/test_asn1.rb" "test/mri/openssl/test_bn.rb" "test/mri/openssl/test_buffering.rb" "test/mri/openssl/test_cipher.rb" "test/mri/openssl/test_config.rb" "test/mri/openssl/test_digest.rb" "test/mri/openssl/test_hmac.rb" "test/mri/openssl/test_ns_spki.rb" "test/mri/openssl/test_pair.rb" "test/mri/openssl/test_pkcs12.rb" "test/mri/openssl/test_pkcs7.rb" "test/mri/openssl/test_pkey_dh.rb" "test/mri/openssl/test_pkey_dsa.rb" "test/mri/openssl/test_pkey_rsa.rb" "test/mri/openssl/test_ssl.rb" "test/mri/openssl/test_x509cert.rb" "test/mri/openssl/test_x509crl.rb" "test/mri/openssl/test_x509ext.rb" "test/mri/openssl/test_x509name.rb" "test/mri/openssl/test_x509req.rb" "test/mri/openssl/test_x509store.rb" "test/mri/optparse/test_bash_completion.rb" "test/mri/optparse/test_getopts.rb" "test/mri/optparse/test_noarg.rb" "test/mri/optparse/test_optarg.rb" "test/mri/optparse/test_optparse.rb" "test/mri/optparse/test_placearg.rb" "test/mri/optparse/test_reqarg.rb" "test/mri/optparse/test_summary.rb" "test/mri/optparse/test_zsh_completion.rb" "test/mri/ostruct/test_ostruct.rb" "test/mri/pathname/test_pathname.rb" "test/mri/psych/test_alias_and_anchor.rb" "test/mri/psych/test_array.rb" "test/mri/psych/test_boolean.rb" "test/mri/psych/test_class.rb" "test/mri/psych/test_coder.rb" "test/mri/psych/test_date_time.rb" "test/mri/psych/test_deprecated.rb" "test/mri/psych/test_document.rb" "test/mri/psych/test_emitter.rb" "test/mri/psych/test_encoding.rb" "test/mri/psych/test_engine_manager.rb" "test/mri/psych/test_exception.rb" "test/mri/psych/test_hash.rb" "test/mri/psych/test_json_tree.rb" "test/mri/psych/test_merge_keys.rb" "test/mri/psych/test_nil.rb" "test/mri/psych/test_null.rb" "test/mri/psych/test_numeric.rb" "test/mri/psych/test_object.rb" "test/mri/psych/test_object_references.rb" "test/mri/psych/test_omap.rb" "test/mri/psych/test_parser.rb" "test/mri/psych/test_psych.rb" "test/mri/psych/test_scalar.rb" "test/mri/psych/test_scalar_scanner.rb" "test/mri/psych/test_serialize_subclasses.rb" "test/mri/psych/test_set.rb" "test/mri/psych/test_stream.rb" "test/mri/psych/test_string.rb" "test/mri/psych/test_struct.rb" "test/mri/psych/test_symbol.rb" "test/mri/psych/test_tainted.rb" "test/mri/psych/test_to_yaml_properties.rb" "test/mri/psych/test_tree_builder.rb" "test/mri/psych/test_yaml.rb" "test/mri/psych/test_yamlstore.rb" "test/mri/psych/json/test_stream.rb" "test/mri/psych/nodes/test_enumerable.rb" "test/mri/psych/visitors/test_depth_first.rb" "test/mri/psych/visitors/test_emitter.rb" "test/mri/psych/visitors/test_to_ruby.rb" "test/mri/psych/visitors/test_yaml_tree.rb" "test/mri/ripper/test_files.rb" "test/mri/ripper/test_filter.rb" "test/mri/ripper/test_parser_events.rb" "test/mri/ripper/test_ripper.rb" "test/mri/scanf/test_scanf.rb" "test/mri/scanf/test_scanfblocks.rb" "test/mri/socket/test_basicsocket.rb" "test/mri/socket/test_nonblock.rb" "test/mri/socket/test_socket.rb" "test/mri/stringio/test_stringio.rb" "test/mri/strscan/test_stringscanner.rb" "test/mri/thread/test_queue.rb" "test/mri/zlib/test_zlib.rb" "test/mri/ruby/enc/test_big5.rb" "test/mri/ruby/enc/test_cp949.rb" "test/mri/ruby/enc/test_emoji.rb" "test/mri/ruby/enc/test_euc_jp.rb" "test/mri/ruby/enc/test_euc_kr.rb" "test/mri/ruby/enc/test_euc_tw.rb" "test/mri/ruby/enc/test_gb18030.rb" "test/mri/ruby/enc/test_gbk.rb" "test/mri/ruby/enc/test_iso_8859.rb" "test/mri/ruby/enc/test_koi8.rb" "test/mri/ruby/enc/test_shift_jis.rb" "test/mri/ruby/enc/test_utf16.rb" "test/mri/ruby/enc/test_utf32.rb" "test/mri/ruby/enc/test_windows_1251.rb" 
/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_marshal.rb:281 warning: already initialized constant Résumé
Run options: 

# Running tests:

..................................../Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/cgi/test_cgi_multipart.rb:122 warning: Tempfile#unlink or delete called on open file; ignoring
./Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/cgi/test_cgi_multipart.rb:334 warning: Tempfile#unlink or delete called on open file; ignoring
./Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/2.1/cgi/core.rb:582 warning: Tempfile#unlink or delete called on open file; ignoring
/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/2.1/cgi/core.rb:582 warning: Tempfile#unlink or delete called on open file; ignoring
... (repeated a few hundred times)
/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/2.1/cgi/core.rb:554 warning: Tempfile#unlink or delete called on open file; ignoring
/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/2.1/cgi/core.rb:554 warning: Tempfile#unlink or delete called on open file; ignoring
/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/cgi/test_cgi_multipart.rb:183 warning: Tempfile#unlink or delete called on open file; ignoring
/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/cgi/test_cgi_multipart.rb:183 warning: Tempfile#unlink or delete called on open file; ignoring
.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F............................/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/bigdecimal/test_bigdecimal.rb:106 warning: SAFE levels are not supported in JRuby
............................................................................................................................................................................................................................................................................................................................................................................................................................/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/coverage/test_coverage.rb:11 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................./Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_gc.rb:40 warning: GC.enable does nothing on JRuby
/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_gc.rb:42 warning: GC.disable does nothing on JRuby
./Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_gc.rb:15 warning: GC.stress= does nothing on JRuby
......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................../Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_iterator.rb:451 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
.................................................................................................................................................................................................../bin/sh: ldd: command not found
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F..........................................................................................................................................................

Finished tests in 147.497000s, 37.0313 tests/s, 5944.2972 assertions/s.

  1) Failure:
TestBigDecimal#test_BigMath_log_with_1 [/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/bigdecimal/test_bigdecimal.rb:1355]:
Expected |0.0 - 10| (10.0) to be <= 0.001.

  2) Failure:
TestTranscode#test_shift_jis [/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_transcode.rb:1243]:
[Encoding::UndefinedConversionError] exception expected, not
Class: <Encoding::InvalidByteSequenceError>
Message: <"\"\"\\xEF\"\" on Shift_JIS">
---Backtrace---
org/jruby/RubyString.java:6040:in `encode'
/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/ruby/test_transcode.rb:1243:in `test_shift_jis'
---------------

5462 tests, 876766 assertions, 2 failures, 0 errors, 9 skips

ruby -v: jruby 9000.dev (2.1.0.dev) 2013-10-29 b6a8fd0 on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]
rake aborted!
2

Tasks: TOP => test:mri => test:mri:int
(See full trace by running task with --trace)

# This (above) is the expected behavior.

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ bin/jruby -S rake test:mri TEST=test/mri/bigdecimal/test_bigdecimal.rb
/Users/peter_v/Documents/data/projects/jruby/jruby/bin/jruby -I"lib" -X-C -J-ea -I test/mri -I test/mri/ruby -r ./test/mri_test_env.rb -r minitest/excludes -I"/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared" "/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared/rake/rake_test_loader.rb" "test/mri/bigdecimal/test_bigdecimal.rb" 
Run options: 

# Running tests:

E............................/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/bigdecimal/test_bigdecimal.rb:106 warning: SAFE levels are not supported in JRuby
.................................

Finished tests in 0.189000s, 328.0423 tests/s, 1137.5661 assertions/s.

  1) Error:
TestBigDecimal#test_BigMath_log_with_1:
NoMethodError: undefined method `log' for BigMath:Module
    /Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/bigdecimal/test_bigdecimal.rb:1355:in `test_BigMath_log_with_1'

62 tests, 215 assertions, 0 failures, 1 errors, 0 skips

ruby -v: jruby 9000.dev (2.1.0.dev) 2013-10-29 b6a8fd0 on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]
rake aborted!
1

Tasks: TOP => test:mri => test:mri:int
(See full trace by running task with --trace)

@headius
Copy link
Member Author

headius commented Oct 30, 2013

You will want to define the method like this:

module BigMath
  def log(x, prec)
    ...
  end
  module_function :log
end

And to run an individual test you can just jruby -n .

@petervandenabeele
Copy link
Contributor

Thanks for the reply, but kind of weird though ... The entire module already has:

28 module BigMath                                                                       
 27   module_function
...
 16   def sqrt(x, prec)                                                                  
 15     x.sqrt(prec)                                                                     
 14   end                                        

Which turns copies all follow-on methods into module methods.

Second, when running the full test suite with rake test:mri the result is as expected
(with the module method present, and responding with the incorrect '10' value).

It is only when running a single test file with TEST=test/mri/bigdecimal/test_bigmath.rb
that I see this failure.

Sorry, but I also fail to understand on the jruby -n comment ... some utterly naive trials
and looking up the option with --help.

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ bin/jruby -n                                                       
^C%                                                                                                                                                                              

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ bin/jruby -n rake test:mri TEST=test/mri/bigdecimal/test_bigmath.rb
Error opening script file: /Users/peter_v/Documents/data/projects/jruby/jruby/rake (No such file or directory)

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ bin/jruby -n rake test:mri                                         
Error opening script file: /Users/peter_v/Documents/data/projects/jruby/jruby/rake (No such file or directory)

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ jruby -n
zsh: correct 'jruby' to 'ruby' [nyae]? n
zsh: command not found: jruby

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ bin/jruby --help | grep '\-n'
  -a              autosplit mode with -n or -p (splits $_ into $F)
  -n              assume 'while gets(); ... end' loop around your script
  -p              assume loop like -n but print line also like sed

Thanks!

@petervandenabeele
Copy link
Contributor

OK, fixed it with this diff. I will commit this in my branch.

diff --git a/test/mri/bigdecimal/test_bigdecimal.rb b/test/mri/bigdecimal/test_bigdecimal.rb
index 07c79a8..5bee2ea 100644
--- a/test/mri/bigdecimal/test_bigdecimal.rb
+++ b/test/mri/bigdecimal/test_bigdecimal.rb
@@ -1,5 +1,6 @@
 require_relative "testbase"
 require_relative "../ruby/envutil"
+require 'bigdecimal/math'

 require 'thread'

The isolated test needed an extra require (not surprisingly ... on the file that has the method under test). This require otherwise seemed to appear earlier in the test sequence in a require by test_bigmath.rb.

Maybe this problem occurs in more places, that tests in isolation have hidden dependencies on other tests?

Now I get the expected single failure on the returned value (10):

➜  jruby git:(gh-1186_BigMath_log_exp) ✗ bin/jruby -S rake test:mri TEST=test/mri/bigdecimal/test_bigdecimal.rb
/Users/peter_v/Documents/data/projects/jruby/jruby/bin/jruby -I"lib" -X-C -J-ea -I test/mri -I test/mri/ruby -r ./test/mri_test_env.rb -r minitest/excludes -I"/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared" "/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared/rake/rake_test_loader.rb" "test/mri/bigdecimal/test_bigdecimal.rb" 
Run options: 

# Running tests:

F............................/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/bigdecimal/test_bigdecimal.rb:107 warning: SAFE levels are not supported in JRuby
.................................

Finished tests in 0.173000s, 358.3815 tests/s, 1248.5549 assertions/s.

  1) Failure:
TestBigDecimal#test_BigMath_log_with_1 [/Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/bigdecimal/test_bigdecimal.rb:1356]:
Expected |0.0 - 10| (10.0) to be <= 0.001.

62 tests, 216 assertions, 1 failures, 0 errors, 0 skips

ruby -v: jruby 9000.dev (2.1.0.dev) 2013-10-29 b6a8fd0 on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]
rake aborted!
1

Tasks: TOP => test:mri => test:mri:int
(See full trace by running task with --trace)

Thanks again @headius for the support on this.

@headius
Copy link
Member Author

headius commented Oct 30, 2013

If this file needs to be required for the test, we should fix that in MRI's tests too. I have commit rights there, so I'll take care of that.

Looks like you're on your way to impl now!

@headius
Copy link
Member Author

headius commented Oct 30, 2013

Strange....jruby master has that require line for me already.

@petervandenabeele
Copy link
Contributor

Strange indeed. I just fetched/pulled again a few minutes ago and redid that commit here.

Let's compare absolute sha's

➜  jruby git:(isolated_test) ✗ git log -2 | cat
commit f7508674d1154818f75a91cddb6a8aee4d8c1f0c
Author: Peter Vandenabeele <peter@vandenabeele.com>
Date:   Wed Oct 30 18:47:53 2013 +0100

    Add require 'bigdecimal/math' for running the isolated test

commit ceb9b7ca80a6e22105e06aba2cd10b40c527e783
Merge: d83c6c3 a2c0adb
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Wed Oct 30 09:48:03 2013 -0500

    Merge branch 'jruby-1_7'

➜  jruby git:(isolated_test) ✗ git diff ceb9b7ca8..f750867 | cat
diff --git a/test/mri/bigdecimal/test_bigdecimal.rb b/test/mri/bigdecimal/test_bigdecimal.rb
index 07c79a8..5bee2ea 100644
--- a/test/mri/bigdecimal/test_bigdecimal.rb
+++ b/test/mri/bigdecimal/test_bigdecimal.rb
@@ -1,5 +1,6 @@
 require_relative "testbase"
 require_relative "../ruby/envutil"
+require 'bigdecimal/math'

 require 'thread'

All the rest starts to work nicely now ... (with 1 test actived log(1).should == 0),
I can get red and green tests with a "0" implementation (of course, further
triangulation will follow).

➜  jruby git:(isolated_test) ✗ bin/jruby -S rake test:mri TEST=test/mri/bigdecimal/test_bigdecimal.rb
/Users/peter_v/Documents/data/projects/jruby/jruby/bin/jruby -I"lib" -X-C -J-ea -I test/mri -I test/mri/ruby -r ./test/mri_test_env.rb -r minitest/excludes -I"/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared" "/Users/peter_v/Documents/data/projects/jruby/jruby/lib/ruby/shared/rake/rake_test_loader.rb" "test/mri/bigdecimal/test_bigdecimal.rb" 
Run options: 

# Running tests:

............................./Users/peter_v/Documents/data/projects/jruby/jruby/test/mri/bigdecimal/test_bigdecimal.rb:107 warning: SAFE levels are not supported in JRuby
.................................

Finished tests in 0.158000s, 392.4051 tests/s, 1379.7468 assertions/s.

62 tests, 218 assertions, 0 failures, 0 errors, 0 skips

ruby -v: jruby 9000.dev (2.1.0.dev) 2013-10-29 b6a8fd0 on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]

➜  jruby git:(isolated_test) ✗ bin/jruby -e 'require "bigdecimal"; require "bigdecimal/math";  puts BigMath.log(BigDecimal('8'), 5)'
0.0

@petervandenabeele
Copy link
Contributor

Interestingly, this is the 160 line C implementation that we want to reproduce in JRuby ...
(in C, Java, ruby, or maybe ... a Java implementation for arbitrary precision Math already exists ?).

(from https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2777-2937 )

/* call-seq:
 * BigMath.log(decimal, numeric)    -> BigDecimal
 *
 * Computes the natural logarithm of +decimal+ to the specified number of
 * digits of precision, +numeric+.
 *
 * If +decimal+ is zero or negative, raises Math::DomainError.
 *
 * If +decimal+ is positive infinity, returns Infinity.
 *
 * If +decimal+ is NaN, returns NaN.
 */
static VALUE
BigMath_s_log(VALUE klass, VALUE x, VALUE vprec)
{
    ssize_t prec, n, i;
    SIGNED_VALUE expo;
    Real* vx = NULL;
    VALUE argv[2], vn, one, two, w, x2, y, d;
    int zero = 0;
    int negative = 0;
    int infinite = 0;
    int nan = 0;
    double flo;
    long fix;

    if (!is_integer(vprec)) {
    rb_raise(rb_eArgError, "precision must be an Integer");
    }

    prec = NUM2SSIZET(vprec);
    if (prec <= 0) {
    rb_raise(rb_eArgError, "Zero or negative precision for exp");
    }

    /* TODO: the following switch statement is almostly the same as one in the
     *       BigDecimalCmp function. */
    switch (TYPE(x)) {
      case T_DATA:
      if (!is_kind_of_BigDecimal(x)) break;
      vx = DATA_PTR(x);
      zero = VpIsZero(vx);
      negative = VpGetSign(vx) < 0;
      infinite = VpIsPosInf(vx) || VpIsNegInf(vx);
      nan = VpIsNaN(vx);
      break;

      case T_FIXNUM:
    fix = FIX2LONG(x);
    zero = fix == 0;
    negative = fix < 0;
    goto get_vp_value;

      case T_BIGNUM:
    zero = RBIGNUM_ZERO_P(x);
    negative = RBIGNUM_NEGATIVE_P(x);
get_vp_value:
    if (zero || negative) break;
    vx = GetVpValue(x, 0);
    break;

      case T_FLOAT:
    flo = RFLOAT_VALUE(x);
    zero = flo == 0;
    negative = flo < 0;
    infinite = isinf(flo);
    nan = isnan(flo);
    if (!zero && !negative && !infinite && !nan) {
        vx = GetVpValueWithPrec(x, DBL_DIG+1, 1);
    }
    break;

      case T_RATIONAL:
    zero = RRATIONAL_ZERO_P(x);
    negative = RRATIONAL_NEGATIVE_P(x);
    if (zero || negative) break;
    vx = GetVpValueWithPrec(x, prec, 1);
    break;

      case T_COMPLEX:
    rb_raise(rb_eMathDomainError,
         "Complex argument for BigMath.log");

      default:
    break;
    }
    if (infinite && !negative) {
    Real* vy;
    vy = VpCreateRbObject(prec, "#0");
    RB_GC_GUARD(vy->obj);
    VpSetInf(vy, VP_SIGN_POSITIVE_INFINITE);
    return ToValue(vy);
    }
    else if (nan) {
    Real* vy;
    vy = VpCreateRbObject(prec, "#0");
    RB_GC_GUARD(vy->obj);
    VpSetNaN(vy);
    return ToValue(vy);
    }
    else if (zero || negative) {
    rb_raise(rb_eMathDomainError,
         "Zero or negative argument for log");
    }
    else if (vx == NULL) {
    cannot_be_coerced_into_BigDecimal(rb_eArgError, x);
    }
    x = ToValue(vx);

    RB_GC_GUARD(one) = ToValue(VpCreateRbObject(1, "1"));
    RB_GC_GUARD(two) = ToValue(VpCreateRbObject(1, "2"));

    n = prec + rmpd_double_figures();
    RB_GC_GUARD(vn) = SSIZET2NUM(n);
    expo = VpExponent10(vx);
    if (expo < 0 || expo >= 3) {
    char buf[16];
    snprintf(buf, 16, "1E%"PRIdVALUE, -expo);
    x = BigDecimal_mult2(x, ToValue(VpCreateRbObject(1, buf)), vn);
    }
    else {
    expo = 0;
    }
    w = BigDecimal_sub(x, one);
    argv[0] = BigDecimal_add(x, one);
    argv[1] = vn;
    x = BigDecimal_div2(2, argv, w);
    RB_GC_GUARD(x2) = BigDecimal_mult2(x, x, vn);
    RB_GC_GUARD(y)  = x;
    RB_GC_GUARD(d)  = y;
    i = 1;
    while (!VpIsZero((Real*)DATA_PTR(d))) {
    SIGNED_VALUE const ey = VpExponent10(DATA_PTR(y));
    SIGNED_VALUE const ed = VpExponent10(DATA_PTR(d));
    ssize_t m = n - vabs(ey - ed);
    if (m <= 0) {
        break;
    }
    else if ((size_t)m < rmpd_double_figures()) {
        m = rmpd_double_figures();
    }

    x = BigDecimal_mult2(x2, x, vn);
    i += 2;
    argv[0] = SSIZET2NUM(i);
    argv[1] = SSIZET2NUM(m);
    d = BigDecimal_div2(2, argv, x);
    y = BigDecimal_add(y, d);
    }

    y = BigDecimal_mult(y, two);
    if (expo != 0) {
    VALUE log10, vexpo, dy;
    log10 = BigMath_s_log(klass, INT2FIX(10), vprec);
    vexpo = ToValue(GetVpValue(SSIZET2NUM(expo), 1));
    dy = BigDecimal_mult(log10, vexpo);
    y = BigDecimal_add(y, dy);
    }

    return y;
}

@headius
Copy link
Member Author

headius commented Oct 30, 2013

There are definitely open-source libraries that add additional BigDecimal capabilities on top of Java's BigDecimal, and some which provide their own BigDecimal impls too. But since we only need two methods, I'm reluctant to pull in yet another external library. So...

  • If we can find something public-domain or that can be simply copied into JRuby, that works.
  • Or we can implement our own logic.
  • Or if we absolutely have to we can look at adding a 3rd-party library as is.

@petervandenabeele
Copy link
Contributor

I am already working on the translation of the C implementation to Ruby. Going well :-)
(and completing the MRI tests in the process; the "logical" test coverage in a pure TDD perspective is not really complete).

See https://github.com/petervandenabeele/jruby/compare/gh-1186-BigMath-log for the progress.

@petervandenabeele
Copy link
Contributor

So, this is going to work out, nearly there ...
https://github.com/petervandenabeele/jruby/compare/gh-1186-BigMath-log

@headius
Copy link
Member Author

headius commented Nov 18, 2013

Fixed by #1235. Thank you!

@headius headius closed this as completed Nov 18, 2013
@petervandenabeele
Copy link
Contributor

For clarity #1235 only implemented BigMath.log.

Will see if I find time for BigMath.exp

@headius
Copy link
Member Author

headius commented Nov 18, 2013

Ahh of course. I will reopen.

@headius headius reopened this Nov 18, 2013
@enebo enebo modified the milestone: JRuby 9.0.0.0 Jul 14, 2015
@headius
Copy link
Member Author

headius commented Oct 14, 2015

exp was added in 9.0.1.

@headius headius closed this as completed Oct 14, 2015
@headius headius added this to the JRuby 9.0.1.0 milestone Oct 14, 2015
@headius headius added the stdlib label Oct 14, 2015
@headius headius mentioned this issue Nov 14, 2016
71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants