<commit_before># Machine
require_relative "../models/machine"

describe Machine do
  let(:machine) { Machine.new()}
  let(:quarter) { Coin.new({weight: 5.67, diameter: 24.26, thickness: 1.75})}
  let(:dime) { Coin.new({weight: 2.27, diameter: 17.91, thickness: 1.35})}
  let(:nickel) { Coin.new({weight: 5, diameter: 21.21, thickness: 1.95})}
  let(:penny) { Coin.new() }
  let(:chips) { Product.new({name: "Chips", price: 0.5}) }

  describe "#initialize" do
    it "initializes with no money inserted" do
      expect(machine.inserted_value).to eq 0
    end

    it "initializes with no stored coins" do
      expect(machine.coins).to eq({'quarter' => 0, 'dime' => 0, 'nickel' => 0})
    end
  end

  describe "#add_coin" do
    it "stores the coin in the machine" do
      machine.add_coin(quarter)
      expect(machine.coins['quarter']).to eq 1
    end

    it "adds the coin's value to the inserted value" do
      machine.add_coin(dime)
      expect(machine.inserted_value).to eq 0.1
    end

    it "does not add invalid coins" do
      expect(machine.add_coin(penny)).to be false
    end
  end

  describe "#products" do
    it "starts as an empty array" do
      expect(machine.products).to eq([])
    end

    describe "#add_product" do
      it "adds a product object to a machine's inventory" do
        machine.add_product(chips)
        expect(machine.products).to eq([chips])
      end

      it "does not add non-product objects to a machine's inventory" do
        machine.add_product("chips")
        expect(machine.products).to eq([])
      end
    end

    describe "#remove_product" do
      before(:each) do
        machine.add_product(chips)
      end

      it "removes a product object from a machine's inventory" do
        machine.remove_product(chips)
        expect(machine.products).to eq([])
      end

      it "only removes one product from the machine when duplicates are present" do
        machine.add_product(chips)
        machine.remove_product(chips)
        expect(machine.products).to eq([chips])
      end
    end
  end

  describe "#in_stock?" do
    it "determines whether or not a product is present in machine's inventory" do
      machine.add_product(chips)
      expect(machine.in_stock?(chips)).to be true
    end
  end

  describe "#try_to_sell" do
    before(:each) do
      5.times do
        machine.add_product(chips)
      end
      machine.inserted_value = 0.5
      machine.try_to_sell(chips)
    end

    it "sells a product that is in stock when enough money is inserted" do
      expect(machine.products).to eq([chips, chips, chips, chips])
    end

    it "resets inserted value when a product is sold" do
      expect(machine.inserted_value).to eq(0)
    end

  end

### Products can be selected for sale

#### WHEN TOTAL INSERTED VALUE IS EQUAL TO SELECTED PRODUCT'S VALUE AND PRODUCT IS IN STOCK

##### Product quantity decreases

##### Product is dispensed

##### Total inserted value is reset


#### WHEN TOTAL INSERTED VALUE IS GREATER THAN SELECTED PRODUCT'S VALUE AND PRODUCT IS IN STOCK

##### Product quantity decreases

##### Product is dispensed

##### Total inserted value is reset

##### Remaining inserted value is given back to the customer
<commit_msg>outline some other tests, add test for when product is out of stock<commit_after># Machine
require_relative "../models/machine"

describe Machine do
  let(:machine) { Machine.new()}
  let(:quarter) { Coin.new({weight: 5.67, diameter: 24.26, thickness: 1.75})}
  let(:dime) { Coin.new({weight: 2.27, diameter: 17.91, thickness: 1.35})}
  let(:nickel) { Coin.new({weight: 5, diameter: 21.21, thickness: 1.95})}
  let(:penny) { Coin.new() }
  let(:chips) { Product.new({name: "Chips", price: 0.5}) }

  describe "#initialize" do
    it "initializes with no money inserted" do
      expect(machine.inserted_value).to eq 0
    end

    it "initializes with no stored coins" do
      expect(machine.coins).to eq({'quarter' => 0, 'dime' => 0, 'nickel' => 0})
    end
  end

  describe "#add_coin" do
    it "stores the coin in the machine" do
      machine.add_coin(quarter)
      expect(machine.coins['quarter']).to eq 1
    end

    it "adds the coin's value to the inserted value" do
      machine.add_coin(dime)
      expect(machine.inserted_value).to eq 0.1
    end

    it "does not add invalid coins" do
      expect(machine.add_coin(penny)).to be false
    end
  end

  describe "#products" do
    it "starts as an empty array" do
      expect(machine.products).to eq([])
    end

    describe "#add_product" do
      it "adds a product object to a machine's inventory" do
        machine.add_product(chips)
        expect(machine.products).to eq([chips])
      end

      it "does not add non-product objects to a machine's inventory" do
        machine.add_product("chips")
        expect(machine.products).to eq([])
      end
    end

    describe "#remove_product" do
      before(:each) do
        machine.add_product(chips)
      end

      it "removes a product object from a machine's inventory" do
        machine.remove_product(chips)
        expect(machine.products).to eq([])
      end

      it "only removes one product from the machine when duplicates are present" do
        machine.add_product(chips)
        machine.remove_product(chips)
        expect(machine.products).to eq([chips])
      end
    end
  end

  describe "#in_stock?" do
    it "determines whether or not a product is present in machine's inventory" do
      machine.add_product(chips)
      expect(machine.in_stock?(chips)).to be true
    end
  end

  describe "#try_to_sell" do
    context "when the selected product is in stock" do
      context "and enough money for the product is inserted" do
        before(:each) do
          5.times do
            machine.add_product(chips)
          end
          3.times do
            machine.add_coin(quarter)
          end
          machine.try_to_sell(chips)
        end

        it "sells the selected product" do
          expect(machine.products).to eq([chips, chips, chips, chips])
        end

        it "resets inserted value when a product is sold" do
          expect(machine.inserted_value).to eq(0)
        end

        context "and more than enough money was inserted" do
          xit "gives back change" do
            expect(machine.coins).to eq({'quarter' => 1, 'dime' => 0, 'nickel' => 0})
          end
        end
      end

      context "and less than enough money is inserted" do
        xit "does not sell the product" do
          expect(machine.products).to eq([chips, chips, chips, chips, chips])
        end

        xit "does not change the amount of money inserted" do

        end
      end
    end

    context "when the product is out of stock" do
      it "does not change the amount of money inserted" do
        3.times do
          machine.add_coin(quarter)
        end
        machine.try_to_sell(chips)
        expect(machine.coins).to eq({'quarter' => 3, 'dime' => 0, 'nickel' => 0})
      end
    end

  end

#### WHEN TOTAL INSERTED VALUE IS GREATER THAN SELECTED PRODUCT'S VALUE AND PRODUCT IS IN STOCK

##### Product quantity decreases

##### Product is dispensed

##### Total inserted value is reset

##### Remaining inserted value is given back to the customer

{'fraction_non_alphanumeric': 0.10478547854785479, 'fraction_numerical': 0.0121012101210121, 'mean_word_length': 2.6639798488664987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '312526', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2158, 'n_words': 752}