<commit_before>require 'spec_helper.rb'

module Rubaship
  describe Pos do
    it "accepts a string with a valid position" do
      Pos.new("C3:V").should == [:C, 3, :V]
    end

    it "accepts a sequence of Row, Col and Ori objects" do
      Pos.new(Row.new(:A), Col.new(3), Ori.new(:H)).should == [:A, 3, :H]
    end

    it "accepts a sequence of :D, 3, :V" do
      Pos.new(:D, 3, :V).should == [:D, 3, :V]
    end

    it "accepts a range row :B..:E and a column 3 without an orientation" do
      Pos.new(:B..:E, 3).should == [:B..:E, 3, :V]
    end

    it "forces the orientation to :H when passed a column range" do
      lambda { Pos.new(:B, 3..7, :V) }.should raise_error(
        InvalidPositionArgument,
        "Either row or col must be a Range matching the orientation argument if any."
      )
    end

    it "raises an InvalidPositionArgument when passed :C..:E, 4..7" do
      lambda { Pos.new(:C..:E, 4..7) }.should raise_error(
        InvalidPositionArgument,
        "Either row or col must be a Range matching the orientation argument if any."
      )
    end

    it "raises an InvalidPositionArgument when passed :C, 3" do
      lambda { Pos.new(:C, 3) }.should raise_error(
        InvalidPositionArgument,
        "Either row or col must be a Range matching the orientation argument if any."
      )
    end

    context "for a sample position of :B, 8, :H" do
      before(:each) do
        @pos = Pos.new(:B, 8, :H)
      end

      describe "#row" do
        it "returns :B" do
          @pos.row.should == Row.new(:B)
        end
      end

      describe "#col" do
        it "returns 8" do
          @pos.col.should == Col.new(8)
        end
      end

      describe "#ori" do
        it "returns :H" do
          @pos.ori.should == Ori.new(:H)
        end
      end

      describe "#rangify!" do
        it "returns the position rangified :B, 8..10, :H, when passed 3" do
          @pos.rangify!(3).should == [:B, 8..10, :H]
        end

        it "returns the position rangified :B, 8..10, :H, when passed a destroyer" do
          @pos.rangify!(Ship.create(:D)).should == [:B, 8..10, :H]
        end

        it "changes the column from 8 to 8..9 when passed 2" do
          lambda {
            @pos.rangify!(2)
          }.should change(@pos, :to_a).from([:B, 8, :H]).to([:B, 8..9, :H])
        end

        it "changes the column range? status from false to true" do
          lambda {
            @pos.rangify!(3)
          }.should change(@pos.col, :range?).from(false).to(true)
        end
      end

      describe "#to_s" do
        it "returns B8:H" do
          @pos.to_s.should == "B8:H"
        end
      end

      describe "#==" do
        it "should == [:B, 8, :H]" do
          @pos.should == [:B, 8, :H]
        end

        it "should == \"B8:H\"" do
          @pos.should == "B8:H"
        end

        it "should == Pos.new(:B, 8, :H)" do
          @pos.should == Pos.new(:B, 8, :H)
        end

        it "should == [Row.new(:B), Col.new(8), Ori.new(:H)]" do
          @pos.should == [Row.new(:B), Col.new(8), Ori.new(:H)]
        end
      end
    end

    context "for a sample position of :G, 7, :V" do
      before(:each) do
        @pos = Pos.new(:G, 7, :V)
      end

      describe "#row" do
        it "returns :G" do
          @pos.row.should == Row.new(:G)
        end
      end

      describe "#col" do
        it "returns 7" do
          @pos.col.should == Col.new(7)
        end
      end

      describe "#ori" do
        it "returns :V" do
          @pos.ori.should == Ori.new(:V)
        end
      end

      describe "#range?" do
        it "returns false" do
          @pos.range?.should be false
        end
      end

      describe "#rangify!" do
        it "returns the rangified position :G..:J, 7 when passed 4" do
          @pos.rangify!(4).should == [:G..:J, 7, :V]
        end

        it "changes the row from :G to :G..:I when passed 3" do
          lambda {
            @pos.rangify!(3)
          }.should change(@pos, :to_a).from([:G, 7, :V]).to([:G..:I, 7, :V])
        end

        it "changes the row range? status from false to true" do
          lambda {
            @pos.rangify!(3)
          }.should change(@pos.row, :range?).from(false).to(true)
        end
      end

      describe "#to_s" do
        it "returns G7:V" do
          @pos.to_s.should == "G7:V"
        end
      end

      describe "#valid?" do
        it "returns true when passed a Battleship" do
          @pos.valid?(Ship.create(:B)).should be true
        end

        it "returns false when passed an Aircraft Carrier" do
          @pos.valid?(Ship.create(:A)).should be false
        end
      end

      describe "#==" do
        it "should == [:G, 7, :V]" do
          @pos.should == [:G, 7, :V]
        end

        it "should == \"G7:V\"" do
          @pos.should == "G7:V"
        end

        it "should == Pos.new(:G, 7, :V)" do
          @pos.should == Pos.new(:G, 7, :V)
        end

        it "should == [Row.new(:G), Col.new(7), Ori.new(:V)]" do
          @pos.should == [Row.new(:G), Col.new(7), Ori.new(:V)]
        end
      end
    end

    describe ".is_valid?" do
      it "returns true when passed :C, 4, :H" do
        Pos.is_valid?(:C, 4, :V).should be true
      end

      it "returns true when passed :D, 10, :V" do
        Pos.is_valid?(:D, 10, :V).should be true
      end

      it "returns true when passed :D..:F, 6, :V" do
        Pos.is_valid?(:D..:F, 6, :V).should be true
      end

      it "returns true when passed :D, 4..7, :H" do
        Pos.is_valid?(:D, 4..7, :H).should be true
      end

      it "returns true when passed :D, 4..7 with no orientation" do
        Pos.is_valid?(:D, 4..7).should be true
      end

      it "returns false when passed :K, 3, :H" do
        Pos.is_valid?(:K, 3, :H).should be false
      end

      it "returns false when passed :A..:D, 5, :H" do
        Pos.is_valid?(:A..:D, 5, :H).should be false
      end

      it "returns false when passed :C, 5..8, :V" do<commit_msg>Adds sample range position to the specifications<commit_after>require 'spec_helper.rb'

