Verse Library verse

09 Testing And Profiling Your Algorithms

Sorts an array using merge sort, logs results, and verifies each element matches expected output.

extracted-snippets/documentation/en-us/uefn/sorting-algorithms-in-verse/09-testing-and-profiling-your-algorithms.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/sorting-algorithms-in-verse
# Local doc:  epic-docs/documentation/en-us/uefn/sorting-algorithms-in-verse.md
# Section:    Testing and Profiling Your Algorithms
# Test function for sorting arrays and profiling the code.
RunArrayTest(ActualArray:[]t, ExpectedArray:[]t, Compare(L:t, R:t)<decides><transacts>:t, ArrayToString(:[]t)<transacts>:string where t:subtype(comparable))<decides><transacts>:void=
# Perform merge sort
ResultArray := SortingAlgorithms.MergeSort(ActualArray, Compare)
# Print out the Actual, Expected, and Result arrays for troubleshooting.
ProjectLog("Actual: {ArrayToString(ActualArray)}")
ProjectLog("Expected: {ArrayToString(ExpectedArray)}")
ProjectLog("Result: {ArrayToString(ResultArray)}")
# Verify the test passed and sorted the array as expected.
for (Index -> Result : ResultArray, Expected := ExpectedArray[Index]):
Result = Expected

Comments

    Sign in to vote, comment, or suggest an edit. Sign in