long-decimal 0.00.14 → 0.00.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,8 @@
2
2
  #
3
3
  # testlongdecimal.rb -- runit test for long-decimal.rb
4
4
  #
5
- # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.9 2006/03/19 11:17:55 bk1 Exp $
6
- # CVS-Label: $Name: PRE_ALPHA_0_14 $
5
+ # CVS-ID: $Header: /var/cvs/long-decimal/long-decimal/test/testlongdecimal.rb,v 1.11 2006/03/20 21:38:32 bk1 Exp $
6
+ # CVS-Label: $Name: PRE_ALPHA_0_15 $
7
7
  # Author: $Author: bk1 $ (Karl Brodowsky)
8
8
  #
9
9
 
@@ -18,7 +18,7 @@ load "lib/long-decimal.rb"
18
18
  #
19
19
  class TestLongDecimal_class < RUNIT::TestCase
20
20
 
21
- @RCS_ID='-$Id: testlongdecimal.rb,v 1.9 2006/03/19 11:17:55 bk1 Exp $-'
21
+ @RCS_ID='-$Id: testlongdecimal.rb,v 1.11 2006/03/20 21:38:32 bk1 Exp $-'
22
22
 
23
23
  #
24
24
  # helper method for test_split_merge_words
@@ -427,7 +427,7 @@ class TestLongDecimal_class < RUNIT::TestCase
427
427
  end
428
428
 
429
429
  #
430
- # helper method for test_sqrtb
430
+ # helper method for test_int_sqrtb
431
431
  #
432
432
  def check_sqrtb(x, s)
433
433
  y = LongMath.sqrtb(x)
@@ -441,7 +441,7 @@ class TestLongDecimal_class < RUNIT::TestCase
441
441
  #
442
442
  # test method sqrtb for calculating sqrt of short integers
443
443
  #
444
- def test_sqrtb
444
+ def test_int_sqrtb
445
445
  assert_equal(Complex(0,1), LongMath.sqrtb(-1), "sqrt(-1)=i")
446
446
  1024.times do |x|
447
447
  check_sqrtb(x, " loop x=#{x}")
@@ -477,7 +477,7 @@ class TestLongDecimal_class < RUNIT::TestCase
477
477
  end
478
478
 
479
479
  #
480
- # helper method of test_sqrtw
480
+ # helper method of test_int_sqrtw
481
481
  #
482
482
  def check_sqrtw(x, s)
483
483
  y = LongMath.sqrtw(x)
@@ -491,7 +491,7 @@ class TestLongDecimal_class < RUNIT::TestCase
491
491
  #
492
492
  # test method sqrtb for calculating sqrt of long integers
493
493
  #
494
- def test_sqrtw
494
+ def test_int_sqrtw
495
495
  assert_equal(Complex(0,1), LongMath.sqrtw(-1), "sqrt(-1)=i")
496
496
  1024.times do |x|
497
497
  check_sqrtw(x, " loop x=#{x}")
@@ -527,7 +527,7 @@ class TestLongDecimal_class < RUNIT::TestCase
527
527
  end
528
528
 
529
529
  #
530
- # helper method for test_sqrtb_with_remainder
530
+ # helper method for test_int_sqrtb_with_remainder
531
531
  #
532
532
  def check_sqrtb_with_remainder(x, s)
533
533
  y, r = LongMath.sqrtb_with_remainder(x)
@@ -543,7 +543,7 @@ class TestLongDecimal_class < RUNIT::TestCase
543
543
  #
544
544
  # test method sqrtb_with_remainder for calculating sqrt _with_remainderof short integers
545
545
  #
546
- def test_sqrtb_with_remainder
546
+ def test_int_sqrtb_with_remainder
547
547
  10.times do |x|
548
548
  check_sqrtb_with_remainder(x, " loop x=#{x}")
549
549
  end
@@ -583,7 +583,7 @@ class TestLongDecimal_class < RUNIT::TestCase
583
583
  end
584
584
 
585
585
  #
586
- # helper method for test_sqrtw_with_remainder
586
+ # helper method for test_int_sqrtw_with_remainder
587
587
  #
588
588
  def check_sqrtw_with_remainder(x, s)
589
589
  y, r = LongMath.sqrtw_with_remainder(x)
@@ -599,7 +599,7 @@ class TestLongDecimal_class < RUNIT::TestCase
599
599
  #
600
600
  # test method sqrtb_with_remainder for calculating sqrt _with_remainderof long integers
601
601
  #
602
- def test_sqrtw_with_remainder
602
+ def test_int_sqrtw_with_remainder
603
603
  10.times do |x|
604
604
  check_sqrtw_with_remainder(x, " loop x=#{x}")
605
605
  end
@@ -1712,6 +1712,303 @@ class TestLongDecimal_class < RUNIT::TestCase
1712
1712
  end
