fOOrth 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rdoc_options +17 -0
- data/Gemfile +4 -0
- data/README.md +67 -0
- data/bin/fOOrth +8 -0
- data/demo.rb +24 -0
- data/fOOrth.gemspec +40 -0
- data/fOOrth.reek +109 -0
- data/integration/README.md +12 -0
- data/integration/_FILE_test.foorth +5 -0
- data/integration/array_lib_tests.rb +360 -0
- data/integration/class_lib_tests.rb +116 -0
- data/integration/clone_lib_tests.rb +108 -0
- data/integration/comparison_tests.rb +132 -0
- data/integration/compile_lib_tests.rb +190 -0
- data/integration/ctrl_struct_lib_tests.rb +80 -0
- data/integration/data_ref_lib_tests.rb +43 -0
- data/integration/exception_lib_tests.rb +86 -0
- data/integration/fiber_bundle_tests.rb +380 -0
- data/integration/hash_lib_tests.rb +120 -0
- data/integration/in_stream_test_1.txt +4 -0
- data/integration/load_test_one.foorth +6 -0
- data/integration/load_test_two.foorth +4 -0
- data/integration/numeric_lib_tests.rb +321 -0
- data/integration/object_lib_tests.rb +38 -0
- data/integration/procedure_lib_tests.rb +40 -0
- data/integration/queue_lib_tests.rb +66 -0
- data/integration/stack_lib_tests.rb +70 -0
- data/integration/standard_lib_tests.rb +208 -0
- data/integration/stdio_lib_tests.rb +52 -0
- data/integration/stream_lib_tests.rb +196 -0
- data/integration/string_lib_tests.rb +217 -0
- data/integration/support/foorth_testing.rb +135 -0
- data/integration/thread_lib_tests.rb +83 -0
- data/integration/time_lib_tests.rb +791 -0
- data/integration/vm_lib_tests.rb +38 -0
- data/lib/fOOrth.rb +57 -0
- data/lib/fOOrth/compiler.rb +78 -0
- data/lib/fOOrth/compiler/context.rb +49 -0
- data/lib/fOOrth/compiler/context/locals.rb +34 -0
- data/lib/fOOrth/compiler/context/map_name.rb +92 -0
- data/lib/fOOrth/compiler/context/tags.rb +48 -0
- data/lib/fOOrth/compiler/modes.rb +32 -0
- data/lib/fOOrth/compiler/modes/compiled.rb +41 -0
- data/lib/fOOrth/compiler/modes/deferred.rb +57 -0
- data/lib/fOOrth/compiler/modes/delayed.rb +40 -0
- data/lib/fOOrth/compiler/modes/nested.rb +34 -0
- data/lib/fOOrth/compiler/modes/suspend.rb +32 -0
- data/lib/fOOrth/compiler/parser.rb +26 -0
- data/lib/fOOrth/compiler/parser/get_string.rb +71 -0
- data/lib/fOOrth/compiler/parser/normal.rb +53 -0
- data/lib/fOOrth/compiler/parser/skip.rb +50 -0
- data/lib/fOOrth/compiler/parser/special.rb +42 -0
- data/lib/fOOrth/compiler/process.rb +47 -0
- data/lib/fOOrth/compiler/process/generate.rb +24 -0
- data/lib/fOOrth/compiler/process/get_token.rb +23 -0
- data/lib/fOOrth/compiler/process/procedure.rb +55 -0
- data/lib/fOOrth/compiler/process/string.rb +20 -0
- data/lib/fOOrth/compiler/source.rb +51 -0
- data/lib/fOOrth/compiler/source/console.rb +70 -0
- data/lib/fOOrth/compiler/source/file_source.rb +37 -0
- data/lib/fOOrth/compiler/source/read_point.rb +46 -0
- data/lib/fOOrth/compiler/source/string_source.rb +28 -0
- data/lib/fOOrth/compiler/token.rb +37 -0
- data/lib/fOOrth/compiler/word_specs.rb +178 -0
- data/lib/fOOrth/core.rb +27 -0
- data/lib/fOOrth/core/class.rb +116 -0
- data/lib/fOOrth/core/object.rb +78 -0
- data/lib/fOOrth/core/virtual_machine.rb +28 -0
- data/lib/fOOrth/debug.rb +13 -0
- data/lib/fOOrth/debug/context_dump.rb +31 -0
- data/lib/fOOrth/debug/dbg_puts.rb +17 -0
- data/lib/fOOrth/debug/display_abort.rb +37 -0
- data/lib/fOOrth/debug/vm_dump.rb +27 -0
- data/lib/fOOrth/initialize.rb +83 -0
- data/lib/fOOrth/interpreter.rb +24 -0
- data/lib/fOOrth/interpreter/add_to_hash.rb +17 -0
- data/lib/fOOrth/interpreter/data_stack.rb +125 -0
- data/lib/fOOrth/interpreter/do_loop.rb +55 -0
- data/lib/fOOrth/interpreter/squash.rb +25 -0
- data/lib/fOOrth/library.rb +38 -0
- data/lib/fOOrth/library/array_library.rb +577 -0
- data/lib/fOOrth/library/bundle_library.rb +112 -0
- data/lib/fOOrth/library/class_library.rb +90 -0
- data/lib/fOOrth/library/clone_library.rb +72 -0
- data/lib/fOOrth/library/command_library.rb +205 -0
- data/lib/fOOrth/library/compile_library.rb +181 -0
- data/lib/fOOrth/library/complex_library.rb +81 -0
- data/lib/fOOrth/library/ctrl_struct_library.rb +116 -0
- data/lib/fOOrth/library/data_ref_library.rb +100 -0
- data/lib/fOOrth/library/duration/arithmetic.rb +114 -0
- data/lib/fOOrth/library/duration/formatter.rb +152 -0
- data/lib/fOOrth/library/duration/intervals.rb +233 -0
- data/lib/fOOrth/library/duration/make.rb +75 -0
- data/lib/fOOrth/library/duration_library.rb +52 -0
- data/lib/fOOrth/library/fiber_library.rb +120 -0
- data/lib/fOOrth/library/hash_library.rb +203 -0
- data/lib/fOOrth/library/in_stream_library.rb +81 -0
- data/lib/fOOrth/library/integer_library.rb +104 -0
- data/lib/fOOrth/library/mutex_library.rb +31 -0
- data/lib/fOOrth/library/numeric_library.rb +380 -0
- data/lib/fOOrth/library/object_library.rb +80 -0
- data/lib/fOOrth/library/other_value_types_library.rb +96 -0
- data/lib/fOOrth/library/out_stream_library.rb +146 -0
- data/lib/fOOrth/library/procedure_library.rb +65 -0
- data/lib/fOOrth/library/queue_library.rb +47 -0
- data/lib/fOOrth/library/rational_library.rb +90 -0
- data/lib/fOOrth/library/stack_library.rb +56 -0
- data/lib/fOOrth/library/stdio_library.rb +56 -0
- data/lib/fOOrth/library/string_library.rb +285 -0
- data/lib/fOOrth/library/stubs.rb +76 -0
- data/lib/fOOrth/library/sync_bundle_library.rb +50 -0
- data/lib/fOOrth/library/thread_library.rb +73 -0
- data/lib/fOOrth/library/time_library.rb +302 -0
- data/lib/fOOrth/library/vm_library.rb +105 -0
- data/lib/fOOrth/main.rb +125 -0
- data/lib/fOOrth/monkey_patch.rb +14 -0
- data/lib/fOOrth/monkey_patch/complex.rb +30 -0
- data/lib/fOOrth/monkey_patch/exceptions.rb +154 -0
- data/lib/fOOrth/monkey_patch/false.rb +11 -0
- data/lib/fOOrth/monkey_patch/float.rb +22 -0
- data/lib/fOOrth/monkey_patch/integer.rb +22 -0
- data/lib/fOOrth/monkey_patch/nil.rb +11 -0
- data/lib/fOOrth/monkey_patch/numeric.rb +33 -0
- data/lib/fOOrth/monkey_patch/object.rb +43 -0
- data/lib/fOOrth/monkey_patch/rational.rb +31 -0
- data/lib/fOOrth/monkey_patch/string.rb +51 -0
- data/lib/fOOrth/symbol_map.rb +82 -0
- data/lib/fOOrth/version.rb +7 -0
- data/license.txt +21 -0
- data/rakefile.rb +65 -0
- data/reek.txt +1 -0
- data/sire.rb +132 -0
- data/t.txt +3 -0
- data/test.foorth +5 -0
- data/tests/compiler/context_tests.rb +180 -0
- data/tests/compiler/file_source_test_one.txt +1 -0
- data/tests/compiler/file_source_test_three.txt +3 -0
- data/tests/compiler/file_source_test_two.txt +3 -0
- data/tests/compiler/file_source_tests.rb +130 -0
- data/tests/compiler/mode_tests.rb +45 -0
- data/tests/compiler/parser_tests.rb +116 -0
- data/tests/compiler/spec_tests.rb +113 -0
- data/tests/compiler/string_source_tests.rb +128 -0
- data/tests/core_tests.rb +138 -0
- data/tests/interpreter/data_stack_tests.rb +119 -0
- data/tests/monkey_patch/coerce_test.rb +131 -0
- data/tests/monkey_patch/complex_test.rb +25 -0
- data/tests/monkey_patch/numeric_test.rb +62 -0
- data/tests/monkey_patch/object_test.rb +49 -0
- data/tests/monkey_patch/rational_test.rb +57 -0
- data/tests/monkey_patch/string_test.rb +53 -0
- data/tests/symbol_map_tests.rb +53 -0
- metadata +366 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative '../lib/fOOrth'
|
4
|
+
require_relative 'support/foorth_testing'
|
5
|
+
gem 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest_visible'
|
8
|
+
|
9
|
+
#Test the standard fOOrth library.
|
10
|
+
class HashLibraryTester < Minitest::Test
|
11
|
+
|
12
|
+
include XfOOrthTestExtensions
|
13
|
+
|
14
|
+
#Track mini-test progress.
|
15
|
+
include MinitestVisible
|
16
|
+
|
17
|
+
def test_some_hash_basics
|
18
|
+
foorth_equal('Hash ', [Hash])
|
19
|
+
foorth_equal('Hash .new ', [{}])
|
20
|
+
foorth_equal('{ } ', [{}])
|
21
|
+
foorth_equal('{ 4 "A" -> 5 "B" -> } ', [{4=>"A", 5=>"B"}])
|
22
|
+
foorth_equal('{ 1 4 do i dup 3 * -> loop }', [{1=>3, 2=>6, 3=>9}])
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_hashes_with_defaults
|
26
|
+
foorth_run('{ } val$: $thwd')
|
27
|
+
foorth_equal('$thwd', [{}])
|
28
|
+
foorth_equal('"apple" $thwd .[]@', [nil])
|
29
|
+
foorth_run('99 "apple" $thwd .[]!')
|
30
|
+
foorth_equal('"apple" $thwd .[]@', [99])
|
31
|
+
|
32
|
+
foorth_run('42 Hash .new_default val$: $thwd')
|
33
|
+
foorth_equal('$thwd', [{}])
|
34
|
+
foorth_equal('"apple" $thwd .[]@', [42])
|
35
|
+
foorth_run('99 "apple" $thwd .[]!')
|
36
|
+
foorth_equal('"apple" $thwd .[]@', [99])
|
37
|
+
|
38
|
+
foorth_run('Hash .new_default{{ 42 }} val$: $thwd')
|
39
|
+
foorth_equal('$thwd', [{}])
|
40
|
+
foorth_equal('"apple" $thwd .[]@', [42])
|
41
|
+
foorth_run('99 "apple" $thwd .[]!')
|
42
|
+
foorth_equal('"apple" $thwd .[]@', [99])
|
43
|
+
|
44
|
+
foorth_run('{ } val$: $thwd')
|
45
|
+
foorth_equal('$thwd', [{}])
|
46
|
+
foorth_equal('"apple" $thwd .[]@', [nil])
|
47
|
+
foorth_run('24 $thwd .default')
|
48
|
+
foorth_equal('"apple" $thwd .[]@', [24])
|
49
|
+
foorth_run('99 "apple" $thwd .[]!')
|
50
|
+
foorth_equal('"apple" $thwd .[]@', [99])
|
51
|
+
|
52
|
+
foorth_run('{ } val$: $thwd')
|
53
|
+
foorth_equal('$thwd', [{}])
|
54
|
+
foorth_equal('"apple" $thwd .[]@', [nil])
|
55
|
+
foorth_run('$thwd .default{{ 12 }}')
|
56
|
+
foorth_equal('"apple" $thwd .[]@', [12])
|
57
|
+
foorth_run('99 "apple" $thwd .[]!')
|
58
|
+
foorth_equal('"apple" $thwd .[]@', [99])
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_hashes_in_variables
|
62
|
+
foorth_equal('{ 1 3 -> 2 6 -> 3 9 -> } val$: $thiv1 ', [])
|
63
|
+
foorth_equal('$thiv1', [{1=>3, 2=>6, 3=>9}])
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_simple_hash_indexing
|
67
|
+
foorth_equal('{ 0 3 do i dup 3 * -> loop } val$: $tshi1', [])
|
68
|
+
foorth_equal('$tshi1', [{0=>0, 1=>3, 2=>6}])
|
69
|
+
|
70
|
+
foorth_equal('1 $tshi1 .[]@', [3])
|
71
|
+
foorth_equal('4 1 $tshi1 .[]!', [])
|
72
|
+
foorth_equal('1 $tshi1 .[]@', [4])
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_the_hash_each
|
76
|
+
foorth_equal('{ 0 3 do i dup 3 * -> loop } val$: $tshi2', [])
|
77
|
+
foorth_equal('$tshi2', [{0=>0, 1=>3, 2=>6}])
|
78
|
+
|
79
|
+
foorth_equal('$tshi2 .each{{ x }} ', [0,1,2])
|
80
|
+
foorth_equal('$tshi2 .each{{ v }} ', [0,3,6])
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_keys_and_values
|
85
|
+
foorth_equal('{ 0 3 do i dup 3 * -> loop } val$: $tshi3', [])
|
86
|
+
|
87
|
+
foorth_equal('$tshi3 .keys', [[0,1,2]])
|
88
|
+
foorth_equal('$tshi3 .values', [[0,3,6]])
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_pretty_print_and_support
|
93
|
+
foorth_equal('{ 0 11 do i dup dup * -> loop } val$: $tppas1', [])
|
94
|
+
|
95
|
+
foorth_equal('$tppas1 .strmax2', [2,3])
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_hash_length
|
100
|
+
foorth_equal('{ "a" 1 -> "b" 2 -> } .length', [2])
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_hash_empty
|
104
|
+
foorth_equal('{ } .empty?', [true])
|
105
|
+
foorth_equal('{ "a" 1 -> } .empty?', [false])
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_hash_to_s
|
109
|
+
foorth_equal('{ 1 2 -> 3 4 -> } .to_s', ["{ 1 2 -> 3 4 -> }"])
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_compatibility_methods
|
113
|
+
foorth_equal('{ 0 2 -> 1 4 -> 2 6 -> 3 8 -> } .to_h ', [{0=>2, 1=>4, 2=>6, 3=>8}])
|
114
|
+
foorth_equal('{ 0 2 -> 1 4 -> 2 6 -> 3 8 -> } .to_a ', [[2,4,6,8]])
|
115
|
+
foorth_equal('{ 0 2 -> 1 4 -> 2 6 -> 3 8 -> } .map{{ v 1+ }}', [{0=>3,1=>5,2=>7,3=>9}])
|
116
|
+
foorth_equal('{ 0 2 -> 1 4 -> 2 6 -> 3 8 -> } .select{{ v 2/ 1 and 0= }}', [{1=>4, 3=>8}])
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,321 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative '../lib/fOOrth'
|
4
|
+
require_relative 'support/foorth_testing'
|
5
|
+
gem 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest_visible'
|
8
|
+
|
9
|
+
#Test the standard fOOrth numeric (and related) library.
|
10
|
+
class NumericLibraryTester < Minitest::Test
|
11
|
+
|
12
|
+
include XfOOrthTestExtensions
|
13
|
+
|
14
|
+
#Track mini-test progress.
|
15
|
+
include MinitestVisible
|
16
|
+
|
17
|
+
def test_some_conversions
|
18
|
+
foorth_equal('5 .to_n', [5])
|
19
|
+
foorth_equal('5.0 .to_n', [5.0])
|
20
|
+
foorth_equal('5/1 .to_n', ['5/1'.to_r])
|
21
|
+
foorth_equal('5+0i .to_n', [Complex(5,0)])
|
22
|
+
foorth_equal('"xx" .to_n', [nil])
|
23
|
+
|
24
|
+
foorth_equal('5 .to_n!', [5])
|
25
|
+
foorth_equal('5.0 .to_n!', [5.0])
|
26
|
+
foorth_equal('5/1 .to_n!', ['5/1'.to_r])
|
27
|
+
foorth_equal('5+0i .to_n!', [Complex(5,0)])
|
28
|
+
foorth_raises('"xx" .to_n!')
|
29
|
+
|
30
|
+
foorth_equal('5 .to_i', [5])
|
31
|
+
foorth_equal('5.0 .to_i', [5])
|
32
|
+
foorth_equal('5/1 .to_i', [5])
|
33
|
+
foorth_equal('5+0i .to_i', [5])
|
34
|
+
|
35
|
+
foorth_equal('5 .to_i!', [5])
|
36
|
+
foorth_equal('5.0 .to_i!', [5])
|
37
|
+
foorth_equal('5/1 .to_i!', [5])
|
38
|
+
foorth_equal('5+0i .to_i!', [5])
|
39
|
+
|
40
|
+
foorth_equal('"xx" .to_i', [nil])
|
41
|
+
foorth_equal('5+3i .to_i', [nil])
|
42
|
+
|
43
|
+
foorth_raises('"xx" .to_i!')
|
44
|
+
foorth_raises('5+3i .to_i!')
|
45
|
+
|
46
|
+
foorth_equal('"2.0" .to_f ', [2.0])
|
47
|
+
foorth_equal('"apple" .to_f ', [nil])
|
48
|
+
foorth_equal('"2.0" .to_f!', [2.0])
|
49
|
+
foorth_raises('"apple" .to_f!')
|
50
|
+
|
51
|
+
foorth_equal('7 .to_r', [Rational(7,1)])
|
52
|
+
foorth_equal('7.0 .to_r', [Rational(7,1)])
|
53
|
+
foorth_equal('1.3 .to_r', [Rational(13,10)])
|
54
|
+
foorth_equal('2.5 .to_r', [Rational(5,2)])
|
55
|
+
foorth_equal('"5/2" .to_r', [Rational(5,2)])
|
56
|
+
foorth_equal('"apple" .to_r', [nil])
|
57
|
+
|
58
|
+
foorth_equal('7 .to_r!', [Rational(7,1)])
|
59
|
+
foorth_equal('7.0 .to_r!', [Rational(7,1)])
|
60
|
+
foorth_equal('1.3 .to_r!', [Rational(13,10)])
|
61
|
+
foorth_equal('2.5 .to_r!', [Rational(5,2)])
|
62
|
+
foorth_equal('"5/2" .to_r!', [Rational(5,2)])
|
63
|
+
foorth_raises('"apple" .to_r!')
|
64
|
+
|
65
|
+
foorth_equal('5 .to_x', [Complex(5,0)])
|
66
|
+
foorth_equal('5.2 .to_x', [Complex(5.2,0)])
|
67
|
+
foorth_equal('"5" .to_x', [Complex(5,0)])
|
68
|
+
foorth_equal('1+2i .to_x', [Complex(1,2)])
|
69
|
+
foorth_equal('"apple" .to_x', [nil])
|
70
|
+
|
71
|
+
foorth_equal('5 .to_x!', [Complex(5,0)])
|
72
|
+
foorth_equal('5.2 .to_x!', [Complex(5.2,0)])
|
73
|
+
foorth_equal('"5" .to_x!', [Complex(5,0)])
|
74
|
+
foorth_equal('1+2i .to_x!', [Complex(1,2)])
|
75
|
+
foorth_raises('"apple" .to_x!')
|
76
|
+
|
77
|
+
foorth_equal('5 .real', [5])
|
78
|
+
foorth_equal('5 .imaginary', [0])
|
79
|
+
|
80
|
+
foorth_equal('5+7i .real', [5])
|
81
|
+
foorth_equal('5+7i .imaginary', [7])
|
82
|
+
|
83
|
+
foorth_equal('3 .magnitude', [3])
|
84
|
+
foorth_equal('3 .angle .r2d', [0])
|
85
|
+
foorth_equal('-3 .angle .r2d', [180])
|
86
|
+
|
87
|
+
foorth_equal('3+4i .magnitude', [5])
|
88
|
+
foorth_equal('1+1i .angle .r2d', [45.0])
|
89
|
+
|
90
|
+
foorth_equal('42 .conjugate', [42])
|
91
|
+
foorth_equal('1+1i .conjugate', [Complex(1,-1)])
|
92
|
+
|
93
|
+
foorth_equal('1+1i .polar .r2d', [Math.sqrt(2.0), 45.0])
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_some_computations
|
97
|
+
foorth_equal('5 3 +', [8])
|
98
|
+
foorth_equal('5 3 -', [2])
|
99
|
+
foorth_equal('5 3 *', [15])
|
100
|
+
foorth_equal('5 3 /', [1])
|
101
|
+
foorth_equal('5 3 mod', [2])
|
102
|
+
foorth_raises('1+1i 3 mod')
|
103
|
+
foorth_raises('3 1+1i mod')
|
104
|
+
|
105
|
+
foorth_equal('5 "3" +', [8])
|
106
|
+
foorth_equal('5 "3" -', [2])
|
107
|
+
foorth_equal('5 "3" *', [15])
|
108
|
+
foorth_equal('5 "3" /', [1])
|
109
|
+
foorth_equal('5 "3" mod', [2])
|
110
|
+
|
111
|
+
foorth_equal('5 neg', [-5])
|
112
|
+
foorth_equal('0 neg', [0])
|
113
|
+
foorth_equal('-5 neg', [5])
|
114
|
+
|
115
|
+
foorth_equal('5.0 neg', [-5.0])
|
116
|
+
foorth_equal('0.0 neg', [0.0])
|
117
|
+
foorth_equal('-5.0 neg', [5.0])
|
118
|
+
|
119
|
+
foorth_equal('5 3 <<', [40])
|
120
|
+
foorth_equal('40 3 >>', [5])
|
121
|
+
|
122
|
+
foorth_equal('2 10 **', [1024])
|
123
|
+
foorth_equal('2.0 .1/x', [0.5])
|
124
|
+
|
125
|
+
foorth_equal(' 2.0 .abs', [2.0])
|
126
|
+
foorth_equal('-2.0 .abs', [2.0])
|
127
|
+
|
128
|
+
foorth_equal(' 2.0 .ceil', [2])
|
129
|
+
foorth_equal(' 2.1 .ceil', [3])
|
130
|
+
foorth_equal(' 2.9 .ceil', [3])
|
131
|
+
foorth_raises('1+1i .ceil')
|
132
|
+
|
133
|
+
foorth_equal(' 2.0 .floor', [2])
|
134
|
+
foorth_equal(' 2.1 .floor', [2])
|
135
|
+
foorth_equal(' 2.9 .floor', [2])
|
136
|
+
foorth_raises('1+1i .floor')
|
137
|
+
|
138
|
+
foorth_equal(' 2.0 .round', [2])
|
139
|
+
foorth_equal(' 2.1 .round', [2])
|
140
|
+
foorth_equal(' 2.9 .round', [3])
|
141
|
+
foorth_raises('1+1i .round')
|
142
|
+
|
143
|
+
foorth_equal(' 1.5 .numerator', [3])
|
144
|
+
foorth_equal(' 1.5 .denominator', [2])
|
145
|
+
|
146
|
+
foorth_equal(' 3/2 .numerator', [3])
|
147
|
+
foorth_equal(' 3/2 .denominator', [2])
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_some_bitwise_ops
|
152
|
+
foorth_equal("5 3 and", [1])
|
153
|
+
foorth_equal("5 3 or", [7])
|
154
|
+
foorth_equal("5 3 xor", [6])
|
155
|
+
foorth_equal("5 com", [-6])
|
156
|
+
|
157
|
+
foorth_equal("5 3 <<", [40])
|
158
|
+
foorth_equal("40 3 >>", [5])
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_some_trig
|
163
|
+
foorth_equal("pi", [Math::PI])
|
164
|
+
foorth_equal("e", [Math::E])
|
165
|
+
foorth_equal("dpr", [XfOOrth::DegreesPerRadian])
|
166
|
+
|
167
|
+
foorth_equal("45 .d2r dup .sin dup * swap .cos dup * + ", [1.0])
|
168
|
+
|
169
|
+
foorth_equal("0 .tan ", [0.0])
|
170
|
+
|
171
|
+
foorth_equal("1 .asin .r2d", [90.0])
|
172
|
+
foorth_equal("1 .acos .r2d", [ 0.0])
|
173
|
+
foorth_equal("1 .atan .r2d", [45.0])
|
174
|
+
foorth_equal("1 1 .atan2 .r2d", [45.0])
|
175
|
+
|
176
|
+
foorth_raises('1+1i .sin')
|
177
|
+
foorth_raises('1+1i .cos')
|
178
|
+
foorth_raises('1+1i .tan')
|
179
|
+
foorth_raises('1+1i .asin')
|
180
|
+
foorth_raises('1+1i .acos')
|
181
|
+
foorth_raises('1+1i .atan')
|
182
|
+
foorth_raises('1+1i 3 .atan2')
|
183
|
+
foorth_raises('1 1+1i .atan2')
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_some_exagerated_trig
|
187
|
+
foorth_equal("0 .sinh ", [0.0])
|
188
|
+
foorth_equal("0 .cosh ", [1.0])
|
189
|
+
foorth_equal("0 .tanh ", [0.0])
|
190
|
+
|
191
|
+
foorth_equal("0 .asinh ", [0.0])
|
192
|
+
foorth_equal("1 .acosh ", [0.0])
|
193
|
+
foorth_equal("0 .atanh ", [0.0])
|
194
|
+
|
195
|
+
foorth_raises('1+1i .sinh')
|
196
|
+
foorth_raises('1+1i .cosh')
|
197
|
+
foorth_raises('1+1i .tanh')
|
198
|
+
foorth_raises('1+1i .asinh')
|
199
|
+
foorth_raises('1+1i .acosh')
|
200
|
+
foorth_raises('1+1i .atanh')
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_some_powers
|
204
|
+
foorth_equal("0 .e**", [1.0])
|
205
|
+
foorth_equal("1 .ln", [0.0])
|
206
|
+
foorth_equal("e .ln", [1.0])
|
207
|
+
|
208
|
+
foorth_equal("2 .10**", [100.0])
|
209
|
+
foorth_equal("100 .log10", [2.0])
|
210
|
+
|
211
|
+
foorth_equal("10 .2**", [1024.0])
|
212
|
+
foorth_equal("1024 .log2", [10.0])
|
213
|
+
|
214
|
+
foorth_equal("16 .sqr ", [256])
|
215
|
+
foorth_equal("16.0 .sqr ", [256.0])
|
216
|
+
foorth_equal("1+1i .sqr ", [Complex(0,2)])
|
217
|
+
foorth_equal("16 .cube", [4096])
|
218
|
+
foorth_equal("16.0 .cube", [4096.0])
|
219
|
+
foorth_equal("1+1i .cube", [Complex(-2,2)])
|
220
|
+
|
221
|
+
foorth_equal("1024 .sqrt", [32.0])
|
222
|
+
foorth_equal("0+1i .sqrt", [Complex(0.7071067811865476, 0.7071067811865475)])
|
223
|
+
|
224
|
+
foorth_equal("8 .cbrt", [ 2.0])
|
225
|
+
foorth_equal("64 .cbrt", [ 4.0])
|
226
|
+
|
227
|
+
foorth_equal("3 4 .hypot", [5.0])
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_some_integer_ops
|
231
|
+
foorth_equal("100 64 .gcd", [4])
|
232
|
+
foorth_equal("100 64 .lcm", [1600])
|
233
|
+
|
234
|
+
foorth_equal("100 .even?", [true])
|
235
|
+
foorth_equal("101 .even?", [false])
|
236
|
+
foorth_equal("16666600 .even?", [true])
|
237
|
+
foorth_equal("16666601 .even?", [false])
|
238
|
+
|
239
|
+
foorth_equal("100 .odd?", [false])
|
240
|
+
foorth_equal("101 .odd?", [true])
|
241
|
+
foorth_equal("16666600 .odd?", [false])
|
242
|
+
foorth_equal("16666601 .odd?", [true])
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_being_rational
|
247
|
+
foorth_equal("1/2 .split", [1, 2])
|
248
|
+
|
249
|
+
foorth_equal("1 2 rational", ['1/2'.to_r])
|
250
|
+
foorth_equal("3.1 4 rational", ['31/40'.to_r])
|
251
|
+
foorth_equal('"3.1" 4 rational', ['31/40'.to_r])
|
252
|
+
foorth_equal('pi 1 rational', ['245_850_922/78_256_779'.to_r])
|
253
|
+
foorth_equal('"apple" 4 rational', [nil])
|
254
|
+
|
255
|
+
foorth_equal("1 2 rational!", ['1/2'.to_r])
|
256
|
+
foorth_equal("3.1 4 rational!", ['31/40'.to_r])
|
257
|
+
foorth_equal('"3.1" 4 rational!', ['31/40'.to_r])
|
258
|
+
foorth_raises('"apple" 4 rational!')
|
259
|
+
foorth_raises('nil 4 rational!')
|
260
|
+
foorth_raises('false 4 rational!')
|
261
|
+
foorth_raises('true 4 rational!')
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_that_we_do_not_rationalize_too_much
|
265
|
+
foorth_equal('0.01 pi .rationalize_to', ['22/7'.to_r])
|
266
|
+
foorth_equal('0.001 pi .rationalize_to', ['201/64'.to_r])
|
267
|
+
foorth_equal('0.0001 pi .rationalize_to', ['333/106'.to_r])
|
268
|
+
foorth_equal('0.00001 pi .rationalize_to', ['355/113'.to_r])
|
269
|
+
foorth_equal('0.000001 pi .rationalize_to', ['355/113'.to_r])
|
270
|
+
foorth_equal('0.0000001 pi .rationalize_to', ['75948/24175'.to_r])
|
271
|
+
|
272
|
+
foorth_equal('0.01 1234/55 .rationalize_to', ['157/7'.to_r])
|
273
|
+
|
274
|
+
foorth_raises('0.01 1+5i .rationalize_to')
|
275
|
+
foorth_raises('0.01 "apple" .rationalize_to')
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_being_complex
|
279
|
+
foorth_equal("1 2 complex", [Complex(1,2)])
|
280
|
+
foorth_equal("1+2i .split", [1, 2])
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_the_polar_vortex
|
284
|
+
foorth_equal("1 1 .c2p .r2d", [Math::sqrt(2.0), 45.0])
|
285
|
+
#foorth_equal("2.0 .sqrt 45 .d2r .p2c", [1.0, 1.0])
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_short_cut_methods
|
289
|
+
foorth_equal('10 1+' , [11])
|
290
|
+
foorth_equal('10 1-' , [9])
|
291
|
+
|
292
|
+
foorth_equal('10 2+' , [12])
|
293
|
+
foorth_equal('10 2-' , [8])
|
294
|
+
|
295
|
+
foorth_equal('10 2*' , [20])
|
296
|
+
foorth_equal('10 2/' , [5])
|
297
|
+
|
298
|
+
foorth_equal('10.0 1+' , [11.0])
|
299
|
+
foorth_equal('10.0 1-' , [9.0])
|
300
|
+
|
301
|
+
foorth_equal('10.0 2+' , [12.0])
|
302
|
+
foorth_equal('10.0 2-' , [8.0])
|
303
|
+
|
304
|
+
foorth_equal('10.0 2*' , [20.0])
|
305
|
+
foorth_equal('10.0 2/' , [5.0])
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_some_complex_conversions
|
309
|
+
foorth_equal('4 5 complex', [Complex(4,5)])
|
310
|
+
foorth_raises('"apple" 5 complex')
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_some_rounding
|
314
|
+
foorth_equal('2 pi .round_to', [3.14])
|
315
|
+
|
316
|
+
foorth_raises('2 "apple" .round_to')
|
317
|
+
foorth_raises('"apple" pi .round_to')
|
318
|
+
end
|
319
|
+
|
320
|
+
|
321
|
+
end
|