rkoans 0.0.1 → 0.1.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/CURRICULUM.md +86 -0
- data/README.md +77 -0
- data/THIRD_PARTY_NOTICES.md +30 -0
- data/exercises/about-array-assignment/about_array_assignment.rb +45 -0
- data/exercises/about-array-assignment/brief.md +11 -0
- data/exercises/about-array-assignment/hint.md +11 -0
- data/exercises/about-arrays/about_arrays.rb +77 -0
- data/exercises/about-arrays/brief.md +16 -0
- data/exercises/about-arrays/hint.md +13 -0
- data/exercises/about-asserts/about_asserts.rb +22 -0
- data/exercises/about-asserts/brief.md +22 -0
- data/exercises/about-asserts/hint.md +10 -0
- data/exercises/about-blocks/about_blocks.rb +76 -0
- data/exercises/about-blocks/brief.md +44 -0
- data/exercises/about-blocks/hint.md +7 -0
- data/exercises/about-class-methods/about_class_methods.rb +105 -0
- data/exercises/about-class-methods/brief.md +73 -0
- data/exercises/about-class-methods/hint.md +8 -0
- data/exercises/about-classes/about_classes.rb +131 -0
- data/exercises/about-classes/brief.md +73 -0
- data/exercises/about-classes/hint.md +7 -0
- data/exercises/about-constants/about_constants.rb +49 -0
- data/exercises/about-constants/brief.md +51 -0
- data/exercises/about-constants/hint.md +7 -0
- data/exercises/about-control-statements/about_control_statements.rb +152 -0
- data/exercises/about-control-statements/brief.md +9 -0
- data/exercises/about-control-statements/hint.md +7 -0
- data/exercises/about-dice-project/about_dice_project.rb +27 -0
- data/exercises/about-dice-project/brief.md +12 -0
- data/exercises/about-dice-project/hint.md +5 -0
- data/exercises/about-exceptions/about_exceptions.rb +84 -0
- data/exercises/about-exceptions/brief.md +19 -0
- data/exercises/about-exceptions/hint.md +8 -0
- data/exercises/about-extra-credit/about_extra_credit.rb +117 -0
- data/exercises/about-extra-credit/brief.md +28 -0
- data/exercises/about-extra-credit/hint.md +5 -0
- data/exercises/about-hashes/about_hashes.rb +160 -0
- data/exercises/about-hashes/brief.md +9 -0
- data/exercises/about-hashes/hint.md +8 -0
- data/exercises/about-inheritance/about_inheritance.rb +63 -0
- data/exercises/about-inheritance/brief.md +50 -0
- data/exercises/about-inheritance/hint.md +8 -0
- data/exercises/about-iteration/about_iteration.rb +96 -0
- data/exercises/about-iteration/brief.md +26 -0
- data/exercises/about-iteration/hint.md +6 -0
- data/exercises/about-keyword-arguments/about_keyword_arguments.rb +56 -0
- data/exercises/about-keyword-arguments/brief.md +28 -0
- data/exercises/about-keyword-arguments/hint.md +7 -0
- data/exercises/about-message-passing/about_message_passing.rb +112 -0
- data/exercises/about-message-passing/brief.md +59 -0
- data/exercises/about-message-passing/hint.md +8 -0
- data/exercises/about-methods/about_methods.rb +104 -0
- data/exercises/about-methods/brief.md +55 -0
- data/exercises/about-methods/hint.md +8 -0
- data/exercises/about-modules/about_modules.rb +43 -0
- data/exercises/about-modules/brief.md +44 -0
- data/exercises/about-modules/hint.md +8 -0
- data/exercises/about-nil/about_nil.rb +29 -0
- data/exercises/about-nil/brief.md +12 -0
- data/exercises/about-nil/hint.md +11 -0
- data/exercises/about-objects/about_objects.rb +51 -0
- data/exercises/about-objects/brief.md +14 -0
- data/exercises/about-objects/hint.md +12 -0
- data/exercises/about-open-classes/about_open_classes.rb +38 -0
- data/exercises/about-open-classes/brief.md +34 -0
- data/exercises/about-open-classes/hint.md +7 -0
- data/exercises/about-pattern-matching/about_pattern_matching.rb +106 -0
- data/exercises/about-pattern-matching/brief.md +124 -0
- data/exercises/about-pattern-matching/hint.md +8 -0
- data/exercises/about-proxy-object-project/about_proxy_object_project.rb +43 -0
- data/exercises/about-proxy-object-project/brief.md +10 -0
- data/exercises/about-proxy-object-project/hint.md +5 -0
- data/exercises/about-regular-expressions/about_regular_expressions.rb +174 -0
- data/exercises/about-regular-expressions/brief.md +9 -0
- data/exercises/about-regular-expressions/hint.md +8 -0
- data/exercises/about-sandwich-code/about_sandwich_code.rb +58 -0
- data/exercises/about-sandwich-code/brief.md +14 -0
- data/exercises/about-sandwich-code/hint.md +5 -0
- data/exercises/about-scope/about_scope.rb +76 -0
- data/exercises/about-scope/brief.md +35 -0
- data/exercises/about-scope/hint.md +8 -0
- data/exercises/about-scoring-project/about_scoring_project.rb +16 -0
- data/exercises/about-scoring-project/brief.md +10 -0
- data/exercises/about-scoring-project/hint.md +5 -0
- data/exercises/about-strings/about_strings.rb +142 -0
- data/exercises/about-strings/brief.md +22 -0
- data/exercises/about-strings/hint.md +11 -0
- data/exercises/about-symbols/about_symbols.rb +53 -0
- data/exercises/about-symbols/brief.md +21 -0
- data/exercises/about-symbols/hint.md +12 -0
- data/exercises/about-to-str/about_to_str.rb +49 -0
- data/exercises/about-to-str/brief.md +37 -0
- data/exercises/about-to-str/hint.md +7 -0
- data/exercises/about-triangle-project/about_triangle_project.rb +15 -0
- data/exercises/about-triangle-project/brief.md +11 -0
- data/exercises/about-triangle-project/hint.md +5 -0
- data/exercises/about-triangle-project-two/about_triangle_project_two.rb +22 -0
- data/exercises/about-triangle-project-two/brief.md +10 -0
- data/exercises/about-triangle-project-two/hint.md +5 -0
- data/exercises/about-true-and-false/about_true_and_false.rb +26 -0
- data/exercises/about-true-and-false/brief.md +22 -0
- data/exercises/about-true-and-false/hint.md +7 -0
- data/exercises/blocks-and-methods/blocks_and_methods.rb +14 -0
- data/exercises/blocks-and-methods/brief.md +8 -0
- data/exercises/blocks-and-methods/hint.md +6 -0
- data/exercises/catalog.json +61 -0
- data/exercises/class-state/brief.md +8 -0
- data/exercises/class-state/class_state.rb +39 -0
- data/exercises/class-state/hint.md +5 -0
- data/exercises/closure-capture/brief.md +8 -0
- data/exercises/closure-capture/closure_capture.rb +21 -0
- data/exercises/closure-capture/hint.md +5 -0
- data/exercises/collection-basics/brief.md +8 -0
- data/exercises/collection-basics/collection_basics.rb +16 -0
- data/exercises/collection-basics/hint.md +6 -0
- data/exercises/constant-scope/brief.md +8 -0
- data/exercises/constant-scope/constant_scope.rb +18 -0
- data/exercises/constant-scope/hint.md +5 -0
- data/exercises/core-protocols/brief.md +8 -0
- data/exercises/core-protocols/core_protocols.rb +43 -0
- data/exercises/core-protocols/hint.md +5 -0
- data/exercises/delegation/brief.md +8 -0
- data/exercises/delegation/delegation.rb +20 -0
- data/exercises/delegation/hint.md +5 -0
- data/exercises/dynamic-methods/brief.md +8 -0
- data/exercises/dynamic-methods/dynamic_methods.rb +33 -0
- data/exercises/dynamic-methods/hint.md +5 -0
- data/exercises/exception-flow/brief.md +8 -0
- data/exercises/exception-flow/exception_flow.rb +27 -0
- data/exercises/exception-flow/hint.md +5 -0
- data/exercises/heredoc-layout/brief.md +14 -0
- data/exercises/heredoc-layout/heredoc_layout.rb +25 -0
- data/exercises/heredoc-layout/hint.md +9 -0
- data/exercises/keyword-forwarding/brief.md +8 -0
- data/exercises/keyword-forwarding/hint.md +5 -0
- data/exercises/keyword-forwarding/keyword_forwarding.rb +27 -0
- data/exercises/lazy-enumeration/brief.md +8 -0
- data/exercises/lazy-enumeration/hint.md +5 -0
- data/exercises/lazy-enumeration/lazy_enumeration.rb +16 -0
- data/exercises/literals-and-operators/brief.md +20 -0
- data/exercises/literals-and-operators/hint.md +5 -0
- data/exercises/literals-and-operators/literals_and_operators.rb +15 -0
- data/exercises/method-contracts/brief.md +8 -0
- data/exercises/method-contracts/hint.md +5 -0
- data/exercises/method-contracts/method_contracts.rb +22 -0
- data/exercises/method-lookup/brief.md +8 -0
- data/exercises/method-lookup/hint.md +5 -0
- data/exercises/method-lookup/method_lookup.rb +26 -0
- data/exercises/nonlocal-exit/brief.md +8 -0
- data/exercises/nonlocal-exit/hint.md +5 -0
- data/exercises/nonlocal-exit/nonlocal_exit.rb +29 -0
- data/exercises/numbered-parameters/brief.md +18 -0
- data/exercises/numbered-parameters/hint.md +5 -0
- data/exercises/numbered-parameters/numbered_parameters.rb +18 -0
- data/exercises/numeric-precision/brief.md +8 -0
- data/exercises/numeric-precision/hint.md +5 -0
- data/exercises/numeric-precision/numeric_precision.rb +17 -0
- data/exercises/pattern-matching/brief.md +8 -0
- data/exercises/pattern-matching/hint.md +5 -0
- data/exercises/pattern-matching/pattern_matching.rb +22 -0
- data/exercises/refinement-scope/brief.md +8 -0
- data/exercises/refinement-scope/hint.md +5 -0
- data/exercises/refinement-scope/refinement_scope.rb +33 -0
- data/exercises/regexp-captures/brief.md +8 -0
- data/exercises/regexp-captures/hint.md +5 -0
- data/exercises/regexp-captures/regexp_captures.rb +25 -0
- data/exercises/runtime-context/brief.md +20 -0
- data/exercises/runtime-context/hint.md +8 -0
- data/exercises/runtime-context/runtime_context.rb +11 -0
- data/exercises/shared-rows/brief.md +8 -0
- data/exercises/shared-rows/hint.md +7 -0
- data/exercises/shared-rows/shared_rows.rb +13 -0
- data/exercises/singleton-pattern/brief.md +8 -0
- data/exercises/singleton-pattern/hint.md +5 -0
- data/exercises/singleton-pattern/singleton_pattern.rb +20 -0
- data/exercises/time-and-date/brief.md +8 -0
- data/exercises/time-and-date/hint.md +5 -0
- data/exercises/time-and-date/time_and_date.rb +21 -0
- data/exercises/visibility/brief.md +8 -0
- data/exercises/visibility/hint.md +5 -0
- data/exercises/visibility/visibility.rb +32 -0
- data/lib/rkoans/catalog.rb +31 -0
- data/lib/rkoans/checker.rb +62 -0
- data/lib/rkoans/cli.rb +79 -0
- data/lib/rkoans/error.rb +6 -0
- data/lib/rkoans/exercise.rb +50 -0
- data/lib/rkoans/keyboard.rb +51 -0
- data/lib/rkoans/progress.rb +39 -0
- data/lib/rkoans/selection.rb +31 -0
- data/lib/rkoans/session.rb +127 -0
- data/lib/rkoans/terminal_view.rb +99 -0
- data/lib/rkoans/version.rb +1 -1
- data/lib/rkoans/watcher.rb +58 -0
- data/lib/rkoans.rb +13 -3
- data/sig/about_array_assignment_acceptance_test.rbs +3 -0
- data/sig/about_arrays_acceptance_test.rbs +3 -0
- data/sig/about_asserts_command_test.rbs +4 -0
- data/sig/about_blocks_acceptance_test.rbs +3 -0
- data/sig/about_class_methods_acceptance_test.rbs +3 -0
- data/sig/about_classes_acceptance_test.rbs +3 -0
- data/sig/about_constants_acceptance_test.rbs +3 -0
- data/sig/about_control_statements_acceptance_test.rbs +3 -0
- data/sig/about_dice_project_acceptance_test.rbs +3 -0
- data/sig/about_exceptions_acceptance_test.rbs +3 -0
- data/sig/about_extra_credit_acceptance_test.rbs +5 -0
- data/sig/about_hashes_acceptance_test.rbs +3 -0
- data/sig/about_inheritance_acceptance_test.rbs +3 -0
- data/sig/about_iteration_acceptance_test.rbs +3 -0
- data/sig/about_keyword_arguments_acceptance_test.rbs +3 -0
- data/sig/about_message_passing_acceptance_test.rbs +3 -0
- data/sig/about_methods_acceptance_test.rbs +3 -0
- data/sig/about_modules_acceptance_test.rbs +3 -0
- data/sig/about_nil_acceptance_test.rbs +3 -0
- data/sig/about_objects_acceptance_test.rbs +3 -0
- data/sig/about_open_classes_acceptance_test.rbs +3 -0
- data/sig/about_pattern_matching_acceptance_test.rbs +3 -0
- data/sig/about_proxy_object_project_acceptance_test.rbs +3 -0
- data/sig/about_regular_expressions_acceptance_test.rbs +3 -0
- data/sig/about_sandwich_code_acceptance_test.rbs +3 -0
- data/sig/about_scope_acceptance_test.rbs +3 -0
- data/sig/about_scoring_project_acceptance_test.rbs +3 -0
- data/sig/about_strings_acceptance_test.rbs +3 -0
- data/sig/about_symbols_acceptance_test.rbs +3 -0
- data/sig/about_to_str_acceptance_test.rbs +3 -0
- data/sig/about_triangle_project_acceptance_test.rbs +3 -0
- data/sig/about_triangle_project_two_acceptance_test.rbs +3 -0
- data/sig/about_true_and_false_command_test.rbs +4 -0
- data/sig/catalog_error_command_test.rbs +4 -0
- data/sig/checker_test.rbs +9 -0
- data/sig/class_state_acceptance_test.rbs +3 -0
- data/sig/closure_capture_acceptance_test.rbs +3 -0
- data/sig/command_support.rbs +18 -0
- data/sig/command_test.rbs +5 -0
- data/sig/constant_scope_acceptance_test.rbs +3 -0
- data/sig/core_protocols_acceptance_test.rbs +3 -0
- data/sig/curriculum_cop_test.rbs +9 -0
- data/sig/delegation_acceptance_test.rbs +3 -0
- data/sig/dynamic_methods_acceptance_test.rbs +3 -0
- data/sig/exception_flow_acceptance_test.rbs +3 -0
- data/sig/exercise_test.rbs +3 -0
- data/sig/exercises/about_array_assignment.rbs +36 -0
- data/sig/exercises/about_arrays.rbs +51 -0
- data/sig/exercises/about_asserts.rbs +23 -0
- data/sig/exercises/about_blocks.rbs +40 -0
- data/sig/exercises/about_class_methods.rbs +62 -0
- data/sig/exercises/about_classes.rbs +88 -0
- data/sig/exercises/about_constants.rbs +53 -0
- data/sig/exercises/about_control_statements.rbs +46 -0
- data/sig/exercises/about_dice_project.rbs +16 -0
- data/sig/exercises/about_exceptions.rbs +36 -0
- data/sig/exercises/about_extra_credit.rbs +36 -0
- data/sig/exercises/about_hashes.rbs +62 -0
- data/sig/exercises/about_inheritance.rbs +50 -0
- data/sig/exercises/about_iteration.rbs +37 -0
- data/sig/exercises/about_keyword_arguments.rbs +33 -0
- data/sig/exercises/about_message_passing.rbs +68 -0
- data/sig/exercises/about_methods.rbs +68 -0
- data/sig/exercises/about_modules.rbs +38 -0
- data/sig/exercises/about_nil.rbs +23 -0
- data/sig/exercises/about_objects.rbs +38 -0
- data/sig/exercises/about_open_classes.rbs +31 -0
- data/sig/exercises/about_pattern_matching.rbs +65 -0
- data/sig/exercises/about_proxy_object_project.rbs +31 -0
- data/sig/exercises/about_regular_expressions.rbs +83 -0
- data/sig/exercises/about_sandwich_code.rbs +17 -0
- data/sig/exercises/about_scope.rbs +59 -0
- data/sig/exercises/about_scoring_project.rbs +16 -0
- data/sig/exercises/about_strings.rbs +85 -0
- data/sig/exercises/about_symbols.rbs +46 -0
- data/sig/exercises/about_to_str.rbs +36 -0
- data/sig/exercises/about_triangle_project.rbs +11 -0
- data/sig/exercises/about_triangle_project_two.rbs +12 -0
- data/sig/exercises/about_true_and_false.rbs +27 -0
- data/sig/exercises/blocks_and_methods.rbs +11 -0
- data/sig/exercises/class_state.rbs +19 -0
- data/sig/exercises/closure_capture.rbs +10 -0
- data/sig/exercises/collection_basics.rbs +6 -0
- data/sig/exercises/collection_basics_test.rbs +4 -0
- data/sig/exercises/constant_scope.rbs +11 -0
- data/sig/exercises/core_protocols.rbs +20 -0
- data/sig/exercises/delegation.rbs +14 -0
- data/sig/exercises/dynamic_methods.rbs +13 -0
- data/sig/exercises/exception_flow.rbs +11 -0
- data/sig/exercises/heredoc_layout.rbs +11 -0
- data/sig/exercises/keyword_forwarding.rbs +12 -0
- data/sig/exercises/lazy_enumeration.rbs +10 -0
- data/sig/exercises/literals_and_operators.rbs +12 -0
- data/sig/exercises/method_contracts.rbs +11 -0
- data/sig/exercises/method_lookup.rbs +16 -0
- data/sig/exercises/nonlocal_exit.rbs +14 -0
- data/sig/exercises/numbered_parameters.rbs +11 -0
- data/sig/exercises/numeric_precision.rbs +11 -0
- data/sig/exercises/pattern_matching.rbs +10 -0
- data/sig/exercises/refinement_scope.rbs +18 -0
- data/sig/exercises/regexp_captures.rbs +11 -0
- data/sig/exercises/runtime_context.rbs +23 -0
- data/sig/exercises/shared_rows.rbs +11 -0
- data/sig/exercises/singleton_pattern.rbs +14 -0
- data/sig/exercises/time_and_date.rbs +11 -0
- data/sig/exercises/visibility.rbs +18 -0
- data/sig/fixture_support.rbs +11 -0
- data/sig/help_hint_command_test.rbs +8 -0
- data/sig/heredoc_layout_acceptance_test.rbs +3 -0
- data/sig/keyboard_session_test.rbs +9 -0
- data/sig/keyword_forwarding_acceptance_test.rbs +3 -0
- data/sig/lazy_enumeration_acceptance_test.rbs +3 -0
- data/sig/literals_and_operators_acceptance_test.rbs +3 -0
- data/sig/method_contracts_acceptance_test.rbs +3 -0
- data/sig/method_lookup_acceptance_test.rbs +3 -0
- data/sig/nonlocal_exit_acceptance_test.rbs +3 -0
- data/sig/numbered_parameters_acceptance_test.rbs +3 -0
- data/sig/numeric_precision_acceptance_test.rbs +4 -0
- data/sig/packaging_test.rbs +3 -0
- data/sig/pattern_matching_acceptance_test.rbs +3 -0
- data/sig/reference_solutions_test.rbs +3 -0
- data/sig/refinement_scope_acceptance_test.rbs +3 -0
- data/sig/regexp_captures_acceptance_test.rbs +4 -0
- data/sig/rkoans/catalog.rbs +11 -0
- data/sig/rkoans/checker.rbs +22 -0
- data/sig/rkoans/cli.rbs +21 -0
- data/sig/rkoans/exercise.rbs +18 -0
- data/sig/rkoans/keyboard.rbs +13 -0
- data/sig/rkoans/progress.rbs +9 -0
- data/sig/rkoans/selection.rbs +9 -0
- data/sig/rkoans/session.rbs +30 -0
- data/sig/rkoans/terminal_view.rbs +24 -0
- data/sig/rkoans/watcher.rbs +18 -0
- data/sig/rkoans.rbs +2 -0
- data/sig/runtime_context_command_test.rbs +4 -0
- data/sig/selection_command_test.rbs +5 -0
- data/sig/session_command_test.rbs +12 -0
- data/sig/session_edge_cases_test.rbs +4 -0
- data/sig/shared_rows_acceptance_test.rbs +3 -0
- data/sig/singleton_pattern_acceptance_test.rbs +3 -0
- data/sig/time_and_date_acceptance_test.rbs +4 -0
- data/sig/visibility_acceptance_test.rbs +4 -0
- data/sig/watcher_test.rbs +3 -0
- data/solutions/about-array-assignment/about_array_assignment.rb +36 -0
- data/solutions/about-arrays/about_arrays.rb +53 -0
- data/solutions/about-asserts/about_asserts.rb +22 -0
- data/solutions/about-blocks/about_blocks.rb +30 -0
- data/solutions/about-class-methods/about_class_methods.rb +36 -0
- data/solutions/about-classes/about_classes.rb +40 -0
- data/solutions/about-constants/about_constants.rb +26 -0
- data/solutions/about-control-statements/about_control_statements.rb +35 -0
- data/solutions/about-dice-project/about_dice_project.rb +27 -0
- data/solutions/about-exceptions/about_exceptions.rb +30 -0
- data/solutions/about-extra-credit/about_extra_credit.rb +114 -0
- data/solutions/about-hashes/about_hashes.rb +52 -0
- data/solutions/about-inheritance/about_inheritance.rb +27 -0
- data/solutions/about-iteration/about_iteration.rb +31 -0
- data/solutions/about-keyword-arguments/about_keyword_arguments.rb +28 -0
- data/solutions/about-message-passing/about_message_passing.rb +38 -0
- data/solutions/about-methods/about_methods.rb +39 -0
- data/solutions/about-modules/about_modules.rb +23 -0
- data/solutions/about-nil/about_nil.rb +23 -0
- data/solutions/about-objects/about_objects.rb +34 -0
- data/solutions/about-open-classes/about_open_classes.rb +23 -0
- data/solutions/about-pattern-matching/about_pattern_matching.rb +39 -0
- data/solutions/about-proxy-object-project/about_proxy_object_project.rb +44 -0
- data/solutions/about-regular-expressions/about_regular_expressions.rb +60 -0
- data/solutions/about-sandwich-code/about_sandwich_code.rb +60 -0
- data/solutions/about-scope/about_scope.rb +33 -0
- data/solutions/about-scoring-project/about_scoring_project.rb +19 -0
- data/solutions/about-strings/about_strings.rb +56 -0
- data/solutions/about-symbols/about_symbols.rb +35 -0
- data/solutions/about-to-str/about_to_str.rb +24 -0
- data/solutions/about-triangle-project/about_triangle_project.rb +19 -0
- data/solutions/about-triangle-project-two/about_triangle_project_two.rb +25 -0
- data/solutions/about-true-and-false/about_true_and_false.rb +25 -0
- data/solutions/blocks-and-methods/blocks_and_methods.rb +14 -0
- data/solutions/class-state/class_state.rb +33 -0
- data/solutions/closure-capture/closure_capture.rb +12 -0
- data/solutions/collection-basics/collection_basics.rb +14 -0
- data/solutions/constant-scope/constant_scope.rb +18 -0
- data/solutions/core-protocols/core_protocols.rb +44 -0
- data/solutions/delegation/delegation.rb +17 -0
- data/solutions/dynamic-methods/dynamic_methods.rb +32 -0
- data/solutions/exception-flow/exception_flow.rb +34 -0
- data/solutions/heredoc-layout/heredoc_layout.rb +24 -0
- data/solutions/keyword-forwarding/keyword_forwarding.rb +26 -0
- data/solutions/lazy-enumeration/lazy_enumeration.rb +11 -0
- data/solutions/literals-and-operators/literals_and_operators.rb +22 -0
- data/solutions/method-contracts/method_contracts.rb +18 -0
- data/solutions/method-lookup/method_lookup.rb +26 -0
- data/solutions/nonlocal-exit/nonlocal_exit.rb +46 -0
- data/solutions/numbered-parameters/numbered_parameters.rb +18 -0
- data/solutions/numeric-precision/numeric_precision.rb +17 -0
- data/solutions/pattern-matching/pattern_matching.rb +17 -0
- data/solutions/refinement-scope/refinement_scope.rb +34 -0
- data/solutions/regexp-captures/regexp_captures.rb +24 -0
- data/solutions/runtime-context/runtime_context.rb +19 -0
- data/solutions/shared-rows/shared_rows.rb +13 -0
- data/solutions/singleton-pattern/singleton_pattern.rb +19 -0
- data/solutions/time-and-date/time_and_date.rb +16 -0
- data/solutions/visibility/visibility.rb +34 -0
- data/test/exercises/about_array_assignment_test.rb +87 -0
- data/test/exercises/about_arrays_test.rb +119 -0
- data/test/exercises/about_asserts_test.rb +41 -0
- data/test/exercises/about_blocks_test.rb +140 -0
- data/test/exercises/about_class_methods_test.rb +232 -0
- data/test/exercises/about_classes_test.rb +261 -0
- data/test/exercises/about_constants_test.rb +111 -0
- data/test/exercises/about_control_statements_test.rb +188 -0
- data/test/exercises/about_dice_project_test.rb +40 -0
- data/test/exercises/about_exceptions_test.rb +98 -0
- data/test/exercises/about_extra_credit_test.rb +74 -0
- data/test/exercises/about_hashes_test.rb +163 -0
- data/test/exercises/about_inheritance_test.rb +121 -0
- data/test/exercises/about_iteration_test.rb +148 -0
- data/test/exercises/about_keyword_arguments_test.rb +80 -0
- data/test/exercises/about_message_passing_test.rb +230 -0
- data/test/exercises/about_methods_test.rb +208 -0
- data/test/exercises/about_modules_test.rb +98 -0
- data/test/exercises/about_nil_test.rb +35 -0
- data/test/exercises/about_objects_test.rb +74 -0
- data/test/exercises/about_open_classes_test.rb +60 -0
- data/test/exercises/about_pattern_matching_test.rb +257 -0
- data/test/exercises/about_proxy_object_project_test.rb +75 -0
- data/test/exercises/about_regular_expressions_test.rb +243 -0
- data/test/exercises/about_sandwich_code_test.rb +82 -0
- data/test/exercises/about_scope_test.rb +123 -0
- data/test/exercises/about_scoring_project_test.rb +62 -0
- data/test/exercises/about_strings_test.rb +255 -0
- data/test/exercises/about_symbols_test.rb +120 -0
- data/test/exercises/about_to_str_test.rb +89 -0
- data/test/exercises/about_triangle_project_test.rb +29 -0
- data/test/exercises/about_triangle_project_two_test.rb +28 -0
- data/test/exercises/about_true_and_false_test.rb +43 -0
- data/test/exercises/blocks_and_methods_test.rb +22 -0
- data/test/exercises/class_state_test.rb +29 -0
- data/test/exercises/closure_capture_test.rb +29 -0
- data/test/exercises/collection_basics_test.rb +18 -0
- data/test/exercises/constant_scope_test.rb +18 -0
- data/test/exercises/core_protocols_test.rb +28 -0
- data/test/exercises/delegation_test.rb +23 -0
- data/test/exercises/dynamic_methods_test.rb +28 -0
- data/test/exercises/exception_flow_test.rb +17 -0
- data/test/exercises/heredoc_layout_test.rb +18 -0
- data/test/exercises/keyword_forwarding_test.rb +22 -0
- data/test/exercises/lazy_enumeration_test.rb +15 -0
- data/test/exercises/literals_and_operators_test.rb +25 -0
- data/test/exercises/method_contracts_test.rb +28 -0
- data/test/exercises/method_lookup_test.rb +14 -0
- data/test/exercises/nonlocal_exit_test.rb +22 -0
- data/test/exercises/numbered_parameters_test.rb +15 -0
- data/test/exercises/numeric_precision_test.rb +24 -0
- data/test/exercises/pattern_matching_test.rb +18 -0
- data/test/exercises/refinement_scope_test.rb +14 -0
- data/test/exercises/regexp_captures_test.rb +20 -0
- data/test/exercises/runtime_context_test.rb +59 -0
- data/test/exercises/shared_rows_test.rb +34 -0
- data/test/exercises/singleton_pattern_test.rb +16 -0
- data/test/exercises/time_and_date_test.rb +22 -0
- data/test/exercises/visibility_test.rb +22 -0
- metadata +471 -4
- data/Rakefile +0 -12
- data/sig/test_rkoans.rbs +0 -3
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The original descriptive check identifiers and example strings remain intact.
|
|
4
|
+
# An empty class demonstrates construction without custom methods.
|
|
5
|
+
# Conversions deliberately compare the same protocol on different built-in objects.
|
|
6
|
+
# Keep the related original chapter examples together.
|
|
7
|
+
# Explicit setters are compared with generated accessors in this chapter.
|
|
8
|
+
# The examples contrast block forms and their behavior.
|
|
9
|
+
# The fixed literal expression is an isolated binding or syntax experiment.
|
|
10
|
+
# Explicit getter definitions are compared with attr_reader and attr_accessor.
|
|
11
|
+
# rubocop:disable Layout/LineLength, Lint/EmptyClass, Lint/RedundantTypeConversion, Metrics/ClassLength, Naming/AccessorMethodName, Style/BlockDelimiters, Style/EvalWithLocation, Style/TrivialAccessors
|
|
12
|
+
|
|
13
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
14
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
15
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
16
|
+
|
|
17
|
+
require ARGV.shift
|
|
18
|
+
class AboutClassesTest < Minitest::Test
|
|
19
|
+
class Dog
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Checks instances of classes can be created with new.
|
|
23
|
+
def test_instances_of_classes_can_be_created_with_new
|
|
24
|
+
fido = Dog.new
|
|
25
|
+
|
|
26
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:instances_of_classes_can_be_created_with_new_one), fido.class
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# ------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
class Dog2
|
|
32
|
+
# Demonstrates set name.
|
|
33
|
+
def set_name(a_name)
|
|
34
|
+
@name = a_name
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Checks instance variables can be set by assigning to them.
|
|
39
|
+
def test_instance_variables_can_be_set_by_assigning_to_them
|
|
40
|
+
fido = Dog2.new
|
|
41
|
+
|
|
42
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:instance_variables_can_be_set_by_assigning_to_them_one),
|
|
43
|
+
fido.instance_variables
|
|
44
|
+
|
|
45
|
+
fido.set_name('Fido')
|
|
46
|
+
|
|
47
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:instance_variables_can_be_set_by_assigning_to_them_two),
|
|
48
|
+
fido.instance_variables
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Checks instance variables cannot be accessed outside the class.
|
|
52
|
+
def test_instance_variables_cannot_be_accessed_outside_the_class
|
|
53
|
+
fido = Dog2.new
|
|
54
|
+
fido.set_name('Fido')
|
|
55
|
+
|
|
56
|
+
assert_predicted_error(:instance_variables_cannot_be_accessed_outside_the_class_one, ::NoMethodError) do
|
|
57
|
+
fido.name
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
assert_predicted_error(:instance_variables_cannot_be_accessed_outside_the_class_two, ::SyntaxError) do
|
|
61
|
+
eval 'fido.@name'
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Checks you can politely ask for instance variable values.
|
|
66
|
+
def test_you_can_politely_ask_for_instance_variable_values
|
|
67
|
+
fido = Dog2.new
|
|
68
|
+
fido.set_name('Fido')
|
|
69
|
+
|
|
70
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:you_can_politely_ask_for_instance_variable_values_one),
|
|
71
|
+
fido.instance_variable_get('@name')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Checks you can rip the value out using instance eval.
|
|
75
|
+
def test_you_can_rip_the_value_out_using_instance_eval
|
|
76
|
+
fido = Dog2.new
|
|
77
|
+
fido.set_name('Fido')
|
|
78
|
+
|
|
79
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:you_can_rip_the_value_out_using_instance_eval_one), fido.instance_eval('@name') # string version
|
|
80
|
+
assert_equal(Exercises::AboutClasses.koans.fetch(:you_can_rip_the_value_out_using_instance_eval_two), fido.instance_eval {
|
|
81
|
+
@name
|
|
82
|
+
}) # block version
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# ------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
class Dog3
|
|
88
|
+
# Demonstrates set name.
|
|
89
|
+
def set_name(a_name)
|
|
90
|
+
@name = a_name
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Demonstrates name.
|
|
94
|
+
def name
|
|
95
|
+
@name
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Checks you can create accessor methods to return instance variables.
|
|
100
|
+
def test_you_can_create_accessor_methods_to_return_instance_variables
|
|
101
|
+
fido = Dog3.new
|
|
102
|
+
fido.set_name('Fido')
|
|
103
|
+
|
|
104
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:you_can_create_accessor_methods_to_return_instance_variables_one),
|
|
105
|
+
fido.name
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# ------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
class Dog4
|
|
111
|
+
attr_reader :name
|
|
112
|
+
|
|
113
|
+
# Demonstrates set name.
|
|
114
|
+
def set_name(a_name)
|
|
115
|
+
@name = a_name
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Checks attr reader will automatically define an accessor.
|
|
120
|
+
def test_attr_reader_will_automatically_define_an_accessor
|
|
121
|
+
fido = Dog4.new
|
|
122
|
+
fido.set_name('Fido')
|
|
123
|
+
|
|
124
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:attr_reader_will_automatically_define_an_accessor_one),
|
|
125
|
+
fido.name
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# ------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
class Dog5
|
|
131
|
+
attr_accessor :name
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Checks attr accessor will automatically define both read and write accessors.
|
|
135
|
+
def test_attr_accessor_will_automatically_define_both_read_and_write_accessors
|
|
136
|
+
fido = Dog5.new
|
|
137
|
+
|
|
138
|
+
fido.name = 'Fido'
|
|
139
|
+
|
|
140
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:attr_accessor_will_automatically_define_both_read_and_write_accessors_one),
|
|
141
|
+
fido.name
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# ------------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
class Dog6
|
|
147
|
+
attr_reader :name
|
|
148
|
+
|
|
149
|
+
# Demonstrates initialize.
|
|
150
|
+
def initialize(initial_name)
|
|
151
|
+
@name = initial_name
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Checks initialize provides initial values for instance variables.
|
|
156
|
+
def test_initialize_provides_initial_values_for_instance_variables
|
|
157
|
+
fido = Dog6.new('Fido')
|
|
158
|
+
|
|
159
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:initialize_provides_initial_values_for_instance_variables_one),
|
|
160
|
+
fido.name
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Checks args to new must match initialize.
|
|
164
|
+
def test_args_to_new_must_match_initialize
|
|
165
|
+
assert_predicted_error(:args_to_new_must_match_initialize_one, ::ArgumentError) do
|
|
166
|
+
Dog6.new
|
|
167
|
+
end
|
|
168
|
+
# THINK ABOUT IT:
|
|
169
|
+
# Why is this so?
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Checks different objects have different instance variables.
|
|
173
|
+
def test_different_objects_have_different_instance_variables
|
|
174
|
+
fido = Dog6.new('Fido')
|
|
175
|
+
rover = Dog6.new('Rover')
|
|
176
|
+
|
|
177
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:different_objects_have_different_instance_variables_one),
|
|
178
|
+
(rover.name != fido.name)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# ------------------------------------------------------------------
|
|
182
|
+
|
|
183
|
+
class Dog7
|
|
184
|
+
attr_reader :name
|
|
185
|
+
|
|
186
|
+
# Demonstrates initialize.
|
|
187
|
+
def initialize(initial_name)
|
|
188
|
+
@name = initial_name
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# Demonstrates get self.
|
|
192
|
+
def get_self
|
|
193
|
+
self
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Demonstrates to s.
|
|
197
|
+
def to_s
|
|
198
|
+
@name
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# Demonstrates inspect.
|
|
202
|
+
def inspect
|
|
203
|
+
"<Dog named '#{name}'>"
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Checks inside a method self refers to the containing object.
|
|
208
|
+
def test_inside_a_method_self_refers_to_the_containing_object
|
|
209
|
+
fido = Dog7.new('Fido')
|
|
210
|
+
|
|
211
|
+
fidos_self = fido.get_self
|
|
212
|
+
|
|
213
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:inside_a_method_self_refers_to_the_containing_object_one),
|
|
214
|
+
fidos_self.equal?(fido)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Checks to s provides a string version of the object.
|
|
218
|
+
def test_to_s_provides_a_string_version_of_the_object
|
|
219
|
+
fido = Dog7.new('Fido')
|
|
220
|
+
|
|
221
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:to_s_provides_a_string_version_of_the_object_one), fido.to_s
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Checks to s is used in string interpolation.
|
|
225
|
+
def test_to_s_is_used_in_string_interpolation
|
|
226
|
+
fido = Dog7.new('Fido')
|
|
227
|
+
|
|
228
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:to_s_is_used_in_string_interpolation_one), "My dog is #{fido}"
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# Checks inspect provides a more complete string version.
|
|
232
|
+
def test_inspect_provides_a_more_complete_string_version
|
|
233
|
+
fido = Dog7.new('Fido')
|
|
234
|
+
|
|
235
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:inspect_provides_a_more_complete_string_version_one),
|
|
236
|
+
fido.inspect
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Checks all objects support to s and inspect.
|
|
240
|
+
def test_all_objects_support_to_s_and_inspect
|
|
241
|
+
array = [1, 2, 3]
|
|
242
|
+
|
|
243
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:all_objects_support_to_s_and_inspect_one), array.to_s
|
|
244
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:all_objects_support_to_s_and_inspect_two), array.inspect
|
|
245
|
+
|
|
246
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:all_objects_support_to_s_and_inspect_three), 'STRING'.to_s
|
|
247
|
+
assert_equal Exercises::AboutClasses.koans.fetch(:all_objects_support_to_s_and_inspect_four), 'STRING'.inspect
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# Checks the predicted exception class while returning the captured error.
|
|
251
|
+
# @param key [Symbol] answer field
|
|
252
|
+
# @param klass [Class<Exception>] exception raised by the example
|
|
253
|
+
# @return [Exception]
|
|
254
|
+
def assert_predicted_error(key, ...)
|
|
255
|
+
error = assert_raises(...)
|
|
256
|
+
assert_equal Exercises::AboutClasses.koans.fetch(key), error.class
|
|
257
|
+
error
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# rubocop:enable Layout/LineLength, Lint/EmptyClass, Lint/RedundantTypeConversion, Metrics/ClassLength, Naming/AccessorMethodName, Style/BlockDelimiters, Style/EvalWithLocation, Style/TrivialAccessors
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The explicit class path changes lexical constant lookup.
|
|
4
|
+
# rubocop:disable Style/ClassAndModuleChildren
|
|
5
|
+
|
|
6
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
7
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
8
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
9
|
+
|
|
10
|
+
require ARGV.shift
|
|
11
|
+
C = 'top level'
|
|
12
|
+
|
|
13
|
+
class AboutConstantsTest < Minitest::Test
|
|
14
|
+
C = 'nested'
|
|
15
|
+
|
|
16
|
+
# Checks nested constants may also be referenced with relative paths.
|
|
17
|
+
def test_nested_constants_may_also_be_referenced_with_relative_paths
|
|
18
|
+
assert_equal Exercises::AboutConstants.koans.fetch(:nested_constants_may_also_be_referenced_with_relative_paths_one),
|
|
19
|
+
C
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Checks top level constants are referenced by double colons.
|
|
23
|
+
def test_top_level_constants_are_referenced_by_double_colons
|
|
24
|
+
assert_equal Exercises::AboutConstants.koans.fetch(:top_level_constants_are_referenced_by_double_colons_one), ::C
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Checks nested constants are referenced by their complete path.
|
|
28
|
+
def test_nested_constants_are_referenced_by_their_complete_path
|
|
29
|
+
assert_equal Exercises::AboutConstants.koans.fetch(:nested_constants_are_referenced_by_their_complete_path_one), AboutConstantsTest::C
|
|
30
|
+
assert_equal Exercises::AboutConstants.koans.fetch(:nested_constants_are_referenced_by_their_complete_path_two),
|
|
31
|
+
::AboutConstantsTest::C
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# ------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
class Animal
|
|
37
|
+
LEGS = 4
|
|
38
|
+
# Demonstrates legs in animal.
|
|
39
|
+
def legs_in_animal
|
|
40
|
+
LEGS
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class NestedAnimal
|
|
44
|
+
# Demonstrates legs in nested animal.
|
|
45
|
+
def legs_in_nested_animal
|
|
46
|
+
LEGS
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Checks nested classes inherit constants from enclosing classes.
|
|
52
|
+
def test_nested_classes_inherit_constants_from_enclosing_classes
|
|
53
|
+
assert_equal Exercises::AboutConstants.koans.fetch(:nested_classes_inherit_constants_from_enclosing_classes_one), Animal::NestedAnimal.new.legs_in_nested_animal
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# ------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
class Reptile < Animal
|
|
59
|
+
# Demonstrates legs in reptile.
|
|
60
|
+
def legs_in_reptile
|
|
61
|
+
LEGS
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Checks subclasses inherit constants from parent classes.
|
|
66
|
+
def test_subclasses_inherit_constants_from_parent_classes
|
|
67
|
+
assert_equal Exercises::AboutConstants.koans.fetch(:subclasses_inherit_constants_from_parent_classes_one),
|
|
68
|
+
Reptile.new.legs_in_reptile
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# ------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
class MyAnimals
|
|
74
|
+
LEGS = 2
|
|
75
|
+
|
|
76
|
+
class Bird < Animal
|
|
77
|
+
# Demonstrates legs in bird.
|
|
78
|
+
def legs_in_bird
|
|
79
|
+
LEGS
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Checks who wins with both nested and inherited constants.
|
|
85
|
+
def test_who_wins_with_both_nested_and_inherited_constants
|
|
86
|
+
assert_equal Exercises::AboutConstants.koans.fetch(:who_wins_with_both_nested_and_inherited_constants_one), MyAnimals::Bird.new.legs_in_bird
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# QUESTION: Which has precedence: The constant in the lexical scope,
|
|
90
|
+
# or the constant from the inheritance hierarchy?
|
|
91
|
+
|
|
92
|
+
# ------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
class MyAnimals::Oyster < Animal
|
|
95
|
+
# Demonstrates legs in oyster.
|
|
96
|
+
def legs_in_oyster
|
|
97
|
+
LEGS
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Checks who wins with explicit scoping on class definition.
|
|
102
|
+
def test_who_wins_with_explicit_scoping_on_class_definition
|
|
103
|
+
assert_equal Exercises::AboutConstants.koans.fetch(:who_wins_with_explicit_scoping_on_class_definition_one), MyAnimals::Oyster.new.legs_in_oyster
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# QUESTION: Now which has precedence: The constant in the lexical
|
|
107
|
+
# scope, or the constant from the inheritance hierarchy? Why is it
|
|
108
|
+
# different than the previous answer?
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# rubocop:enable Style/ClassAndModuleChildren
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Literal conditions isolate the control-flow behavior being predicted.
|
|
4
|
+
# Keep the related original chapter examples together.
|
|
5
|
+
# Separate conditional and assignment forms are deliberately contrasted.
|
|
6
|
+
# The example deliberately uses for rather than a block iterator.
|
|
7
|
+
# Full conditionals distinguish statement forms from modifiers.
|
|
8
|
+
# The example demonstrates break inside a while loop.
|
|
9
|
+
# rubocop:disable Lint/LiteralAsCondition, Metrics/ClassLength, Style/ConditionalAssignment, Style/For, Style/IfUnlessModifier, Style/InfiniteLoop
|
|
10
|
+
|
|
11
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
12
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
13
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
14
|
+
|
|
15
|
+
require ARGV.shift
|
|
16
|
+
class AboutControlStatementsTest < Minitest::Test
|
|
17
|
+
# Checks if then else statements.
|
|
18
|
+
def test_if_then_else_statements
|
|
19
|
+
if true
|
|
20
|
+
result = :true_value
|
|
21
|
+
else
|
|
22
|
+
result = :false_value
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:if_then_else_statements_one), result
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Checks if then statements.
|
|
29
|
+
def test_if_then_statements
|
|
30
|
+
result = :default_value
|
|
31
|
+
if true
|
|
32
|
+
result = :true_value
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:if_then_statements_one), result
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Checks if statements return values.
|
|
39
|
+
def test_if_statements_return_values
|
|
40
|
+
value = if true
|
|
41
|
+
:true_value
|
|
42
|
+
else
|
|
43
|
+
:false_value
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:if_statements_return_values_one), value
|
|
47
|
+
|
|
48
|
+
value = if false
|
|
49
|
+
:true_value
|
|
50
|
+
else
|
|
51
|
+
:false_value
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:if_statements_return_values_two), value
|
|
55
|
+
|
|
56
|
+
# NOTE: Actually, EVERY statement in Ruby will return a value, not
|
|
57
|
+
# just if statements.
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Checks if statements with no else with false condition return value.
|
|
61
|
+
def test_if_statements_with_no_else_with_false_condition_return_value
|
|
62
|
+
value = if false
|
|
63
|
+
:true_value
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:if_statements_with_no_else_with_false_condition_return_value_one),
|
|
67
|
+
value
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Checks condition operators.
|
|
71
|
+
def test_condition_operators
|
|
72
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:condition_operators_one),
|
|
73
|
+
((true ? :true_value : :false_value))
|
|
74
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:condition_operators_two),
|
|
75
|
+
((false ? :true_value : :false_value))
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Checks if statement modifiers.
|
|
79
|
+
def test_if_statement_modifiers
|
|
80
|
+
result = :default_value
|
|
81
|
+
result = :true_value if true
|
|
82
|
+
|
|
83
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:if_statement_modifiers_one), result
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Checks unless statement.
|
|
87
|
+
def test_unless_statement
|
|
88
|
+
result = :default_value
|
|
89
|
+
unless false # same as saying 'if !false', which evaluates as 'if true'
|
|
90
|
+
result = :false_value
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:unless_statement_one), result
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Checks unless statement evaluate true.
|
|
97
|
+
def test_unless_statement_evaluate_true
|
|
98
|
+
result = :default_value
|
|
99
|
+
unless true # same as saying 'if !true', which evaluates as 'if false'
|
|
100
|
+
result = :true_value
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:unless_statement_evaluate_true_one), result
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Checks unless statement modifier.
|
|
107
|
+
def test_unless_statement_modifier
|
|
108
|
+
result = :default_value
|
|
109
|
+
result = :false_value unless false
|
|
110
|
+
|
|
111
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:unless_statement_modifier_one), result
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Checks while statement.
|
|
115
|
+
def test_while_statement
|
|
116
|
+
i = 1
|
|
117
|
+
result = 1
|
|
118
|
+
while i <= 10
|
|
119
|
+
result *= i
|
|
120
|
+
i += 1
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:while_statement_one), result
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Checks break statement.
|
|
127
|
+
def test_break_statement
|
|
128
|
+
i = 1
|
|
129
|
+
result = 1
|
|
130
|
+
while true
|
|
131
|
+
break unless i <= 10
|
|
132
|
+
|
|
133
|
+
result *= i
|
|
134
|
+
i += 1
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:break_statement_one), result
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Checks break statement returns values.
|
|
141
|
+
def test_break_statement_returns_values
|
|
142
|
+
i = 1
|
|
143
|
+
result = while i <= 10
|
|
144
|
+
break i if i.even?
|
|
145
|
+
|
|
146
|
+
i += 1
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:break_statement_returns_values_one), result
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Checks next statement.
|
|
153
|
+
def test_next_statement
|
|
154
|
+
i = 0
|
|
155
|
+
result = []
|
|
156
|
+
while i < 10
|
|
157
|
+
i += 1
|
|
158
|
+
next if i.even?
|
|
159
|
+
|
|
160
|
+
result << i
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:next_statement_one), result
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Checks for statement.
|
|
167
|
+
def test_for_statement
|
|
168
|
+
array = %w[fish and chips]
|
|
169
|
+
result = []
|
|
170
|
+
for item in array
|
|
171
|
+
result << item.upcase
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:for_statement_one), result
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Checks times statement.
|
|
178
|
+
def test_times_statement
|
|
179
|
+
sum = 0
|
|
180
|
+
10.times do
|
|
181
|
+
sum += 1
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
assert_equal Exercises::AboutControlStatements.koans.fetch(:times_statement_one), sum
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# rubocop:enable Lint/LiteralAsCondition, Metrics/ClassLength, Style/ConditionalAssignment, Style/For, Style/IfUnlessModifier, Style/InfiniteLoop
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
require ARGV.shift
|
|
8
|
+
|
|
9
|
+
class AboutDiceProjectTest < Minitest::Test
|
|
10
|
+
# A new set is empty and can roll different counts without accumulating old dice.
|
|
11
|
+
def test_can_create_and_resize_a_dice_set
|
|
12
|
+
dice = Exercises::AboutDiceProject::DiceSet.new(random: Random.new(12))
|
|
13
|
+
|
|
14
|
+
assert_empty dice.values
|
|
15
|
+
[5, 3, 1, 0].each do |count|
|
|
16
|
+
dice.roll(count)
|
|
17
|
+
|
|
18
|
+
assert_equal count, dice.values.size
|
|
19
|
+
values = dice.values
|
|
20
|
+
values.each do |value|
|
|
21
|
+
assert_instance_of Integer, value
|
|
22
|
+
assert_includes 1..6, value
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Replaying a seeded source checks rerolling without assuming random rolls differ.
|
|
28
|
+
def test_rolls_use_the_random_source_and_values_stay_stable
|
|
29
|
+
dice = Exercises::AboutDiceProject::DiceSet.new(random: Random.new(12))
|
|
30
|
+
oracle = Random.new(12)
|
|
31
|
+
2.times do
|
|
32
|
+
expected = Array.new(5) { oracle.rand(1..6) }
|
|
33
|
+
dice.roll(5)
|
|
34
|
+
first_read = dice.values.dup
|
|
35
|
+
|
|
36
|
+
assert_equal expected, first_read
|
|
37
|
+
assert_equal first_read, dice.values
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Assignments before later reassignment or return are part of the experiment.
|
|
4
|
+
# Keep the original koan check name.
|
|
5
|
+
# This example deliberately raises an exception instance rather than a class and message pair.
|
|
6
|
+
# The examples demonstrate raise and fail as synonyms.
|
|
7
|
+
# rubocop:disable Lint/UselessAssignment, Naming/MethodName, Style/RaiseArgs, Style/SignalException
|
|
8
|
+
|
|
9
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
10
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
11
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
12
|
+
|
|
13
|
+
require ARGV.shift
|
|
14
|
+
class AboutExceptionsTest < Minitest::Test
|
|
15
|
+
class MySpecialError < RuntimeError
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Checks exceptions inherit from Exception.
|
|
19
|
+
def test_exceptions_inherit_from_Exception
|
|
20
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:exceptions_inherit_from_Exception_one),
|
|
21
|
+
MySpecialError.ancestors[1]
|
|
22
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:exceptions_inherit_from_Exception_two),
|
|
23
|
+
MySpecialError.ancestors[2]
|
|
24
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:exceptions_inherit_from_Exception_three),
|
|
25
|
+
MySpecialError.ancestors[3]
|
|
26
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:exceptions_inherit_from_Exception_four),
|
|
27
|
+
MySpecialError.ancestors[4]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Checks rescue clause.
|
|
31
|
+
def test_rescue_clause
|
|
32
|
+
result = nil
|
|
33
|
+
begin
|
|
34
|
+
fail 'Oops'
|
|
35
|
+
rescue StandardError => e
|
|
36
|
+
result = :exception_handled
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:rescue_clause_one), result
|
|
40
|
+
|
|
41
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:rescue_clause_two), e.is_a?(StandardError)
|
|
42
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:rescue_clause_three), e.is_a?(RuntimeError)
|
|
43
|
+
|
|
44
|
+
assert_includes RuntimeError.ancestors, StandardError,
|
|
45
|
+
'RuntimeError is a subclass of StandardError'
|
|
46
|
+
|
|
47
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:rescue_clause_four), e.message
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Checks raising a particular error.
|
|
51
|
+
def test_raising_a_particular_error
|
|
52
|
+
result = nil
|
|
53
|
+
begin
|
|
54
|
+
# 'raise' and 'fail' are synonyms
|
|
55
|
+
raise MySpecialError, 'My Message'
|
|
56
|
+
rescue MySpecialError => e
|
|
57
|
+
result = :exception_handled
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:raising_a_particular_error_one), result
|
|
61
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:raising_a_particular_error_two), e.message
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Checks ensure clause.
|
|
65
|
+
def test_ensure_clause
|
|
66
|
+
result = nil
|
|
67
|
+
begin
|
|
68
|
+
fail 'Oops'
|
|
69
|
+
rescue StandardError
|
|
70
|
+
# no code here
|
|
71
|
+
ensure
|
|
72
|
+
result = :always_run
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(:ensure_clause_one), result
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Sometimes, we must know about the unknown
|
|
79
|
+
# Checks asserting an error is raised.
|
|
80
|
+
def test_asserting_an_error_is_raised
|
|
81
|
+
# A do-end is a block, a topic to explore more later
|
|
82
|
+
assert_predicted_error(:asserting_an_error_is_raised_one, ::AboutExceptionsTest::MySpecialError) do
|
|
83
|
+
raise MySpecialError.new('New instances can be raised directly.')
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Checks the predicted exception class while returning the captured error.
|
|
88
|
+
# @param key [Symbol] answer field
|
|
89
|
+
# @param klass [Class<Exception>] exception raised by the example
|
|
90
|
+
# @return [Exception]
|
|
91
|
+
def assert_predicted_error(key, ...)
|
|
92
|
+
error = assert_raises(...)
|
|
93
|
+
assert_equal Exercises::AboutExceptions.koans.fetch(key), error.class
|
|
94
|
+
error
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# rubocop:enable Lint/UselessAssignment, Naming/MethodName, Style/RaiseArgs, Style/SignalException
|