You are here:

C++/Verification of Algorithms


Hello Eddie,
 In school, if we write a function like: "int factorial(int x) {}", they will have us verify it by calling the function with a couple different values and then computing factorials by hand and seeing if they match.  But if you have something more complicated, especially if functions have [psuedo] random based algorithms, what kinds of techniques can I use to verify the algorithm was implemented correctly (aside from doing it by hand)?

Hello Jed, thank you for the question.

What I tend to do is write extensive unit tests for methods like this that test a range of values with a range of outputs. There is a handy tool called CppUnit to help with that. For instance, if you wrote a method that returned a random number between 2 params, you can use hard coded parameters to test, and then test the output to ensure it is between them.

Obviously there is no set in stone way to verify that random algorithms always work, but this can give you a good idea.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2017 All rights reserved.