Sha256: 124b3dee3a7f3c418ee012d5095709ab3893a4e9dc810e6581083bf24080bf98

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 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]

      coeffs = [1,-2,1]
      mod=15
      expect(CongruenceSolver.lift(coeffs,mod).sort).to eq [1]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
congruence_solver-0.5.2 spec/congruence_solver_spec.rb
congruence_solver-0.5.1 spec/congruence_solver_spec.rb
congruence_solver-0.5.0 spec/congruence_solver_spec.rb
congruence_solver-0.4.0 spec/congruence_solver_spec.rb
congruence_solver-0.3.2 spec/congruence_solver_spec.rb