Sha256: 39051fa144b123d1b5fc753437a1c6ee8586778d1b6c664c9e03622e27cf4038

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require "congruence_solver"

RSpec.describe CongruenceSolver do
	describe "::lift" do
		it "expects 3 arguments" do
			expect {CongruenceSolver.lift()}.to raise_error ArgumentError
			expect {CongruenceSolver.lift(0)}.to raise_error ArgumentError
			expect {CongruenceSolver.lift([1,2], 3)}.not_to raise_error
			expect {CongruenceSolver.lift([1], [1], nil)}.to raise_error ArgumentError
		end


		it "solves individual polynomial congruences defined by their coefficients and mod" do
			coeffs = [-1, 0, 4]
			mod = 5
			expect(CongruenceSolver.lift(coeffs, mod).sort).to eq [2, 3]

			coeffs = [-3, 4, 9]
			mod = 49
			expect(CongruenceSolver.lift(coeffs, mod).sort).to eq []

			coeffs = [1, -4, 4]
			mod = 5104
			expect(CongruenceSolver.lift(coeffs, mod).sort).to eq []

			coeffs = [4, -4, 1]
			mod = 5104
			expect(CongruenceSolver.lift(coeffs, mod).sort).to eq [2, 1278, 2554, 3830]

			coeffs = Array.new(500, 0)
			coeffs[0] = -1
			coeffs[500] = 1
			mod = 15
			expect(CongruenceSolver.lift(coeffs, mod).sort).to eq [1, 2, 4, 7, 8, 11, 13, 14]
		end

	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
congruence_solver-0.3.0 spec/congruence_solver_spec.rb
congruence_solver-0.2.0 spec/congruence_solver_spec.rb