How do I get a true value when using object_comparison on an empty linked list in my post condition?

59 Views Asked by At

I have an assignment that requires me to create an empty linked list key: LINKED_LIST [KEY], another linked list data_items_1: LINKED_LIST [DATA1] and a hash table data_items_2: HASH_TABLE [DATA2, KEY] in the constructor. The post condition that my professor put was

object_equality_for_keys: keys.object_comparison
object_equality_for_data_items_1: data_items_1.object_comparison
object_equality_for_data_items_2: data_items_2.object_comparison

When I run the program I get a contract violation. In the debugger it's always pointing to this line of code and I'm not sure why. What is the purpose of this post condition and how do I not violate this contract? Error Message

1

There are 1 best solutions below

1
obnosim On

The feature compare_objects of class CONTAINER indicates whether that container uses = (reference comparison) or ~ (value/object comparison, which calls is_equal internally) when comparing items. You can call compare_objects or compare_references to configure individual containers and ensure they work the way you need them to.