diff --git a/autograder/saas_grade.py b/autograder/saas_grade.py index c1680631..e4755713 100644 --- a/autograder/saas_grade.py +++ b/autograder/saas_grade.py @@ -32,9 +32,11 @@ print('%s' % (record['exception']['message'])) print('') -codio_points = int(passed_points * base_points/total_points) - -print(" Your program got %d out of %d points " % (passed_points, total_points)) +codio_points = 0 if total_points == 0 else int(passed_points * base_points/total_points) +if total_points == 0: + print(" Your program got 0 points. ") +else: + print(" Your program got %d out of %d points. " % (passed_points, total_points)) print('

') diff --git a/build_codio.json b/build_codio.json index 63457149..bf3ccedf 100644 --- a/build_codio.json +++ b/build_codio.json @@ -54,6 +54,11 @@ "autograder": { "src": "solutions/spec" } + }, + { + "Gemfile": { + "src": "solutions/Gemfile" + } } ] } diff --git a/scaffolding/codio/assessments.json b/scaffolding/codio/assessments.json index 7955c086..6fbac1d5 100644 --- a/scaffolding/codio/assessments.json +++ b/scaffolding/codio/assessments.json @@ -1,199 +1,163 @@ [ - { - "type": "test", - "taskId": "test-1979733178", - "source": { - "name": "hw-ruby-intro-part 1", - "showName": false, - "instructions": "To submit your solution to Part 1, click the button below.", - "command": "bash .guides/secure/grader.sh 1", - "arePartialPointsAllowed": true, - "timeoutSeconds": 300, - "guidance": "", - "showGuidanceAfterResponse": false, - "points": 100, - "oneTimeTest": false, - "metadata": { - "tags": [ - { - "name": "Assessment Type", - "value": "Advanced Code Test" + { + "type": "test", + "taskId": "test-1979733178", + "source": { + "name": "hw-ruby-intro-part 1", + "showName": false, + "instructions": "To submit your solution to Part 1, click the button below.", + "command": "bash .guides/secure/grader.sh 1", + "arePartialPointsAllowed": true, + "timeoutSeconds": 300, + "guidance": "", + "showGuidanceAfterResponse": false, + "points": 100, + "oneTimeTest": false, + "metadata": { + "tags": [ + { + "name": "Assessment Type", + "value": "Advanced Code Test" + }, + { + "name": "Content", + "value": "Arrays, Hashes, and Enumerables" + }, + { + "name": "Programming Language", + "value": "Ruby" + }, + { + "name": "CHIP", + "value": "hw-ruby-intro" + } + ], + "files": [ + "assignment/lib/ruby_intro.rb", + ".guides/grader.sh", + ".guides/saas_grade.py" + ], + "layout": "2-panels-tree", + "opened": [ + { + "type": "file", + "panelNumber": 0, + "content": "assignment/lib/ruby_intro.rb" + } + ] + }, + "bloomsObjectiveLevel": "6", + "learningObjectives": "" }, - { - "name": "Content", - "value": "Arrays, Hashes, and Enumerables" + "linkedId": "c9da0dd0-fb6b-48a1-ade8-971d6e7d61be", + "libraryId": "288c973f-aab2-45db-96cd-18a442d94b10", + "version": 2 + }, + { + "type": "test", + "taskId": "test-945754669", + "source": { + "name": "hw-ruby-intro-part 2", + "showName": false, + "instructions": "To submit your solution to Part 2, click the button below.", + "command": "bash .guides/secure/grader.sh 2", + "arePartialPointsAllowed": true, + "timeoutSeconds": 300, + "guidance": "", + "showGuidanceAfterResponse": false, + "points": 100, + "oneTimeTest": false, + "metadata": { + "tags": [ + { + "name": "Assessment Type", + "value": "Advanced Code Test" + }, + { + "name": "CHIP", + "value": "hw-ruby-intro" + }, + { + "name": "Content", + "value": "Strings and Regular Expressions" + }, + { + "name": "Programming Language", + "value": "Ruby" + } + ], + "files": [ + "assignment/lib/ruby_intro.rb", + ".guides/secure/grader.sh", + ".guides/secure/saas_grade.py" + ], + "layout": "2-panels-tree", + "opened": [ + { + "type": "file", + "panelNumber": 0, + "content": "assignment/lib/ruby_intro.rb" + } + ] + }, + "bloomsObjectiveLevel": "6", + "learningObjectives": "" }, - { - "name": "Programming Language", - "value": "Ruby" + "libraryId": "288c973f-aab2-45db-96cd-18a442d94b10", + "version": 1, + "linkedId": "d73a59a0-ce36-448e-b72b-23f335938445" + }, + { + "type": "test", + "taskId": "test-2550083281", + "source": { + "name": "hw-ruby-intro-part 3", + "showName": false, + "instructions": "To submit your solution to Part 3, click the button below.", + "command": "bash .guides/secure/grader.sh 3", + "arePartialPointsAllowed": true, + "timeoutSeconds": 300, + "guidance": "", + "showGuidanceAfterResponse": false, + "points": 100, + "oneTimeTest": false, + "metadata": { + "tags": [ + { + "name": "Assessment Type", + "value": "Advanced Code Test" + }, + { + "name": "CHIP", + "value": "hw-ruby-intro" + }, + { + "name": "Content", + "value": "Object Oriented Design" + }, + { + "name": "Programming Language", + "value": "Ruby" + } + ], + "files": [ + "assignment/lib/ruby_intro.rb", + ".guides/secure/grader.sh", + ".guides/secure/saas_grade.py" + ], + "layout": "2-panels-tree", + "opened": [ + { + "type": "file", + "panelNumber": 0, + "content": "assignment/lib/ruby_intro.rb" + } + ] + }, + "bloomsObjectiveLevel": "6", + "learningObjectives": "" }, - { - "name": "CHIP", - "value": "hw-ruby-intro" - } - ], - "files": [ - "assignment/hw-ruby-intro/lib/ruby_intro.rb", - ".guides/grader.sh", - ".guides/saas_grade.py" - ], - "layout": "2-panels-tree", - "opened": [ - { - "type": "file", - "panelNumber": 0, - "content": "assignment/hw-ruby-intro/lib/ruby_intro.rb" - } - ] - }, - "bloomsObjectiveLevel": "6", - "learningObjectives": "" - }, - "linkedId": "c9da0dd0-fb6b-48a1-ade8-971d6e7d61be", - "libraryId": "288c973f-aab2-45db-96cd-18a442d94b10", - "version": 2 - }, - { - "type": "test", - "taskId": "test-60900984", - "source": { - "name": "asdf", - "showName": true, - "instructions": "", - "command": "asdf", - "arePartialPointsAllowed": false, - "timeoutSeconds": 40, - "guidance": "", - "showGuidanceAfterResponse": false, - "points": 1, - "oneTimeTest": false, - "metadata": { - "tags": [ - { - "name": "Assessment Type", - "value": "Advanced Code Test" - } - ], - "files": [ - "assignment/hw-ruby-intro/lib/ruby_intro.rb" - ], - "opened": [ - { - "type": "file", - "panelNumber": 0, - "content": "assignment/hw-ruby-intro/lib/ruby_intro.rb" - } - ] - }, - "bloomsObjectiveLevel": "", - "learningObjectives": "" - } - }, - { - "type": "test", - "taskId": "test-945754669", - "source": { - "name": "hw-ruby-intro-part 2", - "showName": false, - "instructions": "To submit your solution to Part 2, click the button below.", - "command": "bash .guides/secure/grader.sh 2", - "arePartialPointsAllowed": true, - "timeoutSeconds": 300, - "guidance": "", - "showGuidanceAfterResponse": false, - "points": 100, - "oneTimeTest": false, - "metadata": { - "tags": [ - { - "name": "Assessment Type", - "value": "Advanced Code Test" - }, - { - "name": "CHIP", - "value": "hw-ruby-intro" - }, - { - "name": "Content", - "value": "Strings and Regular Expressions" - }, - { - "name": "Programming Language", - "value": "Ruby" - } - ], - "files": [ - "assignment/hw-ruby-intro/lib/ruby_intro.rb", - ".guides/grader.sh", - ".guides/saas_grade.py" - ], - "layout": "2-panels-tree", - "opened": [ - { - "type": "file", - "panelNumber": 0, - "content": "assignment/hw-ruby-intro/lib/ruby_intro.rb" - } - ] - }, - "bloomsObjectiveLevel": "6", - "learningObjectives": "" - }, - "libraryId": "288c973f-aab2-45db-96cd-18a442d94b10", - "version": 1, - "linkedId": "d73a59a0-ce36-448e-b72b-23f335938445" - }, - { - "type": "test", - "taskId": "test-2550083281", - "source": { - "name": "hw-ruby-intro-part 3", - "showName": false, - "instructions": "To submit your solution to Part 3, click the button below.", - "command": "bash .guides/secure/grader.sh 3", - "arePartialPointsAllowed": true, - "timeoutSeconds": 300, - "guidance": "", - "showGuidanceAfterResponse": false, - "points": 100, - "oneTimeTest": false, - "metadata": { - "tags": [ - { - "name": "Assessment Type", - "value": "Advanced Code Test" - }, - { - "name": "CHIP", - "value": "hw-ruby-intro" - }, - { - "name": "Content", - "value": "Object Oriented Design" - }, - { - "name": "Programming Language", - "value": "Ruby" - } - ], - "files": [ - "assignment/hw-ruby-intro/lib/ruby_intro.rb", - ".guides/grader.sh", - ".guides/saas_grade.py" - ], - "layout": "2-panels-tree", - "opened": [ - { - "type": "file", - "panelNumber": 0, - "content": "assignment/hw-ruby-intro/lib/ruby_intro.rb" - } - ] - }, - "bloomsObjectiveLevel": "6", - "learningObjectives": "" - }, - "libraryId": "288c973f-aab2-45db-96cd-18a442d94b10", - "version": 0 - } -] \ No newline at end of file + "libraryId": "288c973f-aab2-45db-96cd-18a442d94b10", + "version": 0 + } + ] \ No newline at end of file diff --git a/scaffolding/codio/book.json b/scaffolding/codio/book.json index 55e1ea1e..54c8d63d 100644 --- a/scaffolding/codio/book.json +++ b/scaffolding/codio/book.json @@ -1,29 +1,35 @@ { - "name": "hw-ruby-intro", - "children": [ - { - "id": "16fbf2b6-b355-1531-60ab-d1ff64cbcd0d", - "title": "Part 1 Submission", - "pageId": "1eaf7474-1748-ba3a-51c0-6034bdf51877", - "type": "page" - }, - { - "id": "31eba402-3ce0-eff5-8d0d-1a98c44cd96c", - "title": "Part 2 Submission", - "pageId": "6e2caee8-ef1c-fb5e-eaaf-3a917cc3f20a", - "type": "page" - }, - { - "id": "ed28cff3-87e9-e83f-d486-1fdc2d698092", - "title": "Part 3 Submission", - "pageId": "a860bb78-d16e-4768-ad03-79b9c26dd8c8", - "type": "page" - }, - { - "id": "f0158808-d4f3-eb27-2452-bdf55d71ae9b", - "title": "Going Further", - "pageId": "ab799e81-a602-6967-80d9-6049be3ee085", - "type": "page" - } - ] -} \ No newline at end of file + "name": "hw-ruby-intro", + "children": [ + { + "title": "Ruby Intro", + "id": "5afae247-d955-654d-4120-74d03b8c8442", + "type": "page", + "pageId": "cdcb00fc-af38-513d-ee32-e6bf9a1d8930" + }, + { + "title": "Part 1 Submission", + "id": "16fbf2b6-b355-1531-60ab-d1ff64cbcd0d", + "type": "page", + "pageId": "1eaf7474-1748-ba3a-51c0-6034bdf51877" + }, + { + "title": "Part 2 Submission", + "id": "31eba402-3ce0-eff5-8d0d-1a98c44cd96c", + "type": "page", + "pageId": "6e2caee8-ef1c-fb5e-eaaf-3a917cc3f20a" + }, + { + "title": "Part 3 Submission", + "id": "ed28cff3-87e9-e83f-d486-1fdc2d698092", + "type": "page", + "pageId": "a860bb78-d16e-4768-ad03-79b9c26dd8c8" + }, + { + "title": "Going Further", + "id": "f0158808-d4f3-eb27-2452-bdf55d71ae9b", + "type": "page", + "pageId": "ab799e81-a602-6967-80d9-6049be3ee085" + } + ] + } \ No newline at end of file diff --git a/scaffolding/codio/metadata.json b/scaffolding/codio/metadata.json index cec9b5e2..c7e6d65b 100644 --- a/scaffolding/codio/metadata.json +++ b/scaffolding/codio/metadata.json @@ -1,99 +1,111 @@ { - "sections": [ - { - "id": "1eaf7474-1748-ba3a-51c0-6034bdf51877", - "title": "Part 1 Submission", - "files": [ - { - "path": "#tabs", - "action": "close" - }, - { - "path": "assignment/hw-ruby-intro/lib/ruby_intro.rb", - "panel": 0, - "action": "open" - } - ], - "layout": "2-panels-tree", - "path": [], - "type": "markdown", - "content-file": ".guides/content/Part-1-Submission-1eaf.md", - "chapter": false, - "reset": [], - "teacherOnly": false, - "learningObjectives": "" - }, - { - "id": "6e2caee8-ef1c-fb5e-eaaf-3a917cc3f20a", - "title": "Part 2 Submission", - "files": [ - { - "path": "#tabs", - "action": "close" - }, - { - "path": " assignment/hw-ruby-intro/lib/ruby_intro.rb", - "panel": 0, - "action": "open" - } - ], - "layout": "2-panels-tree", - "path": [], - "type": "markdown", - "content-file": ".guides/content/Part-2-Submission-6e2c.md", - "chapter": false, - "reset": [], - "teacherOnly": false, - "learningObjectives": "", - "readOnly": false - }, - { - "id": "a860bb78-d16e-4768-ad03-79b9c26dd8c8", - "title": "Part 3 Submission", - "files": [ - { - "path": "#tabs", - "action": "close" - }, - { - "path": " assignment/hw-ruby-intro/lib/ruby_intro.rb", - "panel": 0, - "action": "open" - } - ], - "layout": "2-panels-tree", - "path": [], - "type": "markdown", - "content-file": ".guides/content/Part-3-Submission-a860.md", - "chapter": false, - "reset": [], - "teacherOnly": false, - "learningObjectives": "", - "readOnly": false - }, - { - "id": "ab799e81-a602-6967-80d9-6049be3ee085", - "title": "Going Further", - "files": [], - "path": [], - "type": "markdown", - "content-file": ".guides/content/Going-Further-ab79.md", - "chapter": false, - "reset": [], - "teacherOnly": false, - "learningObjectives": "" - } - ], - "theme": "light", - "scripts": [], - "lexikonTopic": "", - "suppressPageNumbering": true, - "useSubmitButtons": true, - "useMarkAsComplete": true, - "hideMenu": false, - "allowGuideClose": false, - "collapsedOnStart": false, - "hideSectionsToggle": false, - "hideBackToDashboard": false, - "protectLayout": false -} \ No newline at end of file + "sections": [ + { + "id": "cdcb00fc-af38-513d-ee32-e6bf9a1d8930", + "title": "Ruby Intro", + "files": [], + "path": [], + "type": "markdown", + "content-file": ".guides/content/Ruby-Intro-cdcb.md", + "chapter": false, + "reset": [], + "teacherOnly": false, + "learningObjectives": "" + }, + { + "id": "1eaf7474-1748-ba3a-51c0-6034bdf51877", + "title": "Part 1 Submission", + "files": [ + { + "path": "#tabs", + "action": "close" + }, + { + "path": "assignment/lib/ruby_intro.rb", + "panel": 0, + "action": "open" + } + ], + "layout": "2-panels-tree", + "path": [], + "type": "markdown", + "content-file": ".guides/content/Part-1-Submission-1eaf.md", + "chapter": false, + "reset": [], + "teacherOnly": false, + "learningObjectives": "" + }, + { + "id": "6e2caee8-ef1c-fb5e-eaaf-3a917cc3f20a", + "title": "Part 2 Submission", + "files": [ + { + "path": "#tabs", + "action": "close" + }, + { + "path": " assignment/lib/ruby_intro.rb", + "panel": 0, + "action": "open" + } + ], + "layout": "2-panels-tree", + "path": [], + "type": "markdown", + "content-file": ".guides/content/Part-2-Submission-6e2c.md", + "chapter": false, + "reset": [], + "teacherOnly": false, + "learningObjectives": "", + "readOnly": false + }, + { + "id": "a860bb78-d16e-4768-ad03-79b9c26dd8c8", + "title": "Part 3 Submission", + "files": [ + { + "path": "#tabs", + "action": "close" + }, + { + "path": " assignment/lib/ruby_intro.rb", + "panel": 0, + "action": "open" + } + ], + "layout": "2-panels-tree", + "path": [], + "type": "markdown", + "content-file": ".guides/content/Part-3-Submission-a860.md", + "chapter": false, + "reset": [], + "teacherOnly": false, + "learningObjectives": "", + "readOnly": false + }, + { + "id": "ab799e81-a602-6967-80d9-6049be3ee085", + "title": "Going Further", + "files": [], + "path": [], + "type": "markdown", + "content-file": ".guides/content/Going-Further-ab79.md", + "chapter": false, + "reset": [], + "teacherOnly": false, + "learningObjectives": "" + } + ], + "theme": "light", + "scripts": [], + "lexikonTopic": "", + "suppressPageNumbering": true, + "useSubmitButtons": true, + "useMarkAsComplete": true, + "hideMenu": false, + "allowGuideClose": false, + "collapsedOnStart": false, + "hideSectionsToggle": false, + "hideBackToDashboard": false, + "protectLayout": false + } \ No newline at end of file diff --git a/scaffolding/content/Part-1-Submission-1eaf.md b/scaffolding/content/Part-1-Submission-1eaf.md index f24efd90..0a25e9be 100644 --- a/scaffolding/content/Part-1-Submission-1eaf.md +++ b/scaffolding/content/Part-1-Submission-1eaf.md @@ -4,14 +4,14 @@ Check the [Ruby 2.x documentation](http://ruby-doc.org) on `Array`, `Hash` and `Enumerable` as they could help tremendously with these exercises. :-) -0. Define a method `sum(array)` that takes an array of integers as an argument and returns the sum of its elements. For an empty array it should return zero. Run associated tests via: `$ rspec -e '#sum ' spec/part1_spec.rb` +0. Define a method `sum(array)` that takes an array of integers as an argument and returns the sum of its elements. For an empty array it should return zero. Run associated tests via: `$ rspec -e '#sum ' spec/part1_spec.rb` (Make sure you are in the correct directory: `cd assignment`) 0. Define a method `max_2_sum(array)` which takes an array of integers as an argument and returns the sum of its two largest elements. For an empty array it should return zero. For an array with just one element, it should return that element. Run associated tests via: `$ rspec -e '#max_2_sum' spec/part1_spec.rb` 0. Define a method `sum_to_n?(array, n)` that takes an array of integers and an additional integer, n, as arguments and returns true if any two elements in the array of integers sum to n. `sum_to_n?([], n)` should return false for any value of n, by definition. Run associated tests via: `$ rspec -e '#sum_to_n' spec/part1_spec.rb` -You can check your progress on the all the above by running `$ rspec assignment/hw-ruby-intro/spec/part1_spec.rb`. +You can check your progress on all of the above by running `$ rspec spec/part1_spec.rb`. -{Run rspec spec/part1_spec.rb | terminal}(rspec assignment/hw-ruby-intro/spec/part1_spec.rb) +{Run rspec spec/part1_spec.rb | terminal}(rspec assignment/spec/part1_spec.rb) -{Submit |assessment}(test-1979733178) \ No newline at end of file +{Submit!|assessment}(test-945754669) \ No newline at end of file diff --git a/scaffolding/content/Part-2-Submission-6e2c.md b/scaffolding/content/Part-2-Submission-6e2c.md index 838a0434..2b5a1cae 100644 --- a/scaffolding/content/Part-2-Submission-6e2c.md +++ b/scaffolding/content/Part-2-Submission-6e2c.md @@ -2,14 +2,14 @@ Check the documentation on String and Regexp as they could help tremendously with these exercises. :-) -0. Define a method `hello(name)` that takes a string representing a name and returns the string "Hello, " concatenated with the name. Run associated tests via: `$ rspec -e '#hello' spec/part2_spec.rb` +0. Define a method `hello(name)` that takes a string representing a name and returns the string "Hello, " concatenated with the name. Run associated tests via: `$ rspec -e '#hello' spec/part2_spec.rb` (Make sure you are in the correct directory: `cd assignment`) 0. Define a method `starts_with_consonant?(s)` that takes a string and returns true if it starts with a consonant and false otherwise. (For our purposes, a consonant is any letter other than A, E, I, O, U.) NOTE: be sure it works for both upper and lower case and for nonletters! Run associated tests via: `$ rspec -e '#starts_with_consonant?' spec/part2_spec.rb` 0. Define a method `binary_multiple_of_4?(s)` that takes a string and returns true if the string represents a binary number that is a multiple of 4. NOTE: be sure it returns false if the string is not a valid binary number! Run associated tests via: `$ rspec -e '#binary_multiple_of_4?' spec/part2_spec.rb` -You can check your progress on the all the above by running `$ rspec assignment/hw-ruby-intro/spec/part2_spec.rb`. +You can check your progress on all of the above by running `$ rspec spec/part2_spec.rb`. -{Run rspec spec/part2_spec.rb | terminal}(rspec assignment/hw-ruby-intro/spec/part2_spec.rb) +{Run rspec spec/part2_spec.rb | terminal}(rspec assignment/spec/part2_spec.rb) {Submit!|assessment}(test-945754669) \ No newline at end of file diff --git a/scaffolding/content/Part-3-Submission-a860.md b/scaffolding/content/Part-3-Submission-a860.md index 0595068f..619c7208 100644 --- a/scaffolding/content/Part-3-Submission-a860.md +++ b/scaffolding/content/Part-3-Submission-a860.md @@ -1,14 +1,14 @@ # 3. Object Oriented Basics -Define a class `BookInStock` which represents a book with an ISBN number, `isbn`, and price of the book as a floating-point number, `price`, as attributes. Run associated tests via: `$ rspec -e 'getters and setters' spec/part3_spec.rb` +Define a class `BookInStock` which represents a book with an ISBN number, `isbn`, and price of the book as a floating-point number, `price`, as attributes. Run associated tests via: `$ rspec -e 'getters and setters' spec/part3_spec.rb` (Make sure you are in the correct directory: `cd assignment`) The constructor should accept the ISBN number (a string, since in real life ISBN numbers can begin with zero and can include hyphens) as the first argument and price as second argument, and should raise `ArgumentError` (one of Ruby's built-in exception types) if the ISBN number is the empty string or if the price is less than or equal to zero. Include the proper getters and setters for these attributes. Run associated tests via: `$ rspec -e 'constructor' spec/part3_spec.rb` Include a method `price_as_string` that returns the price of the book formatted with a leading dollar sign and two decimal places, that is, a price of 20 should format as `$20.00` and a price of 33.8 should format as `$33.80`. Run associated tests via: `$ rspec -e '#price_as_string' spec/part3_spec.rb` -You can check your progress on the all the above by running `rspec assignment/hw-ruby-intro/spec/part3_spec.rb`. +You can check your progress on all of the above by running `rspec spec/part3_spec.rb`. -{Run rspec spec/part3_spec.rb | terminal}(rspec assignment/hw-ruby-intro/spec/part3_spec.rb) +{Run rspec spec/part3_spec.rb | terminal}(rspec assignment/spec/part3_spec.rb) {Submit!|assessment}(test-2550083281) \ No newline at end of file diff --git a/scaffolding/content/Ruby-Intro-cdcb.md b/scaffolding/content/Ruby-Intro-cdcb.md new file mode 100644 index 00000000..8878c971 --- /dev/null +++ b/scaffolding/content/Ruby-Intro-cdcb.md @@ -0,0 +1,56 @@ +Ruby Intro +============= + +This 3-part homework gives some basic practice in Ruby as well as +getting you accustomed to making testing a regular part of your workflow. + +**NOTE: If you are working on a local computer, do not clone this repo to your workspace. Fork it first, then clone your fork.** + + +Learning Goals +-------------- +After completing this assignment, you will know how to: + +* Write simple code that uses basic constructs in the Ruby language, including methods and arguments, conditionals, string and array manipulation, regular expressions, and basic object-oriented programming mechanisms +* Understand the Ruby project conventions for where code files and test files are located in a project's directory hierarchy +* Run individual tests or suites of tests using the RSpec unit testing tool +* Understand the basic syntax of RSpec unit tests + +Overview +-------- + +**You may find the [Ruby documentation at ruby-doc.org](https://ruby-doc.org) helpful to have on hand.** + +The repo for this assigment follows a fairly standard Ruby convention for codebases: the code +files are stored in `lib/` and the test files are stored in `spec/`. +(We use the RSpec unit-testing framework; if we were using Ruby's default +framework, known as `Test::Unit`, the test files would be under +`test/`.) + +**We've placed "starter code" in `lib/ruby_intro.rb`; when you're all done, you +can submit this single file to the autograder.** + +However, you can test each of the 3 parts separately. The files +`spec/part[123]_spec.rb` contain RSpec tests for each of the three +parts. For example, to test your answers to Part 1, say `rspec +spec/part1_spec.rb`. `rspec` with no arguments runs the tests in all +the files `spec/*_spec.rb`. + +* The line numbers in the RSpec error report will +give you guidance as to which tests failed. (You can check the [RSpec +documentation](http://rspec.info) to see how the `.rspec` file can be +used to customize the output format.) + +If you are working in Codio, you are ready to move on to the next part. If you are working on a local computer, proceed with the following steps. + +| Local computer setup | +|-----| +To ensure you have the rspec gem installed you need bundler and can then +run bundle install like so: +```sh +$ gem install bundler +$ cd assignment +$ bundle +``` +When the above completes successfully you'll have RSpec installed and can +run `rspec` from the command line to test your code. diff --git a/solutions/README.md b/solutions/README.md index 67002e5a..35b37cf9 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -4,7 +4,8 @@ Ruby Intro This 3-part homework gives some basic practice in Ruby as well as getting you accustomed to making testing a regular part of your workflow. -**NOTE: Do not clone this repo to your workspace. Fork it first, then clone your fork.** +**NOTE: If you are working on a local computer, do not clone this repo to your workspace. Fork it first, then clone your fork.** + Learning Goals -------------- @@ -40,66 +41,59 @@ give you guidance as to which tests failed. (You can check the [RSpec documentation](http://rspec.info) to see how the `.rspec` file can be used to customize the output format.) +If you are working in Codio, you are ready to move on to the next part. If you are working on a local computer, proceed with the following steps. + +| Local computer setup | +|-----| To ensure you have the rspec gem installed you need bundler and can then run bundle install like so: - ```sh $ gem install bundler -$ cd hw-ruby-intro +$ cd assignment $ bundle ``` - When the above completes successfully you'll have RSpec installed and can run `rspec` from the command line to test your code. - # 1. Arrays, Hashes, and Enumerables Check the [Ruby 2.x documentation](http://ruby-doc.org) on `Array`, `Hash` and `Enumerable` as they could help tremendously with these exercises. :-) -0. Define a method `sum(array)` that takes an array of integers as an argument and returns the sum of its elements. For an empty array it should return zero. Run associated tests via: `$ rspec -e '#sum ' spec/part1_spec.rb` +0. Define a method `sum(array)` that takes an array of integers as an argument and returns the sum of its elements. For an empty array it should return zero. Run associated tests via: `$ rspec -e '#sum ' spec/part1_spec.rb` (Make sure you are in the correct directory: `cd assignment`) 0. Define a method `max_2_sum(array)` which takes an array of integers as an argument and returns the sum of its two largest elements. For an empty array it should return zero. For an array with just one element, it should return that element. Run associated tests via: `$ rspec -e '#max_2_sum' spec/part1_spec.rb` 0. Define a method `sum_to_n?(array, n)` that takes an array of integers and an additional integer, n, as arguments and returns true if any two elements in the array of integers sum to n. `sum_to_n?([], n)` should return false for any value of n, by definition. Run associated tests via: `$ rspec -e '#sum_to_n' spec/part1_spec.rb` -You can check your progress on the all the above by running `$ rspec spec/part1_spec.rb`. +You can check your progress on all of the above by running `$ rspec spec/part1_spec.rb`. + # 2. Strings and Regular Expressions Check the documentation on String and Regexp as they could help tremendously with these exercises. :-) -0. Define a method `hello(name)` that takes a string representing a name and returns the string "Hello, " concatenated with the name. Run associated tests via: `$ rspec -e '#hello' spec/part2_spec.rb` +0. Define a method `hello(name)` that takes a string representing a name and returns the string "Hello, " concatenated with the name. Run associated tests via: `$ rspec -e '#hello' spec/part2_spec.rb` (Make sure you are in the correct directory: `cd assignment`) 0. Define a method `starts_with_consonant?(s)` that takes a string and returns true if it starts with a consonant and false otherwise. (For our purposes, a consonant is any letter other than A, E, I, O, U.) NOTE: be sure it works for both upper and lower case and for nonletters! Run associated tests via: `$ rspec -e '#starts_with_consonant?' spec/part2_spec.rb` 0. Define a method `binary_multiple_of_4?(s)` that takes a string and returns true if the string represents a binary number that is a multiple of 4. NOTE: be sure it returns false if the string is not a valid binary number! Run associated tests via: `$ rspec -e '#binary_multiple_of_4?' spec/part2_spec.rb` -You can check your progress on the all the above by running `$ rspec spec/part2_spec.rb`. +You can check your progress on all of the above by running `$ rspec spec/part2_spec.rb`. + # 3. Object Oriented Basics -Define a class `BookInStock` which represents a book with an ISBN -number, `isbn`, and price of the book as a floating-point number, -`price`, as attributes. Run associated tests via: `$ rspec -e 'getters and setters' spec/part3_spec.rb` +Define a class `BookInStock` which represents a book with an ISBN number, `isbn`, and price of the book as a floating-point number, `price`, as attributes. Run associated tests via: `$ rspec -e 'getters and setters' spec/part3_spec.rb` (Make sure you are in the correct directory: `cd assignment`) + +The constructor should accept the ISBN number (a string, since in real life ISBN numbers can begin with zero and can include hyphens) as the first argument and price as second argument, and should raise `ArgumentError` (one of Ruby's built-in exception types) if the ISBN number is the empty string or if the price is less than or equal to zero. Include the proper getters and setters for these attributes. Run associated tests via: `$ rspec -e 'constructor' spec/part3_spec.rb` -The constructor should accept the ISBN number -(a string, since in real life ISBN numbers can begin with zero and can -include hyphens) as the first argument and price as second argument, and -should raise `ArgumentError` (one of Ruby's built-in exception types) if -the ISBN number is the empty string or if the price is less than or -equal to zero. Include the proper getters and setters for these -attributes. Run associated tests via: `$ rspec -e 'constructor' spec/part3_spec.rb` +Include a method `price_as_string` that returns the price of the book formatted with a leading dollar sign and two decimal places, that is, a price of 20 should format as `$20.00` and a price of 33.8 should format as `$33.80`. Run associated tests via: `$ rspec -e '#price_as_string' spec/part3_spec.rb` -Include a method `price_as_string` that returns the price of -the book formatted with a leading dollar sign and two decimal places, that is, a price -of 20 should format as "$20.00" and a price of 33.8 should format as -"$33.80". Run associated tests via: `$ rspec -e '#price_as_string' spec/part3_spec.rb` +You can check your progress on all of the above by running `rspec spec/part3_spec.rb`. -You can check your progress on the all the above by running `rspec spec/part3_spec.rb`. ## More Challenges @@ -113,8 +107,3 @@ you write the code, watch the test fail, fill in the code and save the code file then watch the test pass! * Try pairing using the [one-undermanship pair programming style](http://www.agileventures.org/remote-pair-programming/pair-programming-protocols) - -# Submission Directions - -Upload a single `ruby_intro.rb` file to the autograder. - diff --git a/solutions/spec/part1_spec.rb b/solutions/spec/part1_spec.rb index 02022375..8292305b 100644 --- a/solutions/spec/part1_spec.rb +++ b/solutions/spec/part1_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../lib/ruby_intro' - describe 'Ruby intro part 1' do describe '#sum' do it 'should be defined' do diff --git a/solutions/spec/part2_spec.rb b/solutions/spec/part2_spec.rb index 30d04ed1..9b560a63 100644 --- a/solutions/spec/part2_spec.rb +++ b/solutions/spec/part2_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../lib/ruby_intro' - describe '#hello' do it 'should be defined' do expect { hello('Testing') }.not_to raise_error#::NoMethodError) diff --git a/solutions/spec/part3_spec.rb b/solutions/spec/part3_spec.rb index 35b6ccc3..dccd62ef 100644 --- a/solutions/spec/part3_spec.rb +++ b/solutions/spec/part3_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../lib/ruby_intro' - describe 'BookInStock' do it 'should be defined' do expect { BookInStock }.not_to raise_error