Решение на Бонус задача: ArnoldC+- от Михаил Здравков
Към профила на Михаил Здравков
Резултати
- 7 точки от тестове
- 0 бонус точки
- 7 точки общо
- 0 успешни тест(а)
- 0 неуспешни тест(а)
Код
Лог от изпълнението
Finished in 0.00096 seconds 2 examples, 1 failure /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:200:in `flatten': can't convert Class to Array (Class#to_ary gives Symbol) (TypeError) from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:200:in `full_description' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:76:in `store_computed' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:49:in `[]' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:123:in `full_description' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:76:in `store_computed' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/metadata.rb:49:in `[]' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:41:in `block (2 levels) in delegate_to_metadata' from /data/rails/evans-2016/releases/20161119130633/lib/language/ruby/json_formatter.rb:22:in `example_failed' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:130:in `block in notify' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:129:in `each' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:129:in `notify' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:92:in `example_failed' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:264:in `finish' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:231:in `fail_with_exception' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:523:in `block in fail_filtered_examples' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:523:in `each' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:523:in `fail_filtered_examples' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:501:in `rescue in run' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:506:in `run' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `block (2 levels) in run' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `map' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `block in run' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:58:in `report' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:21:in `run' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:in `run' from /data/rails/evans-2016/shared/bundle/ruby/2.3.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'
История (2 версии и 3 коментара)
Михаил обнови решението на 29.12.2016 02:33 (преди почти 8 години)
Лог от изпълнението при ръчна проверка:
.........FFF.......F..FFF..F.
Failures:
1) ArnoldCPM supports basic recursion
Failure/Error: expect(printer).to receive(:print).with(value_to_be_printed).ordered
(Double "printer").print(2)
expected: 1 time with arguments: (2)
received: 0 times
# ./spec.rb:878:in `block in expect_execution'
2) ArnoldCPM can calculate fibonacci(20) recursively
Failure/Error: talk_to_the_hand _fibonacci_20
#<Double "printer"> received :print with unexpected arguments
expected: (6765)
got: (nil)
# ./solution.rb:30:in `block in talk_to_the_hand'
# ./solution.rb:231:in `with_value'
# ./solution.rb:29:in `talk_to_the_hand'
# ./spec.rb:755:in `block (3 levels) in <top (required)>'
# ./solution.rb:11:in `instance_eval'
# ./solution.rb:11:in `totally_recall'
# ./spec.rb:714:in `block (2 levels) in <top (required)>'
3) ArnoldCPM can use closures in very convoluted ways
Failure/Error: expect(printer).to receive(:print).with(value_to_be_printed).ordered
(Double "printer").print(9)
expected: 1 time with arguments: (9)
received: 0 times
# ./spec.rb:878:in `block in expect_execution'
4) ArnoldCPM has boolean arithmetic that given *or* returns truthy values if one of the operands is truthy
Failure/Error: talk_to_the_hand _result
(Double "printer").print(0)
expected: 0 times with arguments: (0)
received: 1 time with arguments: (0)
# ./solution.rb:30:in `block in talk_to_the_hand'
# ./solution.rb:231:in `with_value'
# ./solution.rb:29:in `talk_to_the_hand'
# ./spec.rb:206:in `block (4 levels) in <top (required)>'
# ./solution.rb:11:in `instance_eval'
# ./solution.rb:11:in `totally_recall'
# ./spec.rb:192:in `block (3 levels) in <top (required)>'
5) ArnoldCPM has boolean arithmetic that given *and* returns falsy values if either operand is falsy
Failure/Error: talk_to_the_hand _result
(Double "printer").print(1)
expected: 0 times with arguments: (1)
received: 1 time with arguments: (1)
# ./solution.rb:30:in `block in talk_to_the_hand'
# ./solution.rb:231:in `with_value'
# ./solution.rb:29:in `talk_to_the_hand'
# ./spec.rb:268:in `block (4 levels) in <top (required)>'
# ./solution.rb:11:in `instance_eval'
# ./solution.rb:11:in `totally_recall'
# ./spec.rb:261:in `block (3 levels) in <top (required)>'
6) ArnoldCPM has boolean arithmetic that given *and* between two truthy values returns the second one
Failure/Error: talk_to_the_hand _result
(Double "printer").print(11)
expected: 0 times with arguments: (11)
received: 1 time with arguments: (11)
# ./solution.rb:30:in `block in talk_to_the_hand'
# ./solution.rb:231:in `with_value'
# ./solution.rb:29:in `talk_to_the_hand'
# ./spec.rb:299:in `block (4 levels) in <top (required)>'
# ./solution.rb:11:in `instance_eval'
# ./solution.rb:11:in `totally_recall'
# ./spec.rb:292:in `block (3 levels) in <top (required)>'
7) ArnoldCPM has boolean arithmetic that has the same precedence of *or* and *and* operations
Failure/Error: talk_to_the_hand _result
(Double "printer").print(1)
expected: 0 times with arguments: (1)
received: 1 time with arguments: (1)
# ./solution.rb:30:in `block in talk_to_the_hand'
# ./solution.rb:231:in `with_value'
# ./solution.rb:29:in `talk_to_the_hand'
# ./spec.rb:317:in `block (4 levels) in <top (required)>'
# ./solution.rb:11:in `instance_eval'
# ./solution.rb:11:in `totally_recall'
# ./spec.rb:309:in `block (3 levels) in <top (required)>'
8) ArnoldCPM has branching mechanism that can nest if-else statements
Failure/Error: talk_to_the_hand 44
(Double "printer").print(44)
expected: 0 times with arguments: (44)
received: 1 time with arguments: (44)
# ./solution.rb:30:in `block in talk_to_the_hand'
# ./solution.rb:233:in `with_value'
# ./solution.rb:29:in `talk_to_the_hand'
# ./spec.rb:420:in `block (4 levels) in <top (required)>'
# ./solution.rb:11:in `instance_eval'
# ./solution.rb:11:in `totally_recall'
# ./spec.rb:408:in `block (3 levels) in <top (required)>'
Finished in 0.02961 seconds (files took 0.11884 seconds to load)
29 examples, 8 failures
Failed examples:
rspec ./spec.rb:651 # ArnoldCPM supports basic recursion
rspec ./spec.rb:695 # ArnoldCPM can calculate fibonacci(20) recursively
rspec ./spec.rb:760 # ArnoldCPM can use closures in very convoluted ways
rspec ./spec.rb:183 # ArnoldCPM has boolean arithmetic that given *or* returns truthy values if one of the operands is truthy
rspec ./spec.rb:252 # ArnoldCPM has boolean arithmetic that given *and* returns falsy values if either operand is falsy
rspec ./spec.rb:287 # ArnoldCPM has boolean arithmetic that given *and* between two truthy values returns the second one
rspec ./spec.rb:304 # ArnoldCPM has boolean arithmetic that has the same precedence of *or* and *and* operations
rspec ./spec.rb:378 # ArnoldCPM has branching mechanism that can nest if-else statements
Като цяло си в добра насока. Няколко забележки:
-
ArnoldCPM
държи контекст отвъдprinter
-a. Ако опитам да пусна две ArnoldC+- програми в отделни нишки например, нещата ще се омажат тотално. - Е ли отговорност на
Scope
да се грижи заdefining_function
иput_result_in_var
? - Вероятно и сам си забелязал, че постоянно се повтаря
return if handle_possible_func_def __method__, something
return if @suppress_execution
Идеята на нашето решение е сравнително подобна, може да погледнеш как сме се справили с това.
Мерси за коментарите. Май въобще не ми е хрумнало за пускането на 2 програми едновременно, просто реших, че ще има само един "интерпретатор" в дадено време. За повтарящите се return-и навсякъде: опитвах да се справя с този проблем като ползвам прок, който да прави това и навсякъде да го викам, но проблема беше, че като е дефиниран извън функцията прока, return-а му не работи както очаквах. Целия код е страшно омазан. Уж почнах доста по-рано с домашното, но все не можех да го накарам да работи и накрая писах до среднощ преди крайния срок. Преработвах кода сто пъти и почти се бях отказал, когато успях да оправя сериозните проблеми, но вече нямах сили да рефакторирам. Та така...