-
-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Knapsack exercise #1644
Add Knapsack exercise #1644
Conversation
On Thu, Mar 14, 2024 at 10:21:35PM -0400, Felipe Vogel wrote:
---
exercises/practice/knapsack/knapsack_test.rb | 97 ++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/exercises/practice/knapsack/knapsack_test.rb b/exercises/practice/knapsack/knapsack_test.rb
index e69de29bb2..1a84e0e49f 100644
--- a/exercises/practice/knapsack/knapsack_test.rb
+++ b/exercises/practice/knapsack/knapsack_test.rb
@@ -0,0 +1,97 @@
+require 'minitest/autorun'
+require_relative 'knapsack'
+
+class KnapsackTest < Minitest::Test
+ Item = Data.define(:weight, :value)
Loving the use of `Data` here.
+
+ def test_no_items
+ # skip
+ max_weight = 100
+ items = []
Consider making the assertion line have some kind of potential hint.
In the case of the exercse "all your base" on Ruby, we do something like
this:
```ruby
assert_equal expected, converted, hint
```
In this case, we can do:
```ruby
def test_no_items
maximum_weight = 100
items = []
expected = 0
actual = Knapsack.new(maximum_weight).max_value(items)
assert_equal expected, actual, 'For no items, the resulting value must be 0'
```
This can help layout the reading and provides a reason or a hint as to
what you must do to make that test pass.
+ assert_equal 0, Knapsack.new(max_weight).max_value(items)
+ end
+
---- ✂ Snip Snip ✂ ----
… + Item.new(weight: 118, value: 229),
+ Item.new(weight: 120, value: 240)
+ ]
+ assert_equal 1458, Knapsack.new(max_weight).max_value(items)
+ end
+end
|
About the failing test, it is due to the |
Nah, just a conscious decision to bring it in even with the 3.1 version failing, for a known reason. This will pass on the platform, as it is using Ruby 3.3 according to the repository. |
@kotp Thanks for the feedback! I've made the changes that you suggested. Plus, I added punctuation and fixed typos in the explanation quoted from Reddit, in order to make it more readable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, but a few changes are probably warranted in communicating what must be rather than what should be.
Forum thread: https://forum.exercism.org/t/add-knapsack-exercise-48in24/10320