Algorithm testing system, reading from text file with VBA

For the people, familiar with my blog, it is known that usually I am resolving problems from Codeforces.com. 

Codeforces supports plenty of languages, unfortunately VBA is not one of them. Thus, I have decided to build up a small algorithm testing system, which follows the following pattern – the input and the expected output are both provided via separate text files. Then, the person who writes the algorithm, should be able to write a function, reading from the first file and getting exactly the values from the other file.

Thus, let’s imagine that the task sounds like:

Take an input of 3 numbers and sum them. However, if the third number is even, do sum only the first two and subtract the third. This is easily achievable through this function:

Another possible problem may sound like this:

Give me the next character of a string. Thus “a b c d” would result to “b c d e” and “a z” would be “b a”. This problem is solvable through the following code:


Thus, to solve the first problem, we need the following input and output files.

Input:

Input:

To make it more presentable, the file with the results, has some runtime errors and wrong calculation errors. Thus this is the result in the immediate window:

Now the question – how do we actually do this? The answer is in less than 130 lines here, one should only change the paths of the notepad files (pathInputTests and pathOutputTests) and start the challenge through Main:

The code is also available in GitHub.

About

VBA Developer

Tagged with: ,