1713
1713
  end
1714
1714
 
1715
+ #
1716
+ # test of &-operator of LongDecimal
1717
+ #
1718
+ def test_logand
1719
+ x = LongDecimal(224, 2) # 0x0e0 / 100
1720
+
1721
+ y = LongDecimal(3, 1) # 0x01e / 100
1722
+ z = x & y
1723
+ zz = LongDecimal(0, 2) # 0x000 / 100
1724
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1725
+ assert_equal(zz, z, "z=#{z.inspect}")
1726
+ z = y & x
1727
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1728
+ assert_equal(zz, z, "z=#{z.inspect}")
1729
+
1730
+ y = LongDecimal(32, 1) # 0x140 / 100
1731
+ z = x & y
1732
+ zz = LongDecimal(64, 2) # 0x040 / 100
1733
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1734
+ assert_equal(zz, z, "z=#{z.inspect}")
1735
+ z = y & x
1736
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1737
+ assert_equal(zz, z, "z=#{z.inspect}")
1738
+
1739
+ y = 5 # 0x1f4 / 100
1740
+ z = x & y
1741
+ zz = LongDecimal(224, 2) # 0x0e0 / 100
1742
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1743
+ assert_equal(zz, z, "z=#{z.inspect}")
1744
+ # does not coerce
1745
+ # z = y & x
1746
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1747
+ # assert_equal(zz, z, "z=#{z.inspect}")
1748
+
1749
+ y = 1 # 0x064 / 100
1750
+ z = x & y
1751
+ zz = LongDecimal(96, 2) # 0x060 / 100
1752
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1753
+ assert_equal(zz, z, "z=#{z.inspect}")
1754
+ # does not coerce
1755
+ # z = y & x
1756
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1757
+ # assert_equal(zz, z, "z=#{z.inspect}")
1758
+
1759
+ y = 256 # 0x06400 / 100
1760
+ z = x & y
1761
+ zz = LongDecimal(0, 2) # 0x000 / 100
1762
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1763
+ assert_equal(zz, z, "z=#{z.inspect}")
1764
+ # does not coerce
1765
+ # z = y & x
1766
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1767
+ # assert_equal(zz, z, "z=#{z.inspect}")
1768
+ end
1769
+
1770
+ #
1771
+ # test of |-operator of LongDecimal
1772
+ #
1773
+ def test_logior
1774
+ x = LongDecimal(224, 2) # 0x0e0 / 100
1775
+
1776
+ y = LongDecimal(3, 1) # 0x01e / 100
1777
+ z = x | y
1778
+ zz = LongDecimal(254, 2) # 0x0fe / 100
1779
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1780
+ assert_equal(zz, z, "z=#{z.inspect}")
1781
+ z = y | x
1782
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1783
+ assert_equal(zz, z, "z=#{z.inspect}")
1784
+
1785
+ y = LongDecimal(32, 1) # 0x140 / 100
1786
+ z = x | y
1787
+ zz = LongDecimal(480, 2) # 0x1e0 / 100
1788
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1789
+ assert_equal(zz, z, "z=#{z.inspect}")
1790
+ z = y | x
1791
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1792
+ assert_equal(zz, z, "z=#{z.inspect}")
1793
+
1794
+ y = 5 # 0x1f4 / 100
1795
+ z = x | y
1796
+ zz = LongDecimal(500, 2) # 0x1f4 / 100
1797
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1798
+ assert_equal(zz, z, "z=#{z.inspect}")
1799
+ # does not coerce
1800
+ # z = y | x
1801
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1802
+ # assert_equal(zz, z, "z=#{z.inspect}")
1803
+
1804
+ y = 1 # 0x064 / 100
1805
+ z = x | y
1806
+ zz = LongDecimal(228, 2) # 0x0e4 / 100
1807
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1808
+ assert_equal(zz, z, "z=#{z.inspect}")
1809
+ # does not coerce
1810
+ # z = y | x
1811
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1812
+ # assert_equal(zz, z, "z=#{z.inspect}")
1813
+
1814
+ y = 256 # 0x06400 / 100
1815
+ z = x | y
1816
+ zz = LongDecimal(25824, 2) # 0x064e0 / 100
1817
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1818
+ assert_equal(zz, z, "z=#{z.inspect}")
1819
+ # does not coerce
1820
+ # z = y | x
1821
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1822
+ # assert_equal(zz, z, "z=#{z.inspect}")
1823
+ end
1824
+
1825
+ #
1826
+ # test of ^-operator of LongDecimal
1827
+ #
1828
+ def test_logxor
1829
+ x = LongDecimal(224, 2) # 0x0e0 / 100
1830
+
1831
+ y = LongDecimal(3, 1) # 0x01e / 100
1832
+ z = x ^ y
1833
+ zz = LongDecimal(254, 2) # 0x0fe / 100
1834
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1835
+ assert_equal(zz, z, "z=#{z.inspect}")
1836
+ z = y ^ x
1837
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1838
+ assert_equal(zz, z, "z=#{z.inspect}")
1839
+
1840
+ y = LongDecimal(32, 1) # 0x140 / 100
1841
+ z = x ^ y
1842
+ zz = LongDecimal(416, 2) # 0x1a0 / 100
1843
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1844
+ assert_equal(zz, z, "z=#{z.inspect}")
1845
+ z = y ^ x
1846
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1847
+ assert_equal(zz, z, "z=#{z.inspect}")
1848
+
1849
+ y = 5 # 0x1f4 / 100
1850
+ z = x ^ y
1851
+ zz = LongDecimal(276, 2) # 0x114 / 100
1852
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1853
+ assert_equal(zz, z, "z=#{z.inspect}")
1854
+ # does not coerce
1855
+ # z = y ^ x
1856
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1857
+ # assert_equal(zz, z, "z=#{z.inspect}")
1858
+
1859
+ y = 1 # 0x064 / 100
1860
+ z = x ^ y
1861
+ zz = LongDecimal(132, 2) # 0x084 / 100
1862
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1863
+ assert_equal(zz, z, "z=#{z.inspect}")
1864
+ # does not coerce
1865
+ # z = y ^ x
1866
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1867
+ # assert_equal(zz, z, "z=#{z.inspect}")
1868
+
1869
+ y = 256 # 0x06400 / 100
1870
+ z = x ^ y
1871
+ zz = LongDecimal(25824, 2) # 0x064e0 / 100
1872
+ assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1873
+ assert_equal(zz, z, "z=#{z.inspect}")
1874
+ # does not coerce
1875
+ # z = y ^ x
1876
+ # assert_kind_of(LongDecimal, z, "z=#{z.inspect}")
1877
+ # assert_equal(zz, z, "z=#{z.inspect}")
1878
+ end
1879
+
1880
+ #
1881
+ # test of ^-operator of LongDecimal
1882
+ #
1883
+ def test_lognot
1884
+ x = LongDecimal(224, 2) # 0x0e0 / 100
1885
+ y = ~x
1886
+ z = LongDecimal(-225, 2)
1887
+ assert_kind_of(LongDecimal, y, "y=#{y.inspect}")
1888
+ assert_equal(z, y, "y=#{y.inspect}")
1889
+ x = LongDecimal(0, 2) # 0x00 / 100
1890
+ y = ~x
1891
+ z = LongDecimal(-1, 2)
1892
+ assert_kind_of(LongDecimal, y, "y=#{y.inspect}")
1893
+ assert_equal(z, y, "y=#{y.inspect}")
1894
+ end
1895
+
1896
+ #
1897
+ # test << and >> of LongDecimal
1898
+ #
1899
+ def test_shift
1900
+ n = 12345678901234567890
1901
+ x = LongDecimal(n, 9)
1902
+ y = x << 5
1903
+ yy = LongDecimal(n * 32, 9)
1904
+ z = y >> 5
1905
+ assert_equal(yy, y, "shift left")
1906
+ assert_equal(x, z, "shift left then right")
1907
+
1908
+ y = x >> 5
1909
+ yy = LongDecimal(n >> 5, 9)
1910
+ z = y << 5
1911
+ zz = LongDecimal((n >> 5) << 5, 9)
1912
+ assert_equal(yy, y, "shift right")
1913
+ assert_equal(zz, z, "shift right then left")
1914
+ end
1915
+
1916
+ #
1917
+ # test [] access to digits
1918
+ #
1919
+ def test_bin_digit
1920
+ n = 12345678901234567890
1921
+ x = LongDecimal(n, 9)
1922
+ 100.times do |i|
1923
+ assert_equal(n[i], x[i], "i=#{i}")
1924
+ end
1925
+ n = -12345678901234567890
1926
+ x = LongDecimal(n, 9)
1927
+ 100.times do |i|
1928
+ assert_equal(n[i], x[i], "i=#{i}")
1929
+ end
1930
+ end
1931
+
1932
+ #
1933
+ # test move_point_left and move_point_right
1934
+ #
1935
+ def test_move_point
1936
+ n = 12345678901234567890
1937
+ x = LongDecimal(n, 9)
1938
+
1939
+ y = x.move_point_left(4)
1940
+ yy = x.move_point_right(-4)
1941
+ assert_equal(y, yy, "left / right 4")
1942
+ z = LongDecimal(n, 13)
1943
+ assert_equal(y, z, "left 4")
1944
+ w = y.move_point_right(4)
1945
+ assert_equal(x, w, "left 4 right 4")
1946
+
1947
+ y = x.move_point_left(12)
1948
+ yy = x.move_point_right(-12)
1949
+ assert_equal(y, yy, "left / right 12")
1950
+ z = LongDecimal(n, 21)
1951
+ assert_equal(y, z, "left 12")
1952
+ w = y.move_point_right(12)
1953
+ assert_equal(x, w, "left 12 right 12")
1954
+
1955
+ y = x.move_point_right(4)
1956
+ z = LongDecimal(n, 4)
1957
+ assert_equal(y, z, "right 4")
1958
+ w = y.move_point_left(4)
1959
+ ww = y.move_point_right(-4)
1960
+ assert_equal(w, ww, "left / right 4")
1961
+ assert_equal(x, w, "right 4 left 4")
1962
+
1963
+ y = x.move_point_left(12)
1964
+ yy = x.move_point_right(-12)
1965
+ assert_equal(y, yy, "left / right 12")
1966
+ z = LongDecimal(n * 1000, 0)
1967
+ assert_equal(y, z, "left 12")
1968
+ w = y.move_point_right(12)
1969
+ v = x.round_to_scale(12)
1970
+ assert_equal(v, w, "right 12 left 12")
1971
+ end
1972
+
1973
+ #
1974
+ # helper method of test_sqrt
1975
+ #
1976
+ def check_sqrt(x, scale, mode, su0, su1, str)
1977
+ y = x.sqrt(scale, mode)
1978
+ z0 = (y+su0*y.unit).square
1979
+ z1 = (y+su1*y.unit).square
1980
+ assert(0 <= y.sign, "sqrt must be >= 0" + str)
1981
+ assert(z0 <= x && x <= z1, "y=#{y}=sqrt(#{x}) and x in [#{z0}, #{z1})" + str)
1982
+ y
1983
+ end
1984
+
1985
+ #
1986
+ # test sqrt of LongDecimal
1987
+ #
1988
+ def test_sqrt
1989
+ x = LongDecimal.zero!(101)
1990
+ y = check_sqrt(x, 120, LongDecimal::ROUND_UNNECESSARY, 0, 0, "zero")
1991
+ assert(y.zero?, "sqrt(0)")
1992
+
1993
+ x = LongDecimal.one!(101)
1994
+ y = check_sqrt(x, 120, LongDecimal::ROUND_UNNECESSARY, 0, 0, "one")
1995
+ assert(y.one?, "sqrt(1)")
1996
+
1997
+ x = LongDecimal.two!(101)
1998
+ y0 = check_sqrt(x, 120, LongDecimal::ROUND_DOWN, 0, 1, "two")
1999
+ y1 = check_sqrt(x, 120, LongDecimal::ROUND_HALF_EVEN, -1, 1, "two")
2000
+ y2 = check_sqrt(x, 120, LongDecimal::ROUND_UP, -1, 0, "two")
2001
+ assert(y0 <= y1, "y0 y1")
2002
+ assert(y1 <= y2, "y1 y2")
2003
+
2004
+ x = 4.to_ld.round_to_scale(101)
2005
+ y0 = check_sqrt(x, 120, LongDecimal::ROUND_DOWN, 0, 0, "four")
2006
+ y1 = check_sqrt(x, 120, LongDecimal::ROUND_HALF_EVEN, 0, 0, "four")
2007
+ y2 = check_sqrt(x, 120, LongDecimal::ROUND_UP, 0, 0, "four")
2008
+ assert_equal(y0, y1, "y0 y1")
2009
+ assert_equal(y1, y2, "y1 y2")
2010
+ end
2011
+
1715
2012
  #
