Tests for Checksum class
This commit is contained in:
parent
3882603ba8
commit
349cdab76f
@ -1,22 +1,19 @@
|
|||||||
class Checksum
|
class Checksum
|
||||||
attr_reader :hash_type, :hexdigest
|
attr_reader :hash_type, :hexdigest
|
||||||
|
alias_method :to_s, :hexdigest
|
||||||
|
|
||||||
TYPES = [:sha1, :sha256]
|
TYPES = [:sha1, :sha256]
|
||||||
|
|
||||||
def initialize type=:sha1, val=nil
|
def initialize(hash_type, hexdigest)
|
||||||
@hash_type = type
|
@hash_type = hash_type
|
||||||
@hexdigest = val.to_s
|
@hexdigest = hexdigest
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty?
|
def empty?
|
||||||
@hexdigest.empty?
|
hexdigest.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def ==(other)
|
||||||
@hexdigest
|
hash_type == other.hash_type && hexdigest == other.hexdigest
|
||||||
end
|
|
||||||
|
|
||||||
def == other
|
|
||||||
@hash_type == other.hash_type and @hexdigest == other.hexdigest
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
23
Library/Homebrew/test/test_checksum.rb
Normal file
23
Library/Homebrew/test/test_checksum.rb
Normal 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
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user