<commit_before>require "spec_helper"

RSpec.describe RelativeTime do
  context "given an existing time" do
    before :all do
      @time = Time.new(2000, 1, 1, 3, 45, 00)
    end

    it "calculates a new time before itself" do
      expect(5.minutes.before(@time)).to eq(Time.new(2000, 1, 1, 3, 40, 00))
      expect(5.months.before(@time)).to eq(Time.new(1999, 8, 1, 3, 45, 00))
    end

    it "calculates a new time after itself" do
      expect(5.minutes.after(@time)).to eq(Time.new(2000, 1, 1, 3, 50, 00))
      expect(5.months.after(@time)).to eq(Time.new(2000, 6, 1, 3, 45, 00))
    end

    it "properly handles large periods of time" do
      expect(65.months.before(@time)).to eq(Time.new(1994, 8, 1, 3, 45, 00))
      expect(65.months.after(@time)).to eq(Time.new(2005, 6, 1, 3, 45, 00))
    end
  end

  context "given an odd time case" do
    it "properly calculates the time before it" do
      end_of_march = Time.new(2000, 3, 31, 3, 45, 00)
      expect(
        1.month.before(end_of_march)
      ).to eq(Time.new(2000, 2, 29, 3, 45, 00))
    end

    it "properly calculates the time after it" do
      end_of_january = Time.new(2000, 1, 31, 3, 45, 00)
      expect(
        1.month.after(end_of_january)
      ).to eq(Time.new(2000, 2, 29, 3, 45, 00))
    end
  end

  describe "#to_wall" do
    it "calculates an equivalent WallClock time" do
      expect((5.hours 30.minutes).to_wall).to eq(WallClock.new(5, 30))
    end

    it "raises an error for times beyond 24 hours" do
      expect do
        1.day.to_wall
      end.to raise_error WallClock::TimeOutOfBoundsError

      expect do
        217.hours.to_wall
      end.to raise_error WallClock::TimeOutOfBoundsError

      expect do
        (1.month 3.seconds).to_wall
      end.to raise_error WallClock::TimeOutOfBoundsError
    end
  end

  describe "#to_s" do
    it "converts all units into a string" do
      expect(
        (1.hour 3.minutes 4.seconds).to_s
      ).to eq("1 hour, 3 minutes, 4 seconds")

      expect(
        (1.year 3.months 4.days).to_s(:long)
      ).to eq("1 year, 3 months, 4 days")
    end

    it "converts units into a micro syntax" do
      expect(
        (1.hour 3.minutes 4.seconds).to_s(:micro)
      ).to eq("1h")

      expect(
        (1.year 3.months 4.days).to_s(:micro)
      ).to eq("1y")
    end

    it "converts units into a medium syntax" do
      expect(
        (1.hour 3.minutes 4.seconds).to_s(:short)
      ).to eq("1hr 3min")

      expect(
        (1.year 3.months 4.days).to_s(:short)
      ).to eq("1yr 3mn")
    end
  end

  describe "#average" do
    it "can average from second units to month units" do
      five_weeks = 5.weeks
      expect(five_weeks.get(:seconds)).to eq(3_024_000)

      average = five_weeks.average
      expect(average.get(:seconds)).to eq(394_254)
      expect(average.get(:months)).to eq(1)
    end
  end

  describe "#unaverage" do
    it "can unaverage from month units to second units" do
      expect(2.months.get(:months)).to eq(2)

      unaverage = 2.months.unaverage!
      expect(unaverage.get(:seconds)).to eq(5_259_492)
      expect(unaverage.get(:months)).to eq(0)
    end
  end

  it "can be compared against other `RelativeTime`s" do
    expect(1.minute).to eq(1.minute)
    expect(1.minute).not_to eq(1.hour)

    expect(1.minute).to eq(60.seconds)
    expect(1.week).to eq(7.days)
    expect(12.months).to eq(1.year)
  end
end

RSpec.describe WallClock do
  it "can be created" do
    WallClock.new(12, 30, :pm)<commit_msg>Add specs for `#in_seconds`<commit_after>require "spec_helper"

