Add bin and edit workflow
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s

This commit is contained in:
2026-09-16 13:11:16 -06:00
parent c8ac4fcae5
commit 4cee170d66
17576 changed files with 895740 additions and 2 deletions
@@ -0,0 +1,13 @@
require 'facets/math/abs'
test_case Math do
class_method :abs do
test do
Math.abs(-3.1).assert == 3.1
Math.abs( 0.0).assert == 0.0
Math.abs( 3.1).assert == 3.1
end
end
end
@@ -0,0 +1,23 @@
require 'facets/math/acot'
require 'facets/numeric/range' # used to test within a precision
test_case Math do
class_method :acot do
test do
Math.acot(-1.0).range(1.0e-6).assert === 0.5 * Math::PI - Math.atan(-1.0)
Math.acot( 1.0).range(1.0e-6).assert === 0.5 * Math::PI - Math.atan( 1.0)
end
end
# TODO: Check complementarity of acot and cot
#assert_equal_float(1.0, Math.acot(Math.cot(1.0)), 1.0e-6)
#assert_equal_float(1.0, Math.cot(Math.acot(1.0)), 1.0e-6)
#assert_equal_float(2.0, Math.acot(Math.cot(2.0)), 1.0e-6)
#assert_equal_float(2.0, Math.cot(Math.acot(2.0)), 1.0e-6)
# TODO: Check consistency of atan2 and acot
#assert_equal_float(Math.atan2(1.0, 1.0), Math.acot(1.0), 1.0e-6)
#assert_equal_float(Math.atan2(1.0, 2.0), Math.acot(2.0), 1.0e-6)
end
@@ -0,0 +1,22 @@
require 'facets/math/acoth'
require 'facets/math/coth'
require 'facets/numeric/range' # used to test within a precision
test_case Math do
class_method :acoth do
test do
Math.acoth(1.5).range(1.0e-6).assert === 0.5 * Math.log(5.0)
Math.acoth(5.0).range(1.0e-6).assert === 0.5 * Math.log(1.5)
end
# 1.0e-6
test "check complementarity of acoth and coth" do
Math.acoth(Math.coth( 1.5)).range(1.0e-6).assert === 1.5
Math.coth(Math.acoth( 1.5)).range(1.0e-6).assert === 1.5
Math.acoth(Math.coth(-1.5)).range(1.0e-6).assert === -1.5
Math.coth(Math.acoth(-1.5)).range(1.0e-6).assert === -1.5
end
end
end
@@ -0,0 +1,19 @@
require 'facets/math/beta'
test_case Math do
class_method :beta do
test do
Math.beta(1.0, 1.0).range(1.0e-6).assert === 1.0
Math.beta(1.0, 2.0).range(1.0e-6).assert === 0.5
Math.beta(1.0, 3.0).range(1.0e-6).assert === 1.0 / 3.0
Math.beta(2.0, 1.0).range(1.0e-6).assert === 0.5
Math.beta(2.0, 2.0).range(1.0e-6).assert === 1.0 / 6.0
Math.beta(2.0, 3.0).range(1.0e-6).assert === 1.0 / 12.0
Math.beta(3.0, 1.0).range(1.0e-6).assert === 1.0 / 3.0
Math.beta(3.0, 2.0).range(1.0e-6).assert === 1.0 / 12.0
Math.beta(3.0, 3.0).range(1.0e-6).assert === 1.0 / 30.0
end
end
end
@@ -0,0 +1,22 @@
require 'facets/math/ceil'
test_case Math do
class_method :ceil do
test do
Math.ceil( 1.99999).assert == 2
Math.ceil( 1.5 ).assert == 2
Math.ceil( 1.00001).assert == 2
Math.ceil( 0.99999).assert == 1
Math.ceil( 0.5 ).assert == 1
Math.ceil( 0.00001).assert == 1
Math.ceil(-0.00001).assert == 0
Math.ceil(-0.5 ).assert == 0
Math.ceil(-0.99999).assert == 0
Math.ceil(-1.00001).assert == -1
Math.ceil(-1.5 ).assert == -1
Math.ceil(-1.99999).assert == -1
end
end
end
@@ -0,0 +1,19 @@
require 'facets/math/cosec'
test_case Math do
class_method :cosec do
test do
Math.cosec(-1.0).assert == 1.0 / Math.sin(-1.0)
Math.cosec( 1.0).assert == 1.0 / Math.sin( 1.0)
end
end
# TODO: Check complementarity of cosec and sin
#assert_equal_float(1.0, Math.cosec(-2.0) * Math.sin(-2.0), 1.0e-6)
#assert_equal_float(1.0, Math.cosec(-1.0) * Math.sin(-1.0), 1.0e-6)
#assert_equal_float(1.0, Math.cosec( 1.0) * Math.sin( 1.0), 1.0e-6)
#assert_equal_float(1.0, Math.cosec( 2.0) * Math.sin( 2.0), 1.0e-6)
end
@@ -0,0 +1,19 @@
require 'facets/math/cosech'
test_case Math do
class_method :cosech do
test do
Math.cosech(-1.0).assert == 1.0 / Math.sinh(-1.0)
Math.cosech( 1.0).assert == 1.0 / Math.sinh( 1.0)
end
test "check complementarity of cosech and sinh" do
(Math.cosech(-2.0) * Math.sinh(-2.0)).assert == 1.0
(Math.cosech(-1.0) * Math.sinh(-1.0)).assert == 1.0
(Math.cosech( 1.0) * Math.sinh( 1.0)).assert == 1.0
(Math.cosech( 2.0) * Math.sinh( 2.0)).assert == 1
end
end
end
@@ -0,0 +1,13 @@
require 'facets/math/cot'
require 'facets/numeric/range' # used to test within a precision
test_case Math do
class_method :cot do
test do
Math.cot(1.0).range(1.0e-6).assert === 1.0 / Math.tan(1.0)
Math.cot(2.0).range(1.0e-6).assert === 1.0 / Math.tan(2.0)
end
end
end
@@ -0,0 +1,13 @@
require 'facets/math/coth'
require 'facets/numeric/range' # used to test within a precision
test_case Math do
class_method :coth do
test do
Math.coth(1.0).range(1.0e-6).assert === 1.0 / Math.tanh(1.0)
Math.coth(2.0).range(1.0e-6).assert === 1.0 / Math.tanh(2.0)
end
end
end
@@ -0,0 +1,16 @@
require 'facets/math/distance'
test_case Math do
class_method :distance do
test do
Math.distance(1, 2).assert == 1.0
Math.distance([1,2], [3,4]).assert >= 2.828427
Math.distance([1,2], [3,4]).assert <= 2.8284271247461903
Math.distance([1,2,3], [4,5,6]).assert >= 5.196152
Math.distance([1,2,3], [4,5,6]).assert <= 5.196152422706632
Math.distance([1,2,3,4], [5,6,7,8]).assert == 8.0
end
end
end
@@ -0,0 +1,14 @@
require 'facets/math/exp10'
require 'facets/numeric/range' # used to test within a precision
test_case Math do
class_method :exp10 do
test do
Math.exp10(0.0).range(1.0e-6).assert === 1.0
Math.exp10(0.5).range(1.0e-6).assert === Math.sqrt(10.0)
Math.exp10(1.0).range(1.0e-6).assert === 10.0
end
end
end
@@ -0,0 +1,14 @@
require 'facets/math/exp2'
require 'facets/numeric/range' # used to test within a precision
test_case Math do
class_method :exp2 do
test do
Math.exp2(0.0).range(1.0e-6).assert === 1.0
Math.exp2(0.5).range(1.0e-6).assert === Math.sqrt(2.0)
Math.exp2(1.0).range(1.0e-6).assert === 2.0
end
end
end
@@ -0,0 +1,13 @@
require 'facets/math/factorial'
test_case Math do
class_method :factorial do
fac = 1
1.upto(100) do |i|
fac *= i
Math.factorial(i).assert == fac
end
end
end
@@ -0,0 +1,23 @@
require 'facets/math/floor'
test_case Math do
class_method :floor do
test do
Math.floor( 1.99999).assert == 1
Math.floor( 1.5 ).assert == 1
Math.floor( 1.00001).assert == 1
Math.floor( 0.99999).assert == 0
Math.floor( 0.5 ).assert == 0
Math.floor( 0.00001).assert == 0
Math.floor(-0.00001).assert == -1
Math.floor(-0.5 ).assert == -1
Math.floor(-0.99999).assert == -1
Math.floor(-1.00001).assert == -2
Math.floor(-1.5 ).assert == -2
Math.floor(-1.99999).assert == -2
end
end
end
@@ -0,0 +1,18 @@
require 'facets/math/gcd'
require 'facets/math/factorial'
test_case Math do
class_method :gcd do
test do
Math.gcd(4732, 4700).assert == 4
Math.gcd(3651, 5023).assert == 1
Math.gcd(612221610, 67461255771).assert == 5565651
end
test "on a factorial" do
Math.factorial(47).assert == Math.gcd(Math.factorial(90), Math.factorial(47))
end
end
end
@@ -0,0 +1,13 @@
require 'facets/math/lcm'
test_case Math do
class_method :lcm do
test do
Math.lcm( 77, 221).assert == 17017
Math.lcm(143, 187).assert == 2431
Math.lcm( 91, 119).assert == 1547
end
end
end
@@ -0,0 +1,17 @@
covers 'facets/math/median'
test_case Math do
class_method :median do
test "fractional" do
r = Math.median [1, 2, 3, 3, 6, 11, 20, 20]
r.assert == 4.5
end
test "whole value" do
r = Math.median [1, 2, 4, 6, 8]
r.assert == 4
end
end
end
@@ -0,0 +1,13 @@
covers 'facets/math/percentile'
test_case Math do
class_method :percentile do
test do
a = [1,1,2,2,3,3,3,4]
r = Math.percentile(a,75)
r.assert == 3.0
end
end
end
@@ -0,0 +1,30 @@
require 'facets/math/pow'
require 'facets/numeric/range'
test_case Math do
class_method :pow do
test do
Math.pow( 4.0, 3.0).range(1.0e-6).assert === 64.0
Math.pow( 0.9, 3.0).range(1.0e-6).assert === 0.729
Math.pow( 0.25, -0.5).range(1.0e-6).assert === 2.0
Math.pow( 64.0, -1.0/3).range(1.0e-6).assert === 0.25
end
end
class_method :pwr do
test do
Math.pwr( 4.0, 3.0).range(1.0e-6).assert === 64.0
Math.pwr( 0.9, 3.0).range(1.0e-6).assert === 0.729
Math.pwr( 0.25, -0.5).range(1.0e-6).assert === 2.0
Math.pwr( 64.0, -1.0/3).range(1.0e-6).assert === 0.25
end
end
# TODO: Check complementarity of pwr and root
# assert_equal_float( 4.0, Math.root(Math.pwr(2.0, 6.0), 3.0), 1.0e-6)
# assert_equal_float( 2.0, Math.root(Math.pwr(4.0, 4.0), 8.0), 1.0e-6)
# assert_equal_float(Math.sqrt(2.0), Math.pwr(Math.root(2.0, 6.0), 3.0), 1.0e-6)
# assert_equal_float( 16.0, Math.pwr(Math.root(4.0, 4.0), 8.0), 1.0e-6)
end
@@ -0,0 +1,15 @@
require 'facets/math/root'
require 'facets/numeric/range'
test_case Math do
class_method :root do
test do
Math.root( 64.0, 3.0).range(1.0e-6).assert === 4.0
Math.root( 0.729, 3.0).range(1.0e-6).assert === 0.9
Math.root( 2.0, -0.5).range(1.0e-6).assert === 0.25
Math.root( 0.25, -1.0/3).range(1.0e-6).assert === 64.0
end
end
end
@@ -0,0 +1,19 @@
require 'facets/math/sec'
require 'facets/numeric/range' # used to test within a precision
test_case Math do
class_method :sec do
test do
Math.sec(1.0).range(1.0e-6).assert === 1.0 / Math.cos(1.0)
Math.sec(2.0).range(1.0e-6).assert === 1.0 / Math.cos(2.0)
end
end
# TODO: Check complementarity of cos and sec
#assert_equal_float(1.0, Math.sec(-2.0) * Math.cos(-2.0), 1.0e-6)
#assert_equal_float(1.0, Math.sec(-1.0) * Math.cos(-1.0), 1.0e-6)
#assert_equal_float(1.0, Math.sec( 1.0) * Math.cos( 1.0), 1.0e-6)
#assert_equal_float(1.0, Math.sec( 2.0) * Math.cos( 2.0), 1.0e-6)
end
@@ -0,0 +1,19 @@
require 'facets/math/sech'
require 'facets/numeric/range' # used to test within a precision
test_case Math do
class_method :sech do
test do
Math.sech(1.0).range(1.0e-6).assert === 1.0 / Math.cosh(1.0)
Math.sech(2.0).range(1.0e-6).assert === 1.0 / Math.cosh(2.0)
end
end
# TODO: Check complementarity of cosh and sech
#assert_equal_float(1.0, Math.sech(-2.0) * Math.cosh(-2.0), 1.0e-6)
#assert_equal_float(1.0, Math.sech(-1.0) * Math.cosh(-1.0), 1.0e-6)
#assert_equal_float(1.0, Math.sech( 1.0) * Math.cosh( 1.0), 1.0e-6)
#assert_equal_float(1.0, Math.sech( 2.0) * Math.cosh( 2.0), 1.0e-6)
end
@@ -0,0 +1,20 @@
require 'facets/math/sign'
test_case Math do
class_method :sign do
test do
Math.sign(-3.1).assert == -1.0
Math.sign( 0.0).assert == 0.0
Math.sign( 3.1).assert == 1.0
end
# Check complementarity of abs and sign
#assert_equal_float(-2.0, Math.abs(-2.0) * Math.sign(-2.0), 1e-6)
#assert_equal_float( 0.0, Math.abs( 0.0) * Math.sign( 0.0), 1e-6)
#assert_equal_float( 3.0, Math.abs( 3.0) * Math.sign( 3.0), 1e-6)
end
end
@@ -0,0 +1,15 @@
require 'facets/math/sinc'
test_case Math do
class_method :sinc do
test do
Math.sinc( 0.0).assert == 1.0
Math.sinc( 1.0).assert == Math.sin(1.0)
Math.sinc(-1.0).assert == Math.sin(1.0)
Math.sinc( 2.0).assert == 0.5 * Math.sin(2.0)
Math.sinc(-2.0).assert == 0.5 * Math.sin(2.0)
end
end
end
@@ -0,0 +1,20 @@
require 'facets/math/sqr'
require 'facets/numeric/range'
test_case Math do
class_method :sqr do
test do
Math.sqr(-0.9).range(1.0e-6).assert === 0.81
Math.sqr(-0.7).range(1.0e-6).assert === 0.49
Math.sqr(-0.7).range(1.0e-6).assert === 0.49
Math.sqr( 0.9).range(1.0e-6).assert === 0.81
end
end
# TODO: Check complementarity of sqrt and sqr
# assert_equal_float(0.3, Math.sqrt(Math.sqr( 0.3)), 1.0e-6)
# assert_equal_float(0.3, Math.sqrt(Math.sqr(-0.3)), 1.0e-6)
# assert_equal_float(0.3, Math.sqr(Math.sqrt( 0.3)), 1.0e-6)
end