# coding: utf-8
describe Integer, "#power_mod" do
  @seq = {
    # A015910
    2 => [0,0,2,0,2,4,2,0,8,4,2,4,2,4,8,0,2,10,2,16,8,4,2,
          16,7,4,26,16,2,4,2,0,8,4,18,28,2,4,8,16,2,22,2,16,
          17,4,2,16,30,24,8,16,2,28,43,32,8,4,2,16,2,4,8,0,
          32,64,2,16,8,44,2,64,2,4,68,16,18,64,2,16,80,4,2,
          64].map.with_index(1){|pm, b| [pm, b, b]},

    # A002380
    3 => [0,1,1,3,1,19,25,11,161,227,681,1019,3057,5075,
          15225,29291,55105,34243,233801,439259,269201,
          1856179,3471385,6219851,1882337,5647011,50495465,
          17268667,186023729,21200275,63600825,1264544299,
          3793632897,7085931395].map.with_index{|pm, b| [pm, b, 2**b]},

    # A056969
    10 => [0,0,1,0,0,4,3,0,1,0,10,4,10,2,10,0,10,10,10,0,13,
           12,10,16,0,22,1,4,10,10,10,0,10,32,5,28,10,24,25,
           0,10,22,10,12,10,8,10,16,31,0,31,16,10,28,10,16,
           31,42,10,40,10,38,55,0,30,34,10,4,34,60,10,64,10,
           26,25,44,54,40].map.with_index(1){|pm, b| [pm, b, b]} + [
           0,0,1,0,0,4,4,0,1,0,1,4,3,4,10,0,4,10,9,0,4,12,
           13,16,0,16,10,4,16,10,5,0,1,4,25,28,10,28,16,0,1,
           4,31,12,10,36,27,16,11,0,4,16,28,10,45,32,28,16,
           16,40,47,36,46,0,55,34,10,4,13,60,20,64,72,10,25,
           28,67,16,67,0].map.with_index(1){|pm, b| [pm, 100, b]},

    # A116609
    13 => [0,1,1,1,3,1,6,1,1,9,2,1,0,1,7,1,13,1,13,1,13,15,
           13,1,18,13,1,1,13,19,13,1,19,33,27,1,13,17,13,1,
           13,1,13,5,28,31,13,1,48,49,4,13,13,1,32,1,31,53,
           13,1,13,45,55,1,13,31,13,1,58,29,13,1,13,21,7,61,
           62,13,13,1,1,5].map.with_index(1){|pm, b| [pm, b, b]}
  }

  @seq.each do |a, seq|
    seq.each do |pm, b, m|
      it "returns #{pm} for #{a}.power_mod(#{b}, #{m})" do
        a.power_mod(b, m).should == pm
      end
    end
  end
end
