Base#compare which ignores 'id'

S

Simon Strandgaard

When doing unittesting I ofthen need to compare some computed data against
what is expected. I have a class hierarchy derived from a base class.

How do one install a compare method in the base class, which ignores 'id' ?

--
Simon Strandgaard

def test_transform
a = mk_letter 'a'
b = mk_letter 'b'
alt = mk_alternation(a, b)
wild = mk_wild
c = mk_letter 'c'
rep = mk_repeat wild, 0, 1
seq = mk_sequence alt, rep, c

s = ScannerHierarchy
exp = [
s::Alternation.new(true),
s::pattern.new(true),
s::Match.new(a),
s::pattern.new(false),
s::pattern.new(true),
s::Match.new(b),
s::pattern.new(false),
s::Alternation.new(false),
s::Repeat.new(true),
s::Match.new(wild),
s::Repeat.new(false),
s::Match.new(c)
]
v = TransformVisitor.new
seq.accept(v)
assert_equal(exp, v.result)
end
 
S

Simon Strandgaard

When doing unittesting I ofthen need to compare some computed data against
what is expected. I have a class hierarchy derived from a base class.

How do one install a compare method in the base class, which ignores 'id' ?

What I am interested in is an #assert_equal_ignore_id method.
Is such thing possible ?

How do you do comparison of data structures when unittesting ?
 
S

Simon Strandgaard

What I am interested in is an #assert_equal_ignore_id method.
Is such thing possible ?

How do you do comparison of data structures when unittesting ?

Solved.. compare the output generated Marshal.dump :)

# assert_equal which ignore id
def assert_equal_marshal(expected, actual, message=nil)
full_message = build_message(message, expected, actual) do |arg1, arg2|
"<#{arg1}> expected but was\n" +
"<#{arg2}>"
end
assert_block(full_message) {
Marshal.dump(expected) == Marshal.dump(actual)
}
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,138
Messages
2,570,804
Members
47,349
Latest member
jojonoy597

Latest Threads

Top