<commit_before>require_relative '../../spec_helper'

describe Calculator::FlexiRate do
  let(:calculator) { Calculator::FlexiRate.new }
  let(:order) { mock_model Order, :line_items => [mock_model(LineItem, :amount => 10, :quantity => 4), mock_model(LineItem, :amount => 20, :quantity => 6)] }

  context "compute" do
    it "should compute amount correctly when all fees are 0" do
      calculator.compute(order).round(2).should == 0.0
    end

    it "should compute amount correctly when first_item has a value" do
      calculator.stub :preferred_first_item => 1.99
      calculator.compute(order).round(2).should == 1.99
    end

    it "should compute amount correctly when additional_items has a value" do
      calculator.stub :preferred_additional_item => 0.99
      expected = ( order.line_items.sum(&:quantity) - 1) * calculator.preferred_additional_item
      calculator.compute(order).round(2).should == expected.round(2)
    end

    it "should compute amount correctly when additional_items and first_item have values" do
      calculator.stub :preferred_first_item => 1.99, :preferred_additional_item => 0.99
      expected = (( order.line_items.sum(&:quantity) - 1) * calculator.preferred_additional_item) + calculator.preferred_first_item
      calculator.compute(order).round(2).should == expected.round(2)
    end

    it "should compute amount correctly when additional_items and first_item have values AND max items has value" do
      calculator.stub :preferred_first_item => 1.99, :preferred_additional_item => 0.99, :preferred_max_items => 3
      calculator.compute(order).round(2).should == 13.90<commit_msg>Minor flexi_rate_spec tweaks<commit_after>require 'spec_helper'

describe Calculator::FlexiRate do
  let(:calculator) { Calculator::FlexiRate.new }
  let(:order) { mock_model Order, :line_items => [mock_model(LineItem, :amount => 10, :quantity => 4), mock_model(LineItem, :amount => 20, :quantity => 6)] }

  context "compute" do
    it "should compute amount correctly when all fees are 0" do
      calculator.compute(order).round(2).should == 0.0
    end

    it "should compute amount correctly when first_item has a value" do
      calculator.stub :preferred_first_item => 1.0
      calculator.compute(order).round(2).should == 1.0
    end

    it "should compute amount correctly when additional_items has a value" do
      calculator.stub :preferred_additional_item => 1.0
      calculator.compute(order).round(2).should == 9.0
    end

    it "should compute amount correctly when additional_items and first_item have values" do
      calculator.stub :preferred_first_item => 5.0, :preferred_additional_item => 1.0
      calculator.compute(order).round(2).should == 14.0
    end

    it "should compute amount correctly when additional_items and first_item have values AND max items has value" do
      calculator.stub :preferred_first_item => 5.0, :preferred_additional_item => 1.0, :preferred_max_items => 3
      calculator.compute(order).round(2).should == 26.0
{'fraction_non_alphanumeric': 0.10774858663119388, 'fraction_numerical': 0.02693714665779847, 'mean_word_length': 4.098305084745762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '5891881', 'n_tokens_mistral': 970, 'n_tokens_neox': 890, 'n_words': 246}