<commit_before>require 'minitest/autorun'
require_relative '../lib/grid.rb'
require_relative '../lib/block.rb'
require_relative '../../mvGraph/lib/mvGraph.rb'

class TestGrid < MiniTest::Unit::TestCase
  def setup
    blocks = []
    blocks << Block.new(1)
    blocks << Block.new(2)
    blocks << Block.new(3)
    blocks << Block.new(4)
    blocks << Block.new(5)
    blocks << Block.new(6)
    blocks << Block.new(7)
    blocks << Block.new(8)
    blocks << Block.new(-1)
    @grid = Grid.new(3, 3, blocks)
  end

  def setup_bfs_grid
    blocks = []
    blocks << Block.new(1)
    blocks << Block.new(2)
    blocks << Block.new(3)
    blocks << Block.new(4)
    blocks << Block.new(5)
    blocks << Block.new(6)
    blocks << Block.new(7)
    blocks << Block.new(-1)
    blocks << Block.new(8)
    @bfs_grid = Grid.new(3, 3, blocks)
  end
  
  def setup_alternate_grid
    blocks = []
    blocks << Block.new(-1)
    blocks << Block.new(1)
    blocks << Block.new(2)
    blocks << Block.new(3)
    blocks << Block.new(4)
    blocks << Block.new(5)
    blocks << Block.new(6)
    blocks << Block.new(7)
    blocks << Block.new(8)
    @alternate_grid = Grid.new(3, 3, blocks)
  end

  def test_create_grid
    assert @grid
    assert_equal @grid.block(0, 0), Block.new(1)
    assert_equal @grid.block(1, 0), Block.new(2)
    assert_equal @grid.block(2, 0), Block.new(3)
    assert_equal @grid.block(0, 1), Block.new(4)
    assert_equal @grid.block(1, 1), Block.new(5)
    assert_equal @grid.block(2, 1), Block.new(6)
    assert_equal @grid.block(0, 2), Block.new(7)
    assert_equal @grid.block(1, 2), Block.new(8)
    assert_equal @grid.block(2, 2), Block.new(-1)
  end

  def test_out_of_bounds_block
    refute @grid.block(100, 100)
    refute @grid.block(0, 100)
    refute @grid.block(1000, 0)
    refute @grid.block(3, 0)
    refute @grid.block(0, 3)
    refute @grid.block(-1, 0)
    refute @grid.block(0, -1)
  end

  def test_next_state
    states = @grid.next_states
    states.each do |state|
      refute state.block(2, 2) == Block.new(-1), "Grid location 2, 2 should not be -1 for each state returned from next_states."
    end
  end

  def test_to_s
    #puts @grid
  end

  def test_equal
    blocks = []
    blocks << Block.new(1)
    blocks << Block.new(2)
    blocks << Block.new(3)
    blocks << Block.new(4)
    blocks << Block.new(5)
    blocks << Block.new(6)
    blocks << Block.new(7)
    blocks << Block.new(8)
    blocks << Block.new(-1)
    other_grid = Grid.new(3, 3, blocks)
    blocks2 = []
    blocks2 << Block.new(5)
    blocks2 << Block.new(2)
    blocks2 << Block.new(3)
    blocks2 << Block.new(4)
    blocks2 << Block.new(1)
    blocks2 << Block.new(6)
    blocks2 << Block.new(7)
    blocks2 << Block.new(8)
    blocks2 << Block.new(-1)
    other_grid2 = Grid.new(3, 3, blocks2)
    assert @grid == other_grid, "Grids are not equal when they should be."
    assert @grid.eql?(other_grid), "Grids are not equal when they should be."
    refute @grid == other_grid2, "Grids are equal when they are two different grids."
    refute @grid.eql?(other_grid2), "Grids are equal when they are two different grids."
  end

  def test_bfs_puzzle_search
    setup_bfs_grid
    @graph = Graph.new
    @graph.add_vertex(@grid)
    @graph.search(@grid, "fifo", :next_states, @bfs_grid)  
  end

  #def test_randomize
  #  @grid.randomize
  #  refute @grid.block(0, 0) == Block.new(1) and
  #  @grid.block(1, 0) == Block.new(2) and
  #  @grid.block(2, 0) == Block.new(3) and
  #  @grid.block(0, 1) == Block.new(4) and
  #  @grid.block(1, 1) == Block.new(5) and
  #  @grid.block(2, 1) == Block.new(6) and
  #  @grid.block(0, 2) == Block.new(7) and 
  #  @grid.block(1, 2) == Block.new(8) and
  #  @grid.block(2, 2) == Block.new(nil)
  #end
  
  def test_is_invalid_move?
    assert @grid.is_invalid_move?(2, 2, "down", @grid.rows), "Should be able to slide down from current position (0,0)"
    assert @grid.is_invalid_move?(2, 2, "right", @grid.rows), "Should be able to slide right from current position (0,0)"
    refute @grid.is_invalid_move?(2, 2, "up", @grid.rows), "Shouldn't be able to slide up from current position (0,0)"
    refute @grid.is_invalid_move?(2, 2, "left", @grid.rows), "Shouldn't be able to slide left from current position (0,0)"
    setup_alternate_grid<commit_msg>Added dfs test.<commit_after>require 'minitest/autorun'
require_relative '../lib/grid.rb'
require_relative '../lib/block.rb'
require_relative '../../mvGraph/lib/mvGraph.rb'

