For this test, RestApi test cases.iou -> borrower has negative balance
, I’m getting test failures about half the, time where the entry for “Bob” has a different order for the “owes” item than the test is expecting. In other words, sometimes it appears like this:
@{name = "Bob" ; owes = @{Adam = 3.0 ; Chuck = 3.0}; owed_by = @{}; balance = -6.0}
and sometimes it appears like this:
@{name = "Bob" ; owes = @{Chuck = 3.0 ; Adam = 3.0}; owed_by = @{}; balance = -6.0}
Specifically, this is the failure I’m seeing:
Expected: '... "owed_by": {\n "Bob": 3.0\n },\n "balance": 3.0\n },\n {\n "owes": {\n "Adam": 3.0,\n "C...'
But was: '... "owed_by": {\n "Bob": 3.0\n },\n "balance": 3.0\n },\n {\n "owes": {\n "Chuck": 3.0,\n "...'
----------------------------------------------------------------------------------------------------------------^
Since the test is comparing the expected value and the actual value using JSON strings, the order is very unforgiving. I managed to get this working well enough if I changed the order in which I process the borrower and the lender. However, I still see the occasional failure. Isn’t there a better way in PowerShell to compare two hashtables than converted them to JSON strings? Wouldn’t Compare-Object
give more consistent results?