local Pos = require("nvim-treeclimber.pos")
local assert = require("luassert")

describe("eq/2", function()
	it("is true when the positions are the same", function()
		assert.is_true(Pos.eq(Pos:new(0, 0), Pos:new(0, 0)))
	end)

	it("is false when the positions differ", function()
		assert.is_false(Pos.eq(Pos:new(0, 1), Pos:new(0, 0)))
		assert.is_false(Pos.eq(Pos:new(1, 0), Pos:new(0, 0)))
	end)
end)

describe("gt/2", function ()
	it("is true when the first position is greater than the second", function()
		assert.is_true(Pos.gt(Pos:new(1, 1), Pos:new(0, 0)))
		assert.is_true(Pos.gt(Pos:new(1, 0), Pos:new(0, 0)))
		assert.is_true(Pos.gt(Pos:new(1, 0), Pos:new(0, 1)))
	end)

	it("is false when the first position is less than the second", function()
		assert.is_false(Pos.gt(Pos:new(0, 0), Pos:new(0, 1)))
		assert.is_false(Pos.gt(Pos:new(0, 0), Pos:new(1, 0)))
		assert.is_false(Pos.gt(Pos:new(0, 1), Pos:new(1, 0)))
	end)

	it("is false when the positions are the same", function()
		assert.is_false(Pos.gt(Pos:new(0, 0), Pos:new(0, 0)))
	end)
end)

describe("lt/2", function ()
	it("is true when the first position is less than the second", function()
		assert.is_true(Pos.lt(Pos:new(0, 0), Pos:new(1, 0)))
		assert.is_true(Pos.lt(Pos:new(0, 0), Pos:new(0, 1)))
		assert.is_true(Pos.lt(Pos:new(0, 0), Pos:new(1, 1)))
	end)

	it("is false when the first position is greater than the second", function()
		assert.is_false(Pos.lt(Pos:new(1, 0), Pos:new(0, 0)))
		assert.is_false(Pos.lt(Pos:new(0, 1), Pos:new(0, 0)))
		assert.is_false(Pos.lt(Pos:new(1, 1), Pos:new(0, 0)))
	end)
end)

describe("a < b", function ()
	it("is the same as lt", function()
		assert.is_true(Pos:new(0, 0) < Pos:new(1, 0))
		assert.is_true(Pos:new(0, 0) < Pos:new(0, 1))
		assert.is_true(Pos:new(0, 0) < Pos:new(1, 1))

		assert.is_false(Pos:new(1, 0) < Pos:new(0, 0))
		assert.is_false(Pos:new(0, 1) < Pos:new(0, 0))
		assert.is_false(Pos:new(1, 1) < Pos:new(0, 0))
	end)
end)

describe("a > b", function ()
	it("is the same as gt", function()
		assert.is_false(Pos:new(0, 0) > Pos:new(1, 0))
		assert.is_false(Pos:new(0, 0) > Pos:new(0, 1))
		assert.is_false(Pos:new(0, 0) > Pos:new(1, 1))

		assert.is_true(Pos:new(1, 0) > Pos:new(0, 0))
		assert.is_true(Pos:new(0, 1) > Pos:new(0, 0))
		assert.is_true(Pos:new(1, 1) > Pos:new(0, 0))
	end)
end)

describe("a * b", function ()
	it("multiplies the position by a scalar", function()
		assert.are.same(Pos:new(0, 0), Pos:new(0, 0) * 1)
		--
		assert.are.same(Pos:new(0, 0), Pos:new(1, 1) * 0)
		assert.are.same(Pos:new(1, 1), Pos:new(1, 1) * 1)
		assert.are.same(Pos:new(2, 2), Pos:new(1, 1) * 2)

		assert.are.same(Pos:new(2, 4), Pos:new(1, 2) * 2)
	end)
end)

describe("a / b", function ()
	it("divides the position by a scalar", function ()
		assert.are.same(Pos:new(0, 0), Pos:new(0, 0) / 1)
		assert.are.same(Pos:new(1, 1), Pos:new(1, 1) / 1)
		assert.are.same(Pos:new(1, 1), Pos:new(2, 2) / 2)
		assert.are.same(Pos:new(1, 2), Pos:new(2, 4) / 2)
	end)
end)
