fOOrth 0.6.6 → 0.6.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CODE_OF_CONDUCT.md +49 -0
- data/README.md +32 -1
- data/fOOrth.gemspec +3 -3
- data/integration/array_lib_tests.rb +10 -0
- data/integration/compile_lib_tests.rb +67 -1
- data/integration/exception_lib_tests.rb +4 -0
- data/integration/hash_lib_tests.rb +9 -0
- data/integration/numeric_lib_tests.rb +326 -321
- data/integration/procedure_lib_tests.rb +16 -0
- data/integration/queue_lib_tests.rb +2 -1
- data/integration/stack_lib_tests.rb +2 -1
- data/integration/stdio_lib_tests.rb +62 -0
- data/integration/string_lib_tests.rb +11 -0
- data/integration/thread_lib_tests.rb +19 -5
- data/lib/fOOrth.rb +0 -2
- data/lib/fOOrth/compiler/context.rb +64 -64
- data/lib/fOOrth/compiler/context/locals.rb +34 -34
- data/lib/fOOrth/compiler/context/map_name.rb +85 -74
- data/lib/fOOrth/compiler/context/tags.rb +60 -48
- data/lib/fOOrth/compiler/process/generate.rb +1 -1
- data/lib/fOOrth/compiler/process/procedure.rb +40 -0
- data/lib/fOOrth/compiler/word_specs.rb +3 -3
- data/lib/fOOrth/core/object.rb +1 -1
- data/lib/fOOrth/library.rb +3 -0
- data/lib/fOOrth/library/alias_library.rb +126 -0
- data/lib/fOOrth/library/array_library.rb +41 -21
- data/lib/fOOrth/library/command_library.rb +1 -1
- data/lib/fOOrth/library/compile_library.rb +266 -264
- data/lib/fOOrth/library/complex_library.rb +82 -80
- data/lib/fOOrth/library/float_library.rb +37 -0
- data/lib/fOOrth/library/formatting/array.rb +90 -0
- data/lib/fOOrth/library/formatting/bullets.rb +15 -79
- data/lib/fOOrth/library/formatting/columns.rb +20 -42
- data/lib/fOOrth/library/formatting/hash.rb +29 -0
- data/lib/fOOrth/library/formatting/nil.rb +13 -0
- data/lib/fOOrth/library/formatting/object.rb +18 -0
- data/lib/fOOrth/library/formatting/string.rb +46 -0
- data/lib/fOOrth/library/hash_library.rb +14 -6
- data/lib/fOOrth/library/introspection/class.rb +20 -18
- data/lib/fOOrth/library/introspection/context.rb +3 -2
- data/lib/fOOrth/library/introspection/object.rb +42 -20
- data/lib/fOOrth/library/introspection/string.rb +21 -5
- data/lib/fOOrth/library/introspection/vm.rb +17 -29
- data/lib/fOOrth/library/mutex_library.rb +8 -1
- data/lib/fOOrth/library/numeric_library.rb +359 -380
- data/lib/fOOrth/library/procedure_library.rb +69 -65
- data/lib/fOOrth/library/queue_library.rb +6 -1
- data/lib/fOOrth/library/rational_library.rb +89 -89
- data/lib/fOOrth/library/stack_library.rb +6 -1
- data/lib/fOOrth/library/stdio_library.rb +11 -8
- data/lib/fOOrth/library/string_library.rb +21 -6
- data/lib/fOOrth/library/stubs_library.rb +49 -0
- data/lib/fOOrth/monkey_patch/exceptions.rb +2 -6
- data/lib/fOOrth/monkey_patch/object.rb +7 -0
- data/lib/fOOrth/version.rb +1 -1
- data/reek.txt +1 -59
- data/sire.rb +0 -1
- data/tests/compiler/context_tests.rb +188 -177
- data/tests/compiler/file_source_tests.rb +130 -130
- data/tests/compiler/parser_tests.rb +4 -4
- data/tests/compiler/string_source_tests.rb +4 -4
- data/tests/core_tests.rb +138 -138
- data/tests/monkey_patch/complex_test.rb +24 -24
- data/tests/monkey_patch/object_test.rb +49 -49
- data/tests/monkey_patch/string_test.rb +61 -61
- metadata +20 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ce6a84ad49645378ec632ed55e731ff89d113cf22de2517ebef69e87b1e6d01e
|
4
|
+
data.tar.gz: 610a2c6be6d202ca568fc8ff62d338f003fc5c19a63016975892820c0193c580
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e9bb940f04ac87128cf57a5f235ddc0ab8210f044be38de9a285312348ebd9a9d41a6732fa0e43b9c509ca7e315b43b0d2a41cde1ce480b8a4ed7170050c1b1
|
7
|
+
data.tar.gz: 594473cca8c187f4fe28aaee1f33ea2d7c713bed1d5a0ef68e5ed8167c3aee36e379311ea258a56c99002c49e1553b6cf9149b0fc498626fc6c474e8c3277108
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at peter.c.camilleri@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/README.md
CHANGED
@@ -67,7 +67,27 @@ currently only available in Open Office and PDF formats. The guide tracks
|
|
67
67
|
changes in the language fairly closely. The most current guide in PDF
|
68
68
|
format may be found at the community web site above.
|
69
69
|
|
70
|
-
This code repo also has PDF formatted guides for
|
70
|
+
This code repo also has PDF formatted guides for major revisions.
|
71
|
+
|
72
|
+
### If you get stuck.
|
73
|
+
|
74
|
+
The fOOrth language REPL has several commands inspired by the APL interpreter
|
75
|
+
of the old PDP-10 system I used so many years ago. The commands take the form
|
76
|
+
of )command. That's a right paren then the command name. Some useful ones
|
77
|
+
to know are:
|
78
|
+
|
79
|
+
)"shell command" -- execute the specified command in the shell.
|
80
|
+
)classes -- list the system classes.
|
81
|
+
)globals -- list any global variables.
|
82
|
+
)load"filename" -- load the fOOrth file called filename.
|
83
|
+
)irb -- launch an interactive irb debug session.
|
84
|
+
)quit -- exit fOOrth.
|
85
|
+
)time -- display the current time.
|
86
|
+
)show -- after each command show the contents of the data stack.
|
87
|
+
)noshow -- don't do that.
|
88
|
+
)version -- display current language version info.
|
89
|
+
)words -- list all defined method names.
|
90
|
+
|
71
91
|
|
72
92
|
## Contributing
|
73
93
|
|
@@ -89,3 +109,14 @@ http://nvie.com/posts/a-successful-git-branching-model/
|
|
89
109
|
|
90
110
|
Go to the GitHub repository and raise an issue calling attention to some
|
91
111
|
aspect that could use some TLC or a suggestion or an idea.
|
112
|
+
|
113
|
+
## License
|
114
|
+
|
115
|
+
The gem is available as open source under the terms of the
|
116
|
+
[MIT License](./LICENSE.txt).
|
117
|
+
|
118
|
+
## Code of Conduct
|
119
|
+
|
120
|
+
Everyone interacting in the fully_freeze project’s codebases, issue trackers,
|
121
|
+
chat rooms and mailing lists is expected to follow the
|
122
|
+
[code of conduct](./CODE_OF_CONDUCT.md).
|
data/fOOrth.gemspec
CHANGED
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.required_ruby_version = '>=1.9.3'
|
26
26
|
|
27
|
-
spec.add_development_dependency "bundler", "
|
28
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency "bundler", ">= 2.1.0"
|
28
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
29
29
|
spec.add_development_dependency 'reek', "~> 3.0"
|
30
30
|
spec.add_development_dependency 'minitest', "~> 5.7"
|
31
31
|
spec.add_development_dependency 'minitest_visible', ">= 0.1.1"
|
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_runtime_dependency 'full_clone'
|
37
37
|
spec.add_runtime_dependency 'safe_clone'
|
38
38
|
spec.add_runtime_dependency 'in_array'
|
39
|
-
spec.add_runtime_dependency 'mini_readline', ">= 0.
|
39
|
+
spec.add_runtime_dependency 'mini_readline', ">= 0.8.0"
|
40
40
|
end
|
@@ -359,4 +359,14 @@ class ArrayLibraryTester < Minitest::Test
|
|
359
359
|
foorth_equal('[ 2 4 6 8 ] .keys ', [[0,1,2,3]])
|
360
360
|
end
|
361
361
|
|
362
|
+
def test_array_emptiness
|
363
|
+
foorth_equal('[ ] .empty?', [true])
|
364
|
+
foorth_equal('[ 1 ] .empty?', [false])
|
365
|
+
|
366
|
+
foorth_equal('[ ] .present?', [false])
|
367
|
+
foorth_equal('[ 1 ] .present?', [true])
|
368
|
+
|
369
|
+
foorth_equal('[ 1 ] dup .clear!', [[]])
|
370
|
+
end
|
371
|
+
|
362
372
|
end
|
@@ -112,7 +112,6 @@ class CompileLibraryTester < Minitest::Test
|
|
112
112
|
|
113
113
|
foorth_equal('Object .: .lvt6 val: lv lv 10 * ;' , [])
|
114
114
|
foorth_equal('10 Object .new .lvt6 ' , [100])
|
115
|
-
|
116
115
|
end
|
117
116
|
|
118
117
|
def test_exclusive_methods
|
@@ -233,7 +232,74 @@ class CompileLibraryTester < Minitest::Test
|
|
233
232
|
|
234
233
|
foorth_equal("Integer .: minus self swap - ; 10 5 minus", [5])
|
235
234
|
foorth_equal("Integer '. .: rinus self swap - ; 10 5 rinus", [-5])
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_method_aliasing
|
238
|
+
foorth_run('class: TestAlias')
|
239
|
+
foorth_run('TestAlias .: .method_name 42 ;')
|
240
|
+
foorth_run('TestAlias .new val$: $test_aliasing_one')
|
241
|
+
foorth_run('TestAlias .new val$: $test_aliasing_two')
|
242
|
+
|
243
|
+
foorth_equal('$test_aliasing_one .method_name', [42])
|
244
|
+
foorth_raises('$test_aliasing_one .alias_name')
|
245
|
+
foorth_raises('$test_aliasing_one .with {{ ~other_name }}')
|
246
|
+
|
247
|
+
foorth_run('".method_name" TestAlias .alias: .alias_name')
|
248
|
+
|
249
|
+
foorth_equal('$test_aliasing_one .method_name', [42])
|
250
|
+
foorth_equal('$test_aliasing_one .alias_name', [42])
|
251
|
+
foorth_raises('$test_aliasing_one .with {{ ~other_name }}')
|
252
|
+
|
253
|
+
foorth_run('".method_name" TestAlias .alias: ~other_name')
|
254
|
+
|
255
|
+
foorth_equal('$test_aliasing_one .method_name', [42])
|
256
|
+
foorth_equal('$test_aliasing_one .alias_name', [42])
|
257
|
+
foorth_equal('$test_aliasing_one .with{{ ~other_name }}', [42])
|
258
|
+
|
259
|
+
foorth_raises('".method_name" TestAlias .alias: ++++')
|
260
|
+
|
261
|
+
foorth_run('$test_aliasing_two .:: .method_name 69 ;')
|
262
|
+
foorth_equal('$test_aliasing_one .method_name', [42])
|
263
|
+
foorth_equal('$test_aliasing_two .method_name', [69])
|
264
|
+
|
265
|
+
foorth_run('".method_name" $test_aliasing_two .alias:: .crazy')
|
266
|
+
foorth_equal('$test_aliasing_two .crazy', [69])
|
267
|
+
foorth_raises('$test_aliasing_one .crazy')
|
268
|
+
|
269
|
+
foorth_raises('"+" Numeric .alias: .add')
|
270
|
+
foorth_run('"-" Numeric \'* .alias: .sub')
|
271
|
+
foorth_equal('11 4 .sub', [7])
|
236
272
|
|
273
|
+
foorth_run('"dup" alias: doop')
|
274
|
+
foorth_equal('11 doop', [11, 11])
|
237
275
|
end
|
238
276
|
|
277
|
+
def test_method_stubs
|
278
|
+
foorth_run('class: TestStubs')
|
279
|
+
foorth_equal('TestStubs .new .to_i', [nil])
|
280
|
+
|
281
|
+
foorth_run('TestStubs .stub: .to_i')
|
282
|
+
foorth_raises('TestStubs .new .to_i')
|
283
|
+
|
284
|
+
foorth_run('TestStubs .new val$: $test_stubs_one')
|
285
|
+
foorth_run('TestStubs .new val$: $test_stubs_two')
|
286
|
+
|
287
|
+
foorth_run('$test_stubs_two .stub:: .to_r')
|
288
|
+
|
289
|
+
foorth_equal('$test_stubs_one .to_r', [nil])
|
290
|
+
foorth_raises('$test_stubs_two .to_r')
|
291
|
+
|
292
|
+
foorth_run('"dup" alias: dupe')
|
293
|
+
foorth_equal('3 dup ', [3,3])
|
294
|
+
foorth_equal('3 dupe', [3,3])
|
295
|
+
|
296
|
+
foorth_run('stub: dup')
|
297
|
+
|
298
|
+
foorth_raises('3 dup ')
|
299
|
+
foorth_equal('3 dupe', [3,3])
|
300
|
+
|
301
|
+
foorth_run('"dupe" alias: dup')
|
302
|
+
end
|
303
|
+
|
304
|
+
|
239
305
|
end
|
@@ -116,5 +116,14 @@ class HashLibraryTester < Minitest::Test
|
|
116
116
|
foorth_equal('{ 0 2 -> 1 4 -> 2 6 -> 3 8 -> } .select{{ v 2/ 1 and 0= }}', [{1=>4, 3=>8}])
|
117
117
|
end
|
118
118
|
|
119
|
+
def test_hash_emptiness
|
120
|
+
foorth_equal('{ } .empty?', [true])
|
121
|
+
foorth_equal('{ 1 "a" -> } .empty?', [false])
|
122
|
+
|
123
|
+
foorth_equal('{ } .present?', [false])
|
124
|
+
foorth_equal('{ 1 "a" -> } .present?', [true])
|
125
|
+
|
126
|
+
foorth_equal('{ 1 "a" -> } dup .clear!', [{}])
|
127
|
+
end
|
119
128
|
|
120
129
|
end
|
@@ -1,321 +1,326 @@
|
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
foorth_equal("5 3
|
158
|
-
foorth_equal("
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
foorth_equal("
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
foorth_equal("
|
170
|
-
|
171
|
-
|
172
|
-
foorth_equal("
|
173
|
-
|
174
|
-
foorth_equal("
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
foorth_raises('1+1i .
|
182
|
-
foorth_raises('1+1i
|
183
|
-
foorth_raises('1
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
foorth_equal("
|
193
|
-
foorth_equal("0 .
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
foorth_raises('1+1i .
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
foorth_equal("
|
210
|
-
|
211
|
-
foorth_equal("
|
212
|
-
|
213
|
-
|
214
|
-
foorth_equal("
|
215
|
-
|
216
|
-
foorth_equal("
|
217
|
-
foorth_equal("
|
218
|
-
|
219
|
-
foorth_equal("
|
220
|
-
|
221
|
-
foorth_equal("
|
222
|
-
foorth_equal("
|
223
|
-
|
224
|
-
foorth_equal("
|
225
|
-
|
226
|
-
|
227
|
-
foorth_equal("
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
foorth_equal("
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
foorth_equal("
|
237
|
-
foorth_equal("
|
238
|
-
|
239
|
-
foorth_equal("100 .
|
240
|
-
foorth_equal("101 .
|
241
|
-
foorth_equal("16666600 .
|
242
|
-
foorth_equal("16666601 .
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
foorth_equal("
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
foorth_equal(
|
253
|
-
|
254
|
-
|
255
|
-
foorth_equal("1
|
256
|
-
foorth_equal("3.1 4 rational
|
257
|
-
foorth_equal('
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
foorth_equal('0.
|
271
|
-
|
272
|
-
foorth_equal('0.
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
end
|
282
|
-
|
283
|
-
def
|
284
|
-
foorth_equal("1
|
285
|
-
|
286
|
-
end
|
287
|
-
|
288
|
-
def
|
289
|
-
foorth_equal(
|
290
|
-
foorth_equal(
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
foorth_equal('10
|
296
|
-
|
297
|
-
|
298
|
-
foorth_equal('10
|
299
|
-
|
300
|
-
|
301
|
-
foorth_equal('10
|
302
|
-
|
303
|
-
|
304
|
-
foorth_equal('10.0
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
foorth_equal('
|
310
|
-
|
311
|
-
end
|
312
|
-
|
313
|
-
def
|
314
|
-
foorth_equal('
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
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
|
+
foorth_equal(' 0.1 .numerator', [1])
|
150
|
+
foorth_equal(' 0.1 .denominator', [10])
|
151
|
+
|
152
|
+
foorth_raises(' 1+1i .numerator')
|
153
|
+
foorth_raises(' 1+1i .denominator')
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_some_bitwise_ops
|
157
|
+
foorth_equal("5 3 and", [1])
|
158
|
+
foorth_equal("5 3 or", [7])
|
159
|
+
foorth_equal("5 3 xor", [6])
|
160
|
+
foorth_equal("5 com", [-6])
|
161
|
+
|
162
|
+
foorth_equal("5 3 <<", [40])
|
163
|
+
foorth_equal("40 3 >>", [5])
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_some_trig
|
168
|
+
foorth_equal("pi", [Math::PI])
|
169
|
+
foorth_equal("e", [Math::E])
|
170
|
+
foorth_equal("dpr", [XfOOrth::DegreesPerRadian])
|
171
|
+
|
172
|
+
foorth_equal("45 .d2r dup .sin dup * swap .cos dup * + ", [1.0])
|
173
|
+
|
174
|
+
foorth_equal("0 .tan ", [0.0])
|
175
|
+
|
176
|
+
foorth_equal("1 .asin .r2d", [90.0])
|
177
|
+
foorth_equal("1 .acos .r2d", [ 0.0])
|
178
|
+
foorth_equal("1 .atan .r2d", [45.0])
|
179
|
+
foorth_equal("1 1 .atan2 .r2d", [45.0])
|
180
|
+
|
181
|
+
foorth_raises('1+1i .sin')
|
182
|
+
foorth_raises('1+1i .cos')
|
183
|
+
foorth_raises('1+1i .tan')
|
184
|
+
foorth_raises('1+1i .asin')
|
185
|
+
foorth_raises('1+1i .acos')
|
186
|
+
foorth_raises('1+1i .atan')
|
187
|
+
foorth_raises('1+1i 3 .atan2')
|
188
|
+
foorth_raises('1 1+1i .atan2')
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_some_exagerated_trig
|
192
|
+
foorth_equal("0 .sinh ", [0.0])
|
193
|
+
foorth_equal("0 .cosh ", [1.0])
|
194
|
+
foorth_equal("0 .tanh ", [0.0])
|
195
|
+
|
196
|
+
foorth_equal("0 .asinh ", [0.0])
|
197
|
+
foorth_equal("1 .acosh ", [0.0])
|
198
|
+
foorth_equal("0 .atanh ", [0.0])
|
199
|
+
|
200
|
+
foorth_raises('1+1i .sinh')
|
201
|
+
foorth_raises('1+1i .cosh')
|
202
|
+
foorth_raises('1+1i .tanh')
|
203
|
+
foorth_raises('1+1i .asinh')
|
204
|
+
foorth_raises('1+1i .acosh')
|
205
|
+
foorth_raises('1+1i .atanh')
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_some_powers
|
209
|
+
foorth_equal("0 .e**", [1.0])
|
210
|
+
foorth_equal("1 .ln", [0.0])
|
211
|
+
foorth_equal("e .ln", [1.0])
|
212
|
+
|
213
|
+
foorth_equal("2 .10**", [100.0])
|
214
|
+
foorth_equal("100 .log10", [2.0])
|
215
|
+
|
216
|
+
foorth_equal("10 .2**", [1024.0])
|
217
|
+
foorth_equal("1024 .log2", [10.0])
|
218
|
+
|
219
|
+
foorth_equal("16 .sqr ", [256])
|
220
|
+
foorth_equal("16.0 .sqr ", [256.0])
|
221
|
+
foorth_equal("1+1i .sqr ", [Complex(0,2)])
|
222
|
+
foorth_equal("16 .cube", [4096])
|
223
|
+
foorth_equal("16.0 .cube", [4096.0])
|
224
|
+
foorth_equal("1+1i .cube", [Complex(-2,2)])
|
225
|
+
|
226
|
+
foorth_equal("1024 .sqrt", [32.0])
|
227
|
+
foorth_equal("0+1i .sqrt", [Complex(0.7071067811865476, 0.7071067811865475)])
|
228
|
+
|
229
|
+
foorth_equal("8 .cbrt", [ 2.0])
|
230
|
+
foorth_equal("64 .cbrt", [ 4.0])
|
231
|
+
|
232
|
+
foorth_equal("3 4 .hypot", [5.0])
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_some_integer_ops
|
236
|
+
foorth_equal("100 64 .gcd", [4])
|
237
|
+
foorth_equal("100 64 .lcm", [1600])
|
238
|
+
|
239
|
+
foorth_equal("100 .even?", [true])
|
240
|
+
foorth_equal("101 .even?", [false])
|
241
|
+
foorth_equal("16666600 .even?", [true])
|
242
|
+
foorth_equal("16666601 .even?", [false])
|
243
|
+
|
244
|
+
foorth_equal("100 .odd?", [false])
|
245
|
+
foorth_equal("101 .odd?", [true])
|
246
|
+
foorth_equal("16666600 .odd?", [false])
|
247
|
+
foorth_equal("16666601 .odd?", [true])
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_being_rational
|
252
|
+
foorth_equal("1/2 .split", [1, 2])
|
253
|
+
|
254
|
+
foorth_equal("1 2 rational", ['1/2'.to_r])
|
255
|
+
foorth_equal("3.1 4 rational", ['31/40'.to_r])
|
256
|
+
foorth_equal('"3.1" 4 rational', ['31/40'.to_r])
|
257
|
+
foorth_equal('pi 1 rational', ['245_850_922/78_256_779'.to_r])
|
258
|
+
foorth_equal('"apple" 4 rational', [nil])
|
259
|
+
|
260
|
+
foorth_equal("1 2 rational!", ['1/2'.to_r])
|
261
|
+
foorth_equal("3.1 4 rational!", ['31/40'.to_r])
|
262
|
+
foorth_equal('"3.1" 4 rational!', ['31/40'.to_r])
|
263
|
+
foorth_raises('"apple" 4 rational!')
|
264
|
+
foorth_raises('nil 4 rational!')
|
265
|
+
foorth_raises('false 4 rational!')
|
266
|
+
foorth_raises('true 4 rational!')
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_that_we_do_not_rationalize_too_much
|
270
|
+
foorth_equal('0.01 pi .rationalize_to', ['22/7'.to_r])
|
271
|
+
foorth_equal('0.001 pi .rationalize_to', ['201/64'.to_r])
|
272
|
+
foorth_equal('0.0001 pi .rationalize_to', ['333/106'.to_r])
|
273
|
+
foorth_equal('0.00001 pi .rationalize_to', ['355/113'.to_r])
|
274
|
+
foorth_equal('0.000001 pi .rationalize_to', ['355/113'.to_r])
|
275
|
+
foorth_equal('0.0000001 pi .rationalize_to', ['75948/24175'.to_r])
|
276
|
+
|
277
|
+
foorth_equal('0.01 1234/55 .rationalize_to', ['157/7'.to_r])
|
278
|
+
|
279
|
+
foorth_raises('0.01 1+5i .rationalize_to')
|
280
|
+
foorth_raises('0.01 "apple" .rationalize_to')
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_being_complex
|
284
|
+
foorth_equal("1 2 complex", [Complex(1,2)])
|
285
|
+
foorth_equal("1+2i .split", [1, 2])
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_the_polar_vortex
|
289
|
+
foorth_equal("1 1 .c2p .r2d", [Math::sqrt(2.0), 45.0])
|
290
|
+
#foorth_equal("2.0 .sqrt 45 .d2r .p2c", [1.0, 1.0])
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_short_cut_methods
|
294
|
+
foorth_equal('10 1+' , [11])
|
295
|
+
foorth_equal('10 1-' , [9])
|
296
|
+
|
297
|
+
foorth_equal('10 2+' , [12])
|
298
|
+
foorth_equal('10 2-' , [8])
|
299
|
+
|
300
|
+
foorth_equal('10 2*' , [20])
|
301
|
+
foorth_equal('10 2/' , [5])
|
302
|
+
|
303
|
+
foorth_equal('10.0 1+' , [11.0])
|
304
|
+
foorth_equal('10.0 1-' , [9.0])
|
305
|
+
|
306
|
+
foorth_equal('10.0 2+' , [12.0])
|
307
|
+
foorth_equal('10.0 2-' , [8.0])
|
308
|
+
|
309
|
+
foorth_equal('10.0 2*' , [20.0])
|
310
|
+
foorth_equal('10.0 2/' , [5.0])
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_some_complex_conversions
|
314
|
+
foorth_equal('4 5 complex', [Complex(4,5)])
|
315
|
+
foorth_raises('"apple" 5 complex')
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_some_rounding
|
319
|
+
foorth_equal('2 pi .round_to', [3.14])
|
320
|
+
|
321
|
+
foorth_raises('2 "apple" .round_to')
|
322
|
+
foorth_raises('"apple" pi .round_to')
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
end
|