class TestGrid < MiniTest::Unit::TestCase
  def setup
    blocks = []
    blocks << Block.new(1)
    blocks << Block.new(2)
    blocks << Block.new(3)
    blocks << Block.new(4)
    blocks << Block.new(5)
    blocks << Block.new(6)
    blocks << Block.new(7)
    blocks << Block.new(8)
    blocks << Block.new(-1)
    @grid = Grid.new(3, 3, blocks)
  end

  def setup_bfs_grid
    blocks = []
    blocks << Block.new(1)
    blocks << Block.new(2)
    blocks << Block.new(3)
    blocks << Block.new(4)
    blocks << Block.new(5)
    blocks << Block.new(6)
    blocks << Block.new(7)
    blocks << Block.new(-1)
    blocks << Block.new(8)
    @bfs_grid = Grid.new(3, 3, blocks)
  end
  
  def setup_alternate_grid
    blocks = []
    blocks << Block.new(-1)
    blocks << Block.new(1)
    blocks << Block.new(2)
    blocks << Block.new(3)
    blocks << Block.new(4)
    blocks << Block.new(5)
    blocks << Block.new(6)
    blocks << Block.new(7)
    blocks << Block.new(8)
    @alternate_grid = Grid.new(3, 3, blocks)
  end

  def test_create_grid
    assert @grid
    assert_equal @grid.block(0, 0), Block.new(1)
    assert_equal @grid.block(1, 0), Block.new(2)
    assert_equal @grid.block(2, 0), Block.new(3)
    assert_equal @grid.block(0, 1), Block.new(4)
    assert_equal @grid.block(1, 1), Block.new(5)
    assert_equal @grid.block(2, 1), Block.new(6)
    assert_equal @grid.block(0, 2), Block.new(7)
    assert_equal @grid.block(1, 2), Block.new(8)
    assert_equal @grid.block(2, 2), Block.new(-1)
  end

  def test_out_of_bounds_block
    refute @grid.block(100, 100)
    refute @grid.block(0, 100)
    refute @grid.block(1000, 0)
    refute @grid.block(3, 0)
    refute @grid.block(0, 3)
    refute @grid.block(-1, 0)
    refute @grid.block(0, -1)
  end

  def test_next_state
    states = @grid.next_states
    states.each do |state|
      refute state.block(2, 2) == Block.new(-1), "Grid location 2, 2 should not be -1 for each state returned from next_states."
    end
  end

  def test_to_s
    #puts @grid
  end

  def test_equal
    blocks = []
    blocks << Block.new(1)
    blocks << Block.new(2)
    blocks << Block.new(3)
    blocks << Block.new(4)
    blocks << Block.new(5)
    blocks << Block.new(6)
    blocks << Block.new(7)
    blocks << Block.new(8)
    blocks << Block.new(-1)
    other_grid = Grid.new(3, 3, blocks)
    blocks2 = []
    blocks2 << Block.new(5)
    blocks2 << Block.new(2)
    blocks2 << Block.new(3)
    blocks2 << Block.new(4)
    blocks2 << Block.new(1)
    blocks2 << Block.new(6)
    blocks2 << Block.new(7)
    blocks2 << Block.new(8)
    blocks2 << Block.new(-1)
    other_grid2 = Grid.new(3, 3, blocks2)
    assert @grid == other_grid, "Grids are not equal when they should be."
    assert @grid.eql?(other_grid), "Grids are not equal when they should be."
    refute @grid == other_grid2, "Grids are equal when they are two different grids."
    refute @grid.eql?(other_grid2), "Grids are equal when they are two different grids."
  end

  def test_bfs_puzzle_search
    setup_bfs_grid
    @graph = Graph.new
    @graph.add_vertex(@grid)
    @graph.search(@grid, "fifo", :next_states, @bfs_grid)  
  end

  def test_dfs_puzzle_search
    setup_bfs_grid
    @graph = Graph.new
    @graph.add_vertex(@grid)
    @graph.search(@grid, "lifo", :next_states, @bfs_grid)  
  end


  #def test_randomize
  #  @grid.randomize
  #  refute @grid.block(0, 0) == Block.new(1) and
  #  @grid.block(1, 0) == Block.new(2) and
  #  @grid.block(2, 0) == Block.new(3) and
  #  @grid.block(0, 1) == Block.new(4) and
  #  @grid.block(1, 1) == Block.new(5) and
  #  @grid.block(2, 1) == Block.new(6) and
  #  @grid.block(0, 2) == Block.new(7) and 
  #  @grid.block(1, 2) == Block.new(8) and
  #  @grid.block(2, 2) == Block.new(nil)
  #end
  
  def test_is_invalid_move?
    assert @grid.is_invalid_move?(2, 2, "down", @grid.rows), "Should be able to slide down from current position (0,0)"
    assert @grid.is_invalid_move?(2, 2, "right", @grid.rows), "Should be able to slide right from current position (0,0)"
    refute @grid.is_invalid_move?(2, 2, "up", @grid.rows), "Shouldn't be able to slide up from current position (0,0)"
    refute @grid.is_invalid_move?(2, 2, "left", @grid.rows), "Shouldn't be able to slide left from current position (0,0)"
    setup_alternate_grid
{'fraction_non_alphanumeric': 0.15904956798544792, 'fraction_numerical': 0.03797180536607549, 'mean_word_length': 3.0113999088007297, 'pattern_counts': {'":': 0, '<': 185, '<?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': '720229', 'n_tokens_mistral': 3448, 'n_tokens_neox': 3342, 'n_words': 798}