Move point tests

This commit is contained in:
Anton Vakhrushev 2019-10-13 12:35:54 +03:00
parent 0aaab2e131
commit bccff5461d
4 changed files with 28 additions and 15 deletions

View File

@ -3,9 +3,11 @@ require "./spec_helper"
describe Game::Point do
p1 = Game::Point.new(0, 0)
p2 = Game::Point.new(5, 5)
it "can calc distance" do
p1.distance(p2).should eq 10
end
it "can calc reverse destance" do
p2.distance(p1).should eq 10
end

12
spec/point_spec.cr Normal file
View File

@ -0,0 +1,12 @@
require "./spec_helper"
describe Game::Point do
p1 = Game::Point.new(0, 0)
p2 = Game::Point.new(5, 5)
it "can calc distance" do
p1.distance(p2).should eq 10
end
it "can calc reverse destance" do
p2.distance(p1).should eq 10
end
end

View File

@ -1,19 +1,4 @@
module Game
struct Point
property x : Int32
property y : Int32
def initialize(@x : Int32, @y : Int32)
end
getter x
getter y
def distance(other) : Int32
return (other.x - @x).abs + (other.y - @y).abs
end
end
class Map
alias TileRow = Array(Tile)
alias DataArray = Array(TileRow)

14
src/game/point.cr Normal file
View File

@ -0,0 +1,14 @@
struct Game::Point
property x : Int32
property y : Int32
def initialize(@x : Int32, @y : Int32)
end
getter x
getter y
def distance(other) : Int32
return (other.x - @x).abs + (other.y - @y).abs
end
end