describe("Modular inverse", function()
	local modular_inverse = require("math.modular_inverse")

	it("should handle general cases", function()
		assert.equal(5, modular_inverse(3, 7))
		assert.equal(4, modular_inverse(-1, 5))
		assert.equal(4, modular_inverse(4, 5))
		assert.equal(4, modular_inverse(9, 5))
		assert.equal(17, modular_inverse(5, 21))
		assert.equal(1, modular_inverse(1, 100))
	end)

	it("should handle cases when inputs are not co-prime", function()
		assert.equal(nil, modular_inverse(2, 2))
		assert.equal(nil, modular_inverse(5, 15))
	end)

	it("should handle cases when modulus is 1", function()
		assert.equal(nil, modular_inverse(-1, 1))
		assert.equal(nil, modular_inverse(0, 1))
		assert.equal(nil, modular_inverse(1, 1))
		assert.equal(nil, modular_inverse(2, 1))
	end)

	it("should throw error when modulus is zero", function()
		assert.has_error(function()
			modular_inverse(1, 0)
		end)
	end)

	it("should throw error when modulus is negative", function()
		assert.has_error(function()
			modular_inverse(1, -1)
		end)
	end)
end)
