<commit_before>$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')

require 'knights_tour'

include KnightsTour

describe Application do
  it "should accept dimensions greater than zero" do
    lambda { Application.new(-1) }.should raise_error(ArgumentError)
    lambda { Application.new(0)  }.should raise_error(ArgumentError)
    lambda { Application.new(1)  }.should_not raise_error(ArgumentError)
    lambda { Application.new(8)  }.should_not raise_error(ArgumentError)
  end

  it "should solve dimension of 1" do
    result = Application.new(1).solve
    result.to_s.should == <<-END
+--+
| 1|
+--+
    END
  end

  it "should solve dimension of 4" do
    result = Application.new(4).solve
    result.to_s.should =~ /^(\+--\+--\+--\+--\+\n(\|\w*\d+){4}\|\n){4}\+--\+--\+--\+--\+\n$/
  end
end

describe StringResult, "with trivial length" do
  before(:each) do
    @result = StringResult.new([[1]])
  end

  it "should show the result correctly" do
    @result.to_s.should == <<-END
+--+
| 1|
+--+
    END
  end
end

describe StringResult, "with non-trivial length" do
  before(:each) do
    @result = StringResult.new([[1, 2, 3], [42, 56, 69], [7, 8, 9]])
  end

  it "should show the result correctly" do
    @result.to_s.should == <<-END
+--+--+--+
| 1| 2| 3|
+--+--+--+<commit_msg>Fixed a bug in spec.<commit_after>$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')

require 'knights_tour'

include KnightsTour

describe Application do
  it "should accept dimensions greater than zero" do
    lambda { Application.new(-1) }.should raise_error(ArgumentError)
    lambda { Application.new(0)  }.should raise_error(ArgumentError)
    lambda { Application.new(1)  }.should_not raise_error(ArgumentError)
    lambda { Application.new(8)  }.should_not raise_error(ArgumentError)
  end

  it "should solve dimension of 1" do
    result = Application.new(1).solve
    result.to_s.should == <<-END
+--+
| 1|
+--+
    END
  end

  it "should solve dimension of 4" do
    result = Application.new(4).solve
    result.to_s.should =~ /^(\+--\+--\+--\+--\+\n(\|\s*\d+){4}\|\n){4}\+--\+--\+--\+--\+\n$/
  end
end

describe StringResult, "with trivial length" do
  before(:each) do
    @result = StringResult.new([[1]])
  end

  it "should show the result correctly" do
    @result.to_s.should == <<-END
+--+
| 1|
+--+
    END
  end
end

describe StringResult, "with non-trivial length" do
  before(:each) do
    @result = StringResult.new([[1, 2, 3], [42, 56, 69], [7, 8, 9]])
  end

  it "should show the result correctly" do
    @result.to_s.should == <<-END
+--+--+--+
| 1| 2| 3|
+--+--+--+
{'fraction_non_alphanumeric': 0.18921001926782274, 'fraction_numerical': 0.02157996146435453, 'mean_word_length': 3.031055900621118, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3483778', 'n_tokens_mistral': 991, 'n_tokens_neox': 930, 'n_words': 236}