RSpec.describe RelativeTime do
  context "given an existing time" do
    before :all do
      @time = Time.new(2000, 1, 1, 3, 45, 00)
    end

    it "calculates a new time before itself" do
      expect(5.minutes.before(@time)).to eq(Time.new(2000, 1, 1, 3, 40, 00))
      expect(5.months.before(@time)).to eq(Time.new(1999, 8, 1, 3, 45, 00))
    end

    it "calculates a new time after itself" do
      expect(5.minutes.after(@time)).to eq(Time.new(2000, 1, 1, 3, 50, 00))
      expect(5.months.after(@time)).to eq(Time.new(2000, 6, 1, 3, 45, 00))
    end

    it "properly handles large periods of time" do
      expect(65.months.before(@time)).to eq(Time.new(1994, 8, 1, 3, 45, 00))
      expect(65.months.after(@time)).to eq(Time.new(2005, 6, 1, 3, 45, 00))
    end
  end

  context "given an odd time case" do
    it "properly calculates the time before it" do
      end_of_march = Time.new(2000, 3, 31, 3, 45, 00)
      expect(
        1.month.before(end_of_march)
      ).to eq(Time.new(2000, 2, 29, 3, 45, 00))
    end

    it "properly calculates the time after it" do
      end_of_january = Time.new(2000, 1, 31, 3, 45, 00)
      expect(
        1.month.after(end_of_january)
      ).to eq(Time.new(2000, 2, 29, 3, 45, 00))
    end
  end

  describe "#to_wall" do
    it "calculates an equivalent WallClock time" do
      expect((5.hours 30.minutes).to_wall).to eq(WallClock.new(5, 30))
    end

    it "raises an error for times beyond 24 hours" do
      expect do
        1.day.to_wall
      end.to raise_error WallClock::TimeOutOfBoundsError

      expect do
        217.hours.to_wall
      end.to raise_error WallClock::TimeOutOfBoundsError

      expect do
        (1.month 3.seconds).to_wall
      end.to raise_error WallClock::TimeOutOfBoundsError
    end
  end

  describe "#to_s" do
    it "converts all units into a string" do
      expect(
        (1.hour 3.minutes 4.seconds).to_s
      ).to eq("1 hour, 3 minutes, 4 seconds")

      expect(
        (1.year 3.months 4.days).to_s(:long)
      ).to eq("1 year, 3 months, 4 days")
    end

    it "converts units into a micro syntax" do
      expect(
        (1.hour 3.minutes 4.seconds).to_s(:micro)
      ).to eq("1h")

      expect(
        (1.year 3.months 4.days).to_s(:micro)
      ).to eq("1y")
    end

    it "converts units into a medium syntax" do
      expect(
        (1.hour 3.minutes 4.seconds).to_s(:short)
      ).to eq("1hr 3min")

      expect(
        (1.year 3.months 4.days).to_s(:short)
      ).to eq("1yr 3mn")
    end
  end

  describe "#average" do
    it "can average from second units to month units" do
      five_weeks = 5.weeks
      expect(five_weeks.get(:seconds)).to eq(3_024_000)

      average = five_weeks.average
      expect(average.get(:seconds)).to eq(394_254)
      expect(average.get(:months)).to eq(1)
    end
  end

  describe "#unaverage" do
    it "can unaverage from month units to second units" do
      expect(2.months.get(:months)).to eq(2)

      unaverage = 2.months.unaverage!
      expect(unaverage.get(:seconds)).to eq(5_259_492)
      expect(unaverage.get(:months)).to eq(0)
    end
  end

  describe "#in_seconds" do
    it "converts a `RelativeTime` to seconds" do
      expect(1.second.in_seconds).to eq(1)
      expect((10.minutes 3.seconds).in_seconds).to eq((10 * 60) + 3)
      expect((1.hour 4.minutes).in_seconds).to eq((60 * 60) + (4 * 60))
      expect(3.days.in_seconds).to eq(3 * 24 * 60 * 60)
      expect(2.weeks.in_seconds).to eq(2 * 7 * 24 * 60 * 60)
    end
  end

  it "can be compared against other `RelativeTime`s" do
    expect(1.minute).to eq(1.minute)
    expect(1.minute).not_to eq(1.hour)

    expect(1.minute).to eq(60.seconds)
    expect(1.week).to eq(7.days)
    expect(12.months).to eq(1.year)
  end
end

RSpec.describe WallClock do
  it "can be created" do
    WallClock.new(12, 30, :pm)
{'fraction_non_alphanumeric': 0.1325691166554282, 'fraction_numerical': 0.06446392447741066, 'mean_word_length': 2.5483253588516748, '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': '3477734', 'n_tokens_mistral': 3099, 'n_tokens_neox': 2619, 'n_words': 746}