# 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: Writing Test Cases
# This file contains tests for verifying the sorting algorithm behaves as expected.
# The tests also include profiling the code to see the performance of the algorithm.
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
my_log_channel<public> := class(log_channel):
# A project-wide "Logger" to print messages from functions that are not in a class with a log.
# The non-Logger Print is <no_rollback>, so it can't be used in a <transacts> function.
ProjectLog<public>(Message:[]char, ?Level:log_level = log_level.Normal)<transacts>:void=
Logger := log{Channel := my_log_channel}
Logger.Print(Message, ?Level := Level)
# A Verse-authored creative device that can be placed in a level.
# Place in the level to run tests and profile code.
test_sorting := class(creative_device):
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
# Example arrays to use for the test.
Test1ExpectedIntArray:[]int = array{}
Test1ActualIntArray:[]int = array{}
# Run the tests and report if they failed or succeeded.
if:
RunArrayTest["Integer array in order from smallest to largest", Test1ActualIntArray, Test1ExpectedIntArray, IsIntSmallerThan, IntArrayToString]
then:
ProjectLog("All tests passed.")
else:
ProjectLog("One or more tests failed.")
Verse Library
verse
13 Writing Test Cases
Custom logging channel and creative device for running and reporting sorting algorithm test results.
extracted-snippets/documentation/en-us/uefn/sorting-algorithms-in-verse/13-writing-test-cases.verse