]> git.openstreetmap.org Git - rails.git/blobdiff - vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / examples / stories / game-of-life / behaviour / examples / grid_behaviour.rb
diff --git a/vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb b/vendor/gems/rspec-1.1.2/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb
new file mode 100644 (file)
index 0000000..5be3af5
--- /dev/null
@@ -0,0 +1,66 @@
+describe Grid do
+  it 'should be empty when created' do
+    # given
+    expected_contents = [
+      [0, 0, 0],
+      [0, 0, 0]
+    ]
+    grid = Grid.new(2, 3)
+    
+    # when
+    contents = grid.contents
+    
+    # then
+    contents.should == expected_contents
+  end
+  
+  it 'should compare equal based on its contents' do
+    # given
+    grid1 = Grid.new(2, 3)
+    grid2 = Grid.new(2, 3)
+    
+    # then
+    grid1.should == grid2
+  end
+  
+  it 'should be able to replace its contents' do
+    # given
+    grid = Grid.new(2,2)
+    new_contents = [[0,1,0], [1,0,1]]
+    
+    # when
+    grid.contents = new_contents
+    
+    # then
+    grid.contents.should == new_contents
+    grid.rows.should == 2
+    grid.columns.should == 3
+  end
+  
+  it 'should add an organism' do
+    # given
+    grid = Grid.new(2, 2)
+    expected = Grid.new(2, 2)
+    expected.contents = [[1,0],[0,0]]
+    
+    # when
+    grid.create_at(0,0)
+    
+    # then
+    grid.should == expected
+  end
+  
+  it 'should create itself from a string' do
+    # given
+    expected = Grid.new 3, 3
+    expected.create_at(0,0)
+    expected.create_at(1,0)
+    expected.create_at(2,2)
+    
+    # when
+    actual = Grid.from_string "X.. X.. ..X"
+    
+    # then
+    actual.should == expected
+  end
+end