ruby icon indicating copy to clipboard operation
ruby copied to clipboard

[Boutique Inventory] Counts all stock that exists

Open kotp opened this issue 2 years ago • 3 comments

This corrects a bug that would not account for all items in some inventory that would otherwise pass the tests.

kotp avatar Nov 30 '22 19:11 kotp

Incoming fly-by e-mail patch submitted, but I can not approve.

kotp avatar Nov 30 '22 19:11 kotp

I can't see what this is testing. Do you have an example of code that previously was incorrectly passing pls?

iHiD avatar Nov 30 '22 19:11 iHiD

It is testing that we indeed get a total count for some products. Student code was passing but would not pass with this additional test.

  def total_stock
    stock = items.map { |item| item[:quantity_by_size] }.first
    stock.nil? || stock.empty? ? OUT_OF_STOCK : stock.each_value.inject(:+)
  end

Would pass the current tests, but would fail this situation as presented in the tests. The test was really testing that we ot the total in the first listed type of product, rather than the indicated "total of some products".

The additional test drove this solution for this student:

' def total_stock
    items.inject(0) do |counter, item|
      counter + item[:quantity_by_size].inject(0) { |sum, values| sum + values.last }
    end
  end

kotp avatar Nov 30 '22 20:11 kotp