<commit_before>require "spec_helper"
require "./lib/good"

HEADER = "Quantity, Product, Price\n"

module FakeTaxRegistry
  def self.tax_rate_for_good name
    0.1
  end
end

describe Good do
  describe "#parse_all" do
    it "returns an array of Good elements" do
      goods = Good.parse_all(HEADER + "1, 1, 1")
      expect(goods.size).to eq 1
      expect(goods.first).to be_a_kind_of(Good)
    end

    it "strips leading and trailing whitespace" do
      good = Good.parse_all(HEADER + "1, book , 1").first
      expect(good.name).to eq "book"
    end

    it "converts strings to numbers" do
      good = Good.parse_all(HEADER + "1, book, 10.50").first
      expect(good.quantity).to eq 1
      expect(good.price).to eq 10.50
    end
  end

  describe "#tax returns amount of tax for the good:" do
    it "10% for imported books" do
      good = Good.new 1, "imported book", 10.0, tax_registry: FakeTaxRegistry
      expect(good.tax).to eq 1
    end

    it "10% for music CDs" do
      good = Good.new 1, "music CD", 14.99, tax_registry: FakeTaxRegistry
      expect(good.tax).to eq 1.5
    end

    it "double for 2 books" do
      good = Good.new 2, "music CD", 10, tax_registry: FakeTaxRegistry
      expect(good.tax).to eq 2
    end

    it "rounded up to the nearest 0.05" do
      good = Good.new 1, "imported bottle of perfume", 47.30,
	tax_registry: FakeTaxRegistry
      expect(good.tax).to eq 4.75
    end
  end

  describe "#total returns price + tax, multiplied by quantity" do
    it "one book" do
      good = Good.new 1, "music CD", 10.0, tax_registry: FakeTaxRegistry
      expect(good.total).to eq 11
    end

    it "two books" do
      good = Good.new 2, "music CD", 10.0, tax_registry: FakeTaxRegistry
      expect(good.total).to eq 22
    end
  end

  it "#to_s returns quantity, name and total" do
    good = Good.new 2, "book", 10.0, tax_registry: FakeTaxRegistry
    expect(good.to_s).to eq "2, book, 22.00"
  end
end<commit_msg>* Use generic good name `item' in Good tests.<commit_after>require "spec_helper"
require "./lib/good"

HEADER = "Quantity, Product, Price\n"

module FakeTaxRegistry
  def self.tax_rate_for_good name
    0.1
  end
end

describe Good do
  describe "#parse_all" do
    it "returns an array of Good elements" do
      goods = Good.parse_all(HEADER + "1, 1, 1")
      expect(goods.size).to eq 1
      expect(goods.first).to be_a_kind_of(Good)
    end

    it "strips leading and trailing whitespace" do
      good = Good.parse_all(HEADER + "1, book , 1").first
      expect(good.name).to eq "book"
    end

    it "converts strings to numbers" do
      good = Good.parse_all(HEADER + "1, book, 10.50").first
      expect(good.quantity).to eq 1
      expect(good.price).to eq 10.50
    end
  end

  describe "#tax returns amount of tax for the good:" do
    it "10% for item" do
      good = Good.new 1, "item", 10.0, tax_registry: FakeTaxRegistry
      expect(good.tax).to eq 1
    end

    it "double for 2 items" do
      good = Good.new 2, "item", 10, tax_registry: FakeTaxRegistry
      expect(good.tax).to eq 2
    end

    it "rounded up to the nearest 0.05" do
      good = Good.new 1, "item", 47.30, tax_registry: FakeTaxRegistry
      expect(good.tax).to eq 4.75
    end
  end

  describe "#total returns price + tax, multiplied by quantity" do
    it "one item" do
      good = Good.new 1, "item", 10.0, tax_registry: FakeTaxRegistry
      expect(good.total).to eq 11
    end

    it "two items" do
      good = Good.new 2, "item", 10.0, tax_registry: FakeTaxRegistry
      expect(good.total).to eq 22
    end
  end

  it "#to_s returns quantity, name and total" do
    good = Good.new 2, "item", 10.0, tax_registry: FakeTaxRegistry
    expect(good.to_s).to eq "2, item, 22.00"
  end
end
{'fraction_non_alphanumeric': 0.10687633262260128, 'fraction_numerical': 0.03544776119402985, 'mean_word_length': 2.672211350293542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3466843', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1268, 'n_words': 435}