Ejemplo n.º 1
0
TEST(Board, block_refCount) {
  int init_array[] = {
    3,3,3,3,3,3,3,3,3,3,3,
    3,0,1,1,1,0,0,0,0,0,3,
    3,1,2,2,1,0,0,0,2,0,3,
    3,0,1,2,2,1,0,0,0,0,3,
    3,0,1,2,0,0,0,0,0,0,3,
    3,0,0,1,0,1,0,0,0,0,3,
    3,0,0,0,0,0,0,0,0,0,3,
    3,2,2,2,0,0,0,0,0,0,3,
    3,1,1,1,2,0,0,0,1,0,3,
    3,1,2,0,0,0,0,0,0,0,3,
    3,3,3,3,3,3,3,3,3,3,3
  };
  Board board(9, init_array);

  EXPECT_EQ(1, board.getBelongBlock(0,1)->refCount());
  EXPECT_EQ(4, board.getBelongBlock(1,0)->refCount());
  EXPECT_EQ(1, board.getBelongBlock(2,4)->refCount());
  EXPECT_EQ(1, board.getBelongBlock(4,4)->refCount());

  board.put(3,4,1);
  EXPECT_EQ(4, board.getBelongBlock(3,4)->refCount());
  board.undo();
  EXPECT_EQ(1, board.getBelongBlock(2,4)->refCount());
  EXPECT_EQ(1, board.getBelongBlock(4,4)->refCount());

  BlockPtr oldBlock = board.getBelongBlock(1,1);
  EXPECT_EQ(5, oldBlock->refCount());
  board.put(3,3,1);
  EXPECT_EQ(1, oldBlock->refCount());
  board.undo();
  EXPECT_EQ(5, oldBlock->refCount());
}
Ejemplo n.º 2
0
TEST(Board, refCount_test_for_snapshot) {
  int init_array[] = {
    3,3,3,3,3,3,3,3,3,3,3,
    3,0,1,1,1,0,0,0,0,0,3,
    3,1,2,2,1,0,0,0,2,0,3,
    3,0,1,2,2,1,1,0,0,0,3,
    3,0,1,2,0,0,0,0,0,0,3,
    3,0,0,1,1,1,0,0,0,0,3,
    3,0,0,0,0,0,0,0,0,0,3,
    3,0,0,0,0,0,0,0,0,0,3,
    3,0,0,1,0,0,0,0,1,0,3,
    3,0,0,0,0,0,0,0,0,0,3,
    3,3,3,3,3,3,3,3,3,3,3
  };
  Board board(9, init_array);

  board.put(5,3,2);
  EXPECT_EQ(2, board.getBelongBlock(5,3)->refCount());
  board.put(5,4,1);
  EXPECT_EQ(5, board.getBelongBlock(5,4)->refCount());
  board.put(3,3,2);
  EXPECT_EQ(7, board.getBelongBlock(3,3)->refCount());
  BlockPtr old = board.getBelongBlock(3,3);
  board.put(4,3,1);
  EXPECT_EQ(9, board.getBelongBlock(4,3)->refCount());
  EXPECT_EQ(2, old->refCount());
  board.takeSnapshot();
  board.put(3,3,2);
  board.put(3,2,1);
  board.restoreStateFromSnapshot();
  EXPECT_EQ(9, board.getBelongBlock(4,3)->refCount());
  board.undo();
  EXPECT_EQ(2, board.getBelongBlock(4,2)->refCount());
  EXPECT_EQ(5, board.getBelongBlock(4,4)->refCount());
  EXPECT_EQ(7, board.getBelongBlock(3,3)->refCount());
}