skeem 0.1.03 → 0.2.00

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,63 @@
1
+ require_relative '../spec_helper' # Use the RSpec framework
2
+
3
+ require_relative '../../lib/skeem/interpreter'
4
+ require_relative '../../lib/skeem/skm_procedure_exec' # Load the class under test
5
+
6
+ module Skeem
7
+ describe SkmProcedureExec do
8
+ let(:interpreter) do
9
+ # We load the interpreter with the primitive procedures only
10
+ Interpreter.new { |interp| interp.add_primitives(interp.runtime) }
11
+ end
12
+
13
+ let(:square_source) do
14
+ source = <<-SKEEM
15
+ (define square
16
+ (lambda (x)
17
+ (* x x)))
18
+ square
19
+ SKEEM
20
+ source
21
+ end
22
+
23
+ let(:sample_lamb) do
24
+ result = interpreter.run(square_source)
25
+ result.last
26
+ end
27
+
28
+ let(:sample_call) do
29
+ result = interpreter.parse('(square 3)')
30
+ result.root
31
+ end
32
+
33
+ subject { SkmProcedureExec.new(sample_lamb) }
34
+
35
+ context 'Initialization:' do
36
+ it 'should be initialized with one lambda' do
37
+ expect { SkmProcedureExec.new(sample_lamb) }.not_to raise_error
38
+ end
39
+
40
+ it 'should know the definition of the procedure' do
41
+ expect(subject.definition).to eq(sample_lamb)
42
+ end
43
+ end # context
44
+
45
+ context 'Executing a compound procedure:' do
46
+ it 'should execute the procedure that is called' do
47
+ subject
48
+ call_args = sample_call.operands.to_a
49
+ result = subject.run!(interpreter.runtime, call_args)
50
+ expect(result).to eq(9)
51
+ end
52
+
53
+ it 'should execute the procedure with a procedure call in argument' do
54
+ subject
55
+
56
+ ptree = interpreter.parse('(square (+ (+ 2 1) 2))')
57
+ call_args = ptree.root.operands.to_a
58
+ result = subject.run!(interpreter.runtime, call_args)
59
+ expect(result).to eq(25)
60
+ end
61
+ end
62
+ end # describe
63
+ end # module
@@ -178,11 +178,10 @@ module Skeem
178
178
  end # context
179
179
 
180
180
  context 'Provided services:' do
181
- let(:sample_def) { SkmDefinition.new(nil, identifier('three'), integer(3)) }
182
- let(:runtime) { Runtime.new(Environment.new) }
181
+ let(:runtime) { Runtime.new(SkmFrame.new) }
183
182
 
184
183
  before(:each) do
185
- runtime.define('three', sample_def)
184
+ runtime.add_binding('three', integer(3))
186
185
  end
187
186
 
188
187
  it "should return the variable's value at evaluation" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skeem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.03
4
+ version: 0.2.00
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-15 00:00:00.000000000 Z
11
+ date: 2019-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley
@@ -95,11 +95,14 @@ files:
95
95
  - lib/skeem/runtime.rb
96
96
  - lib/skeem/s_expr_builder.rb
97
97
  - lib/skeem/s_expr_nodes.rb
98
+ - lib/skeem/skm_binding.rb
98
99
  - lib/skeem/skm_compound_datum.rb
99
100
  - lib/skeem/skm_element.rb
100
101
  - lib/skeem/skm_empty_list.rb
101
102
  - lib/skeem/skm_expression.rb
103
+ - lib/skeem/skm_frame.rb
102
104
  - lib/skeem/skm_pair.rb
105
+ - lib/skeem/skm_procedure_exec.rb
103
106
  - lib/skeem/skm_simple_datum.rb
104
107
  - lib/skeem/skm_unary_expression.rb
105
108
  - lib/skeem/standard/base.skm
@@ -110,6 +113,7 @@ files:
110
113
  - spec/skeem/element_visitor_spec.rb
111
114
  - spec/skeem/environment_spec.rb
112
115
  - spec/skeem/interpreter_spec.rb
116
+ - spec/skeem/lambda_spec.rb
113
117
  - spec/skeem/parser_spec.rb
114
118
  - spec/skeem/primitive/primitive_builder_spec.rb
115
119
  - spec/skeem/primitive/primitive_procedure_spec.rb
@@ -118,7 +122,9 @@ files:
118
122
  - spec/skeem/skm_compound_datum_spec.rb
119
123
  - spec/skeem/skm_element_spec.rb
120
124
  - spec/skeem/skm_empty_list_spec.rb
125
+ - spec/skeem/skm_frame_spec.rb
121
126
  - spec/skeem/skm_pair_spec.rb
127
+ - spec/skeem/skm_procedure_exec_spec.rb
122
128
  - spec/skeem/skm_simple_datum_spec.rb
123
129
  - spec/skeem/skm_unary_expression_spec.rb
124
130
  - spec/skeem/tokenizer_spec.rb
@@ -154,6 +160,7 @@ test_files:
154
160
  - spec/skeem/element_visitor_spec.rb
155
161
  - spec/skeem/environment_spec.rb
156
162
  - spec/skeem/interpreter_spec.rb
163
+ - spec/skeem/lambda_spec.rb
157
164
  - spec/skeem/parser_spec.rb
158
165
  - spec/skeem/primitive/primitive_builder_spec.rb
159
166
  - spec/skeem/primitive/primitive_procedure_spec.rb
@@ -161,7 +168,9 @@ test_files:
161
168
  - spec/skeem/skm_compound_datum_spec.rb
162
169
  - spec/skeem/skm_element_spec.rb
163
170
  - spec/skeem/skm_empty_list_spec.rb
171
+ - spec/skeem/skm_frame_spec.rb
164
172
  - spec/skeem/skm_pair_spec.rb
173
+ - spec/skeem/skm_procedure_exec_spec.rb
165
174
  - spec/skeem/skm_simple_datum_spec.rb
166
175
  - spec/skeem/skm_unary_expression_spec.rb
167
176
  - spec/skeem/s_expr_nodes_spec.rb