Tests for Checksum class

This commit is contained in:
Jack Nagel 2013-04-07 00:49:56 -05:00
parent 3882603ba8
commit 349cdab76f
2 changed files with 30 additions and 10 deletions

View File

@ -1,22 +1,19 @@
class Checksum
attr_reader :hash_type, :hexdigest
alias_method :to_s, :hexdigest
TYPES = [:sha1, :sha256]
def initialize type=:sha1, val=nil
@hash_type = type
@hexdigest = val.to_s
def initialize(hash_type, hexdigest)
@hash_type = hash_type
@hexdigest = hexdigest
end
def empty?
@hexdigest.empty?
hexdigest.empty?
end
def to_s
@hexdigest
end
def == other
@hash_type == other.hash_type and @hexdigest == other.hexdigest
def ==(other)
hash_type == other.hash_type && hexdigest == other.hexdigest
end
end

View File

@ -0,0 +1,23 @@
require 'testing_env'
require 'checksum'
class ChecksumTests < Test::Unit::TestCase
def test_empty?
assert_empty Checksum.new(:sha1, '')
end
def test_equality
a = Checksum.new(:sha1, 'deadbeef'*5)
b = Checksum.new(:sha1, 'deadbeef'*5)
assert_equal a, b
a = Checksum.new(:sha1, 'deadbeef'*5)
b = Checksum.new(:sha1, 'feedface'*5)
assert_not_equal a, b
a = Checksum.new(:sha1, 'deadbeef'*5)
b = Checksum.new(:sha256, 'deadbeef'*5)
assert_not_equal a, b
end
end