Sha256: d6d02b6b089510dc26277653ea912d991a3dabb6d011eb47dc5ac642040e5edd
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require_relative './spec_helper' describe "Luhn" do describe "on Numeric" do let(:valid) { 4100410382 } let(:valid_check) { 2 } let(:incomplete) { 410041038 } let(:invalid) { 4100410383 } it "should validate valid luhn codes" do valid.luhn?.should be_true end it "should invalidate invalid luhn codes" do invalid.luhn?.should be_false end it "should calculate the correct luhn check digit" do incomplete.luhn.should == valid_check end it "should append the correct check digit" do incomplete.luhn!.should == valid end it "should quack like a Numeric" do incomplete.luhn!.should be_a Numeric end end describe "on String" do let(:valid) { '4 10041038 2' } let(:valid_check) { '2' } let(:incomplete) { '410041038' } let(:invalid) { '4100410383' } it "should validate valid luhn codes" do valid.luhn?.should be_true end it "should invalidate invalid luhn codes" do invalid.luhn?.should be_false end it "should calculate the correct luhn check digit" do incomplete.luhn.should == valid_check end it "should append the correct check digit" do incomplete.luhn!.should == valid.gsub(/\D+/, '') end it "should return Strings" do incomplete.luhn!.should be_a String end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
moeffju-luhn-0.1.2 | spec/luhn_spec.rb |