arrayOfNums2
GET https://postman-echo.com/get
Now that we have the first arrey saved to firstArrey
we can compare it to the secondArray
in the Tests
tab.
We have defined two functions at the bottom of this script.
- the first, equalsInOrder
, uses a basic string comparison but is limited to comparing arrays that are in the same order.
- the second, haveSameContents
, is designed to compare arrays that have the same contents and will still return true
if the compared arrays match but are ordered differently.
note: this beautiful function was found on 30secondsofcode.org
Try it out:
This test should start in a passing state. 1. Try making the first fail by re-ordering the array in the request body. 1. Now try to make them both fail by adding another item to the array.
Request Body
{"data"=>[12345, 23456, 34567]}