1716
2013
  # test absolute value of LongDecimal
1717
2014
  #
@@ -1819,6 +2116,11 @@ class TestLongDecimal_class < RUNIT::TestCase
1819
2116
 
1820
2117
  end
1821
2118
 
2119
+ # TODO
2120
+ # def test_is_int
2121
+ # def test_zero
2122
+ # def test_one
2123
+
1822
2124
  #
1823
2125
  # test sign-method of LongDecimal
1824
2126
  #
@@ -2199,7 +2501,10 @@ class TestLongDecimal_class < RUNIT::TestCase
2199
2501
  assert_equal(ff, f, "must be equal")
2200
2502
  end
2201
2503
 
2202
- # to_i not tested, goes via to_r anyway
2504
+ # test_to_i: to_i not tested, goes via to_r anyway
2505
+
2506
+ # TODO
2507
+ # def test_to_ld
2203
2508
 
2204
2509
  #
2205
2510
  # test negation operator (unary -) of LongDecimalQuot
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: long-decimal
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.00.14
7
- date: 2006-03-19 00:00:00 +01:00
6
+ version: 0.00.15
7
+ date: 2006-03-20 00:00:00 +01:00
8
8
  summary: LongDecimal for numbers with fixed point
9
9
  require_paths:
10
10
  - lib