module Rubaship
  describe Pos do
    it "accepts a string with a valid position" do
      Pos.new("C3:V").should == [:C, 3, :V]
    end

    it "accepts a sequence of Row, Col and Ori objects" do
      Pos.new(Row.new(:A), Col.new(3), Ori.new(:H)).should == [:A, 3, :H]
    end

    it "accepts a sequence of :D, 3, :V" do
      Pos.new(:D, 3, :V).should == [:D, 3, :V]
    end

    it "accepts a range row :B..:E and a column 3 without an orientation" do
      Pos.new(:B..:E, 3).should == [:B..:E, 3, :V]
    end

    it "forces the orientation to :H when passed a column range" do
      lambda { Pos.new(:B, 3..7, :V) }.should raise_error(
        InvalidPositionArgument,
        "Either row or col must be a Range matching the orientation argument if any."
      )
    end

    it "raises an InvalidPositionArgument when passed :C..:E, 4..7" do
      lambda { Pos.new(:C..:E, 4..7) }.should raise_error(
        InvalidPositionArgument,
        "Either row or col must be a Range matching the orientation argument if any."
      )
    end

    it "raises an InvalidPositionArgument when passed :C, 3" do
      lambda { Pos.new(:C, 3) }.should raise_error(
        InvalidPositionArgument,
        "Either row or col must be a Range matching the orientation argument if any."
      )
    end

    context "for a sample position of :B, 8, :H" do
      before(:each) do
        @pos = Pos.new(:B, 8, :H)
      end

      describe "#row" do
        it "returns :B" do
          @pos.row.should == Row.new(:B)
        end
      end

      describe "#col" do
        it "returns 8" do
          @pos.col.should == Col.new(8)
        end
      end

      describe "#ori" do
        it "returns :H" do
          @pos.ori.should == Ori.new(:H)
        end
      end

      describe "#rangify!" do
        it "returns the position rangified :B, 8..10, :H, when passed 3" do
          @pos.rangify!(3).should == [:B, 8..10, :H]
        end

        it "returns the position rangified :B, 8..10, :H, when passed a destroyer" do
          @pos.rangify!(Ship.create(:D)).should == [:B, 8..10, :H]
        end

        it "changes the column from 8 to 8..9 when passed 2" do
          lambda {
            @pos.rangify!(2)
          }.should change(@pos, :to_a).from([:B, 8, :H]).to([:B, 8..9, :H])
        end

        it "changes the column range? status from false to true" do
          lambda {
            @pos.rangify!(3)
          }.should change(@pos.col, :range?).from(false).to(true)
        end
      end

      describe "#to_s" do
        it "returns B8:H" do
          @pos.to_s.should == "B8:H"
        end
      end

      describe "#==" do
        it "should == [:B, 8, :H]" do
          @pos.should == [:B, 8, :H]
        end

        it "should == \"B8:H\"" do
          @pos.should == "B8:H"
        end

        it "should == Pos.new(:B, 8, :H)" do
          @pos.should == Pos.new(:B, 8, :H)
        end

        it "should == [Row.new(:B), Col.new(8), Ori.new(:H)]" do
          @pos.should == [Row.new(:B), Col.new(8), Ori.new(:H)]
        end
      end
    end

    context "for a sample position of :G, 7, :V" do
      before(:each) do
        @pos = Pos.new(:G, 7, :V)
      end

      describe "#row" do
        it "returns :G" do
          @pos.row.should == Row.new(:G)
        end
      end

      describe "#col" do
        it "returns 7" do
          @pos.col.should == Col.new(7)
        end
      end

      describe "#ori" do
        it "returns :V" do
          @pos.ori.should == Ori.new(:V)
        end
      end

      describe "#range?" do
        it "returns false" do
          @pos.range?.should be false
        end
      end

      describe "#rangify!" do
        it "returns the rangified position :G..:J, 7 when passed 4" do
          @pos.rangify!(4).should == [:G..:J, 7, :V]
        end

        it "changes the row from :G to :G..:I when passed 3" do
          lambda {
            @pos.rangify!(3)
          }.should change(@pos, :to_a).from([:G, 7, :V]).to([:G..:I, 7, :V])
        end

        it "changes the row range? status from false to true" do
          lambda {
            @pos.rangify!(3)
          }.should change(@pos.row, :range?).from(false).to(true)
        end
      end

      describe "#to_s" do
        it "returns G7:V" do
          @pos.to_s.should == "G7:V"
        end
      end

      describe "#valid?" do
        it "returns true when passed a Battleship" do
          @pos.valid?(Ship.create(:B)).should be true
        end

        it "returns false when passed an Aircraft Carrier" do
          @pos.valid?(Ship.create(:A)).should be false
        end
      end

      describe "#==" do
        it "should == [:G, 7, :V]" do
          @pos.should == [:G, 7, :V]
        end

        it "should == \"G7:V\"" do
          @pos.should == "G7:V"
        end

        it "should == Pos.new(:G, 7, :V)" do
          @pos.should == Pos.new(:G, 7, :V)
        end

        it "should == [Row.new(:G), Col.new(7), Ori.new(:V)]" do
          @pos.should == [Row.new(:G), Col.new(7), Ori.new(:V)]
        end
      end
    end

    context "for a sample position with a range of rows :D..:G and 3" do
      before(:each) do
        @pos = Pos.new(:D..:G, 3)
      end

      describe "#row" do
        it "returns :D..:G" do
          @pos.row.should == Row.new(:D..:G)
        end
      end

      describe "#col" do
        it "returns 3" do
          @pos.col.should == Col.new(3)
        end
      end

      describe "#ori" do
        it "returns :V" do
          @pos.ori.should == Ori.new(:V)
        end
      end

      describe "#range?" do
        it "returns true" do
          @pos.range?.should be true
        end
      end

      describe "#rangify!" do
        it "returns the position unchanged since it is already a range" do
          lambda { @pos.rangify!(4) }.should_not change(@pos, :to_a)
        end
      end

      describe "#to_s" do
        it "returns D..G3:V" do
          @pos.to_s.should == "D..G3:V"
        end
      end

      describe "#valid?" do
        it "returns true when passed a Battleship" do
          @pos.valid?(Ship.create(:B)).should be true
        end

        it "returns false when passed an Aircraft Carrier" do
          @pos.valid?(Ship.create(:A)).should be false
        end
      end

      describe "#==" do
        it "should == [:D..:G, 3, :V]" do
          @pos.should == [:D..:G, 3, :V]
        end

        it "should not == \"D3:V\"" do
          @pos.should_not == "D3:V"
        end

        it "should == Pos.new(:D..:G, 3, :V)" do
          @pos.should == Pos.new(:D..:G, 3, :V)
        end

        it "should == Pos.new(:D..:G, 3)" do
          @pos.should == Pos.new(:D..:G, 3)
        end

        it "should == [Row.new(:D..:G), Col.new(3), Ori.new(:V)]" do
          @pos.should == [Row.new(:D..:G), Col.new(3), Ori.new(:V)]
        end
      end
    end

    describe ".is_valid?" do
      it "returns true when passed :C, 4, :H" do
        Pos.is_valid?(:C, 4, :V).should be true
      end

      it "returns true when passed :D, 10, :V" do
        Pos.is_valid?(:D, 10, :V).should be true
      end

      it "returns true when passed :D..:F, 6, :V" do
        Pos.is_valid?(:D..:F, 6, :V).should be true
      end

      it "returns true when passed :D, 4..7, :H" do
        Pos.is_valid?(:D, 4..7, :H).should be true
      end

      it "returns true when passed :D, 4..7 with no orientation" do
        Pos.is_valid?(:D, 4..7).should be true
      end

      it "returns false when passed :K, 3, :H" do
        Pos.is_valid?(:K, 3, :H).should be false
      end

      it "returns false when passed :A..:D, 5, :H" do
        Pos.is_valid?(:A..:D, 5, :H).should be false
      end

      it "returns false when passed :C, 5..8, :V" do
{'fraction_non_alphanumeric': 0.15025906735751296, 'fraction_numerical': 0.015616004605641911, 'mean_word_length': 1.65717017208413, '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': '6399103', 'n_tokens_mistral': 4954, 'n_tokens_neox': 4682, 'n_words': 1536}