<commit_before>require 'spec_helper'
require 'priority_calculator'

describe PriorityCalculator do

  let(:task) { FactoryGirl.create(:task) }

  context "when calculating a task's priority" do
    
    context "and the task does not have a due date" do
      it "should be 0" do
        p = PriorityCalculator.new(task)
        expect(p.calculate).to eq(0)
      end
    end

    context "and the due date is in the past" do
      it "should be 50" do
        past = FactoryGirl.build(:task, due_date: 1.day.ago)
        p = PriorityCalculator.new(past)
        expect(p.calculate).to eq(50)
      end
    end

    context "and the due date is <= 1 week from now" do
      it "should be 25" do
        future = FactoryGirl.build(:task, due_date: 1.week.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(25)
      end
    end

    context "and the due date is between 1 week from now and 1 month from now" do
      it "should be 12" do
        future = FactoryGirl.build(:task, due_date: 1.month.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(12)
      end
    end

    context "and the due date is between 1 month and 3 months from now" do
      it "should be 9" do
        future = FactoryGirl.build(:task, due_date: 3.months.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(9)
      end
    end

    context "and the due date is between 3 months and 6 months from now" do
      it "should be 6" do
        future = FactoryGirl.build(:task, due_date: 6.months.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(6)
      end
    end

    context "and the due date is between 6 months and 9 months from now" do
      it "should be 3" do
        future = FactoryGirl.build(:task, due_date: 9.months.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(3)
      end
    end

    context "and the due date is between 9 months and 10 months from now" do
      it "should be 2" do
        future = FactoryGirl.build(:task, due_date: 10.months.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(2)
      end
    end

    context "and the due date is between 10 months and 1 year from now" do
      it "should be 1" do
        future = FactoryGirl.build(:task, due_date: 1.year.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(1)
      end
    end

    context "and the due date is more than 1 year ago" do
      it "should be 0" do
        future = FactoryGirl.build(:task, due_date: 2.years.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(0)
      end
    end<commit_msg>Set Priority When Task Status is 0<commit_after>require 'spec_helper'
require 'priority_calculator'

describe PriorityCalculator do

  let(:task) { FactoryGirl.create(:task) }

  context "when calculating a task's priority" do
    
    context "and the task does not have a due date" do
      it "should be 0" do
        p = PriorityCalculator.new(task)
        expect(p.calculate).to eq(0)
      end
    end

    context "and the due date is in the past" do
      it "should be 50" do
        past = FactoryGirl.build(:task, due_date: 1.day.ago)
        p = PriorityCalculator.new(past)
        expect(p.calculate).to eq(50)
      end
    end

    context "and the due date is <= 1 week from now" do
      it "should be 25" do
        future = FactoryGirl.build(:task, due_date: 1.week.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(25)
      end
    end

    context "and the due date is between 1 week from now and 1 month from now" do
      it "should be 12" do
        future = FactoryGirl.build(:task, due_date: 1.month.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(12)
      end
    end

    context "and the due date is between 1 month and 3 months from now" do
      it "should be 9" do
        future = FactoryGirl.build(:task, due_date: 3.months.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(9)
      end
    end

    context "and the due date is between 3 months and 6 months from now" do
      it "should be 6" do
        future = FactoryGirl.build(:task, due_date: 6.months.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(6)
      end
    end

    context "and the due date is between 6 months and 9 months from now" do
      it "should be 3" do
        future = FactoryGirl.build(:task, due_date: 9.months.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(3)
      end
    end

    context "and the due date is between 9 months and 10 months from now" do
      it "should be 2" do
        future = FactoryGirl.build(:task, due_date: 10.months.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(2)
      end
    end

    context "and the due date is between 10 months and 1 year from now" do
      it "should be 1" do
        future = FactoryGirl.build(:task, due_date: 1.year.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(1)
      end
    end

    context "and the due date is more than 1 year ago" do
      it "should be 0" do
        future = FactoryGirl.build(:task, due_date: 2.years.from_now)
        p = PriorityCalculator.new(future)
        expect(p.calculate).to eq(0)
      end

      context "and the task status is 0" do
        it "should be 0" do
          future = FactoryGirl.build(:task, due_date: 2.years.from_now, status: 0)
          p = PriorityCalculator.new(future)
          expect(p.calculate).to eq(0)
        end
      end
    end
{'fraction_non_alphanumeric': 0.08759249698847014, 'fraction_numerical': 0.018929616245052485, 'mean_word_length': 2.3041500852757246, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2998865', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1786, 'n_words': 626}