Testing system, reading from Notepad files for VBA Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Removing from a collection in Excel VBAAutomagic testing framework for VBAVBA Excel Game - TestingReading contents of a thousand CSV filesVBA code for testing efficencyFunctional FrameworkBasic Password System in Excel VBAA Moses's worthy string splitterGeneral function to test for empty/no-value controlsVBA code that pulls information from 1000+ files in directory performance

Is there night in Alpha Complex?

Did John Wesley plagiarize Matthew Henry...?

calculator's angle answer for trig ratios that can work in more than 1 quadrant on the unit circle

French equivalents of おしゃれは足元から (Every good outfit starts with the shoes)

Which types of prepositional phrase is "toward its employees" in Philosophy guiding the organization's policies towards its employees is not bad?

First Component in PCA

Is there a spell that can create a permanent fire?

Can gravitational waves pass through a black hole?

Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?

Was the pager message from Nick Fury to Captain Marvel unnecessary?

Noise in Eigenvalues plot

Does a random sequence of vectors span a Hilbert space?

Why not use the yoke to control yaw, as well as pitch and roll?

Twin's vs. Twins'

Proving that any solution to the differential equation of an oscillator can be written as a sum of sinusoids.

IC on Digikey is 5x more expensive than board containing same IC on Alibaba: How?

Plotting a Maclaurin series

Fit odd number of triplets in a measure?

Understanding piped commands in GNU/Linux

Hide attachment record without code

Why do C and C++ allow the expression (int) + 4*5?

How to resize main filesystem

The test team as an enemy of development? And how can this be avoided?

Improvising over quartal voicings



Testing system, reading from Notepad files for VBA



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Removing from a collection in Excel VBAAutomagic testing framework for VBAVBA Excel Game - TestingReading contents of a thousand CSV filesVBA code for testing efficencyFunctional FrameworkBasic Password System in Excel VBAA Moses's worthy string splitterGeneral function to test for empty/no-value controlsVBA code that pulls information from 1000+ files in directory performance



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1












$begingroup$


My idea is to make some testing system for functions, as per the model of CodeForces or TopCoder, but in VBA. There, the users write functions for a problem and the problems are tested vs. predefined tests.



In my case, it will be exactly the same, but the tests would be written on Notepad files.



Long story short, you have to write the function and then the function would be feeded with input parameters from one textfile and the result would be compared with the result from another test file.



The idea of the functions, is that they would be written by a "competitor", as in the aforementioned sites. The functions would be the answer of a predefined problem.



So, let's say that we have defined a problem, which is solvable through this:



If c Mod 2 = 0 Then
MainTest = a + b + c
Else
MainTest = a + b - c
End If


Thus, we need to write 2 notepad files in advance, which consist of the input parameters for a, b and c and the results. These are the notepad files:



2 2 2
2 2
2 2 3
4 54 1
2 2
54 23 6
45 45 10


File with results:



6
1
1
58
100
121
100


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:



Test 1............................................ ok!
Runtime error on 2!
Test 3............................................ ok!
Error on test 4! Expected -> 57 Received -> 58
Runtime error on 5!
Error on test 6! Expected -> 83 Received -> 121
Test 7............................................ ok!



Another possible predefined problem may sound like - "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".



And this is the whole competitive testing system:



Option Explicit

Public Sub Main()

Dim totalTests As Long
Dim pathInputTests As String
Dim pathOutputTests As String

Dim inputTests As Variant
Dim outputTests As Variant

Dim cntTests As Long
Dim cnt As Long

pathInputTests = "C:DesktopTest001.txt"
pathOutputTests = "C:DesktopResult001.txt"

inputTests = Split(ReadFileLineByLineToString(pathInputTests), vbCrLf)
outputTests = Split(ReadFileLineByLineToString(pathOutputTests), vbCrLf)

For cnt = LBound(inputTests) To UBound(inputTests)

Dim expectedValue As Variant
Dim receivedValue As Variant

On Error Resume Next

expectedValue = MainTest(inputTests(cnt))
receivedValue = outputTests(cnt)

If Err.Number <> 0 Then
Debug.Print runtimeError(cnt)
Err.Clear
Else
If expectedValue = receivedValue Then
Debug.Print positiveResult(cnt)
Else
Debug.Print negativeResult(cnt, expectedValue, receivedValue)
End If
End If

Next cnt

End Sub

Public Function runtimeError(ByVal cnt As Long) As String
cnt = cnt + 1
runtimeError = "Runtime error on " & cnt & "!"
End Function

Public Function positiveResult(ByVal cnt As Long) As String
cnt = cnt + 1
positiveResult = "Test " & cnt & "..................................... ok!"
End Function

Public Function negativeResult(ByVal cnt As Long, expected As Variant, _
received As Variant) As String
cnt = cnt + 1
negativeResult = "Error on test " & cnt & "!" & _
" Expected -> " & vbTab & expected & vbTab & _
" Received -> " & vbTab & received

End Function

'---------------------------------------------------------------------------------------
' Method : MainTest
' Purpose: This is where the competitors paste their solution.
'---------------------------------------------------------------------------------------

Public Function MainTest(ByVal consoleInput As String) As String

Dim a As Double
Dim b As Double
Dim c As Double

a = Split(consoleInput)(0)
b = Split(consoleInput)(1)
c = Split(consoleInput)(2)

If c Mod 2 = 0 Then
MainTest = a + b + c
Else
MainTest = a + b - c
End If

End Function

Public Function ReadFileLineByLineToString(path As String) As String

Dim fileNo As Long
fileNo = FreeFile

Open path For Input As #fileNo

Do While Not EOF(fileNo)
Dim textRowInput As String
Line Input #fileNo, textRowInput
ReadFileLineByLineToString = ReadFileLineByLineToString & textRowInput
If Not EOF(fileNo) Then
ReadFileLineByLineToString = ReadFileLineByLineToString & vbCrLf
End If
Loop

Close #fileNo

End Function


The code with the 4 test files is in GitHub here - https://github.com/Vitosh/VBA_personal/tree/master/AlgorithmsWithVBA - feel free to make push requests if you feel like it! :)










share|improve this question











$endgroup$




bumped to the homepage by Community 14 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • $begingroup$
    Please see What to do when someone answers. I have rolled back Rev 4 → 3.
    $endgroup$
    – 200_success
    Feb 5 '18 at 21:42










  • $begingroup$
    @200_success - why did you rolled back? The edit was improving the understanding of the question or I have missed something?
    $endgroup$
    – Vityata
    Feb 5 '18 at 21:44










  • $begingroup$
    We don't allow the code to be modified once an answer has been posted.
    $endgroup$
    – 200_success
    Feb 5 '18 at 22:10

















1












$begingroup$


My idea is to make some testing system for functions, as per the model of CodeForces or TopCoder, but in VBA. There, the users write functions for a problem and the problems are tested vs. predefined tests.



In my case, it will be exactly the same, but the tests would be written on Notepad files.



Long story short, you have to write the function and then the function would be feeded with input parameters from one textfile and the result would be compared with the result from another test file.



The idea of the functions, is that they would be written by a "competitor", as in the aforementioned sites. The functions would be the answer of a predefined problem.



So, let's say that we have defined a problem, which is solvable through this:



If c Mod 2 = 0 Then
MainTest = a + b + c
Else
MainTest = a + b - c
End If


Thus, we need to write 2 notepad files in advance, which consist of the input parameters for a, b and c and the results. These are the notepad files:



2 2 2
2 2
2 2 3
4 54 1
2 2
54 23 6
45 45 10


File with results:



6
1
1
58
100
121
100


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:



Test 1............................................ ok!
Runtime error on 2!
Test 3............................................ ok!
Error on test 4! Expected -> 57 Received -> 58
Runtime error on 5!
Error on test 6! Expected -> 83 Received -> 121
Test 7............................................ ok!



Another possible predefined problem may sound like - "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".



And this is the whole competitive testing system:



Option Explicit

Public Sub Main()

Dim totalTests As Long
Dim pathInputTests As String
Dim pathOutputTests As String

Dim inputTests As Variant
Dim outputTests As Variant

Dim cntTests As Long
Dim cnt As Long

pathInputTests = "C:DesktopTest001.txt"
pathOutputTests = "C:DesktopResult001.txt"

inputTests = Split(ReadFileLineByLineToString(pathInputTests), vbCrLf)
outputTests = Split(ReadFileLineByLineToString(pathOutputTests), vbCrLf)

For cnt = LBound(inputTests) To UBound(inputTests)

Dim expectedValue As Variant
Dim receivedValue As Variant

On Error Resume Next

expectedValue = MainTest(inputTests(cnt))
receivedValue = outputTests(cnt)

If Err.Number <> 0 Then
Debug.Print runtimeError(cnt)
Err.Clear
Else
If expectedValue = receivedValue Then
Debug.Print positiveResult(cnt)
Else
Debug.Print negativeResult(cnt, expectedValue, receivedValue)
End If
End If

Next cnt

End Sub

Public Function runtimeError(ByVal cnt As Long) As String
cnt = cnt + 1
runtimeError = "Runtime error on " & cnt & "!"
End Function

Public Function positiveResult(ByVal cnt As Long) As String
cnt = cnt + 1
positiveResult = "Test " & cnt & "..................................... ok!"
End Function

Public Function negativeResult(ByVal cnt As Long, expected As Variant, _
received As Variant) As String
cnt = cnt + 1
negativeResult = "Error on test " & cnt & "!" & _
" Expected -> " & vbTab & expected & vbTab & _
" Received -> " & vbTab & received

End Function

'---------------------------------------------------------------------------------------
' Method : MainTest
' Purpose: This is where the competitors paste their solution.
'---------------------------------------------------------------------------------------

Public Function MainTest(ByVal consoleInput As String) As String

Dim a As Double
Dim b As Double
Dim c As Double

a = Split(consoleInput)(0)
b = Split(consoleInput)(1)
c = Split(consoleInput)(2)

If c Mod 2 = 0 Then
MainTest = a + b + c
Else
MainTest = a + b - c
End If

End Function

Public Function ReadFileLineByLineToString(path As String) As String

Dim fileNo As Long
fileNo = FreeFile

Open path For Input As #fileNo

Do While Not EOF(fileNo)
Dim textRowInput As String
Line Input #fileNo, textRowInput
ReadFileLineByLineToString = ReadFileLineByLineToString & textRowInput
If Not EOF(fileNo) Then
ReadFileLineByLineToString = ReadFileLineByLineToString & vbCrLf
End If
Loop

Close #fileNo

End Function


The code with the 4 test files is in GitHub here - https://github.com/Vitosh/VBA_personal/tree/master/AlgorithmsWithVBA - feel free to make push requests if you feel like it! :)










share|improve this question











$endgroup$




bumped to the homepage by Community 14 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • $begingroup$
    Please see What to do when someone answers. I have rolled back Rev 4 → 3.
    $endgroup$
    – 200_success
    Feb 5 '18 at 21:42










  • $begingroup$
    @200_success - why did you rolled back? The edit was improving the understanding of the question or I have missed something?
    $endgroup$
    – Vityata
    Feb 5 '18 at 21:44










  • $begingroup$
    We don't allow the code to be modified once an answer has been posted.
    $endgroup$
    – 200_success
    Feb 5 '18 at 22:10













1












1








1





$begingroup$


My idea is to make some testing system for functions, as per the model of CodeForces or TopCoder, but in VBA. There, the users write functions for a problem and the problems are tested vs. predefined tests.



In my case, it will be exactly the same, but the tests would be written on Notepad files.



Long story short, you have to write the function and then the function would be feeded with input parameters from one textfile and the result would be compared with the result from another test file.



The idea of the functions, is that they would be written by a "competitor", as in the aforementioned sites. The functions would be the answer of a predefined problem.



So, let's say that we have defined a problem, which is solvable through this:



If c Mod 2 = 0 Then
MainTest = a + b + c
Else
MainTest = a + b - c
End If


Thus, we need to write 2 notepad files in advance, which consist of the input parameters for a, b and c and the results. These are the notepad files:



2 2 2
2 2
2 2 3
4 54 1
2 2
54 23 6
45 45 10


File with results:



6
1
1
58
100
121
100


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:



Test 1............................................ ok!
Runtime error on 2!
Test 3............................................ ok!
Error on test 4! Expected -> 57 Received -> 58
Runtime error on 5!
Error on test 6! Expected -> 83 Received -> 121
Test 7............................................ ok!



Another possible predefined problem may sound like - "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".



And this is the whole competitive testing system:



Option Explicit

Public Sub Main()

Dim totalTests As Long
Dim pathInputTests As String
Dim pathOutputTests As String

Dim inputTests As Variant
Dim outputTests As Variant

Dim cntTests As Long
Dim cnt As Long

pathInputTests = "C:DesktopTest001.txt"
pathOutputTests = "C:DesktopResult001.txt"

inputTests = Split(ReadFileLineByLineToString(pathInputTests), vbCrLf)
outputTests = Split(ReadFileLineByLineToString(pathOutputTests), vbCrLf)

For cnt = LBound(inputTests) To UBound(inputTests)

Dim expectedValue As Variant
Dim receivedValue As Variant

On Error Resume Next

expectedValue = MainTest(inputTests(cnt))
receivedValue = outputTests(cnt)

If Err.Number <> 0 Then
Debug.Print runtimeError(cnt)
Err.Clear
Else
If expectedValue = receivedValue Then
Debug.Print positiveResult(cnt)
Else
Debug.Print negativeResult(cnt, expectedValue, receivedValue)
End If
End If

Next cnt

End Sub

Public Function runtimeError(ByVal cnt As Long) As String
cnt = cnt + 1
runtimeError = "Runtime error on " & cnt & "!"
End Function

Public Function positiveResult(ByVal cnt As Long) As String
cnt = cnt + 1
positiveResult = "Test " & cnt & "..................................... ok!"
End Function

Public Function negativeResult(ByVal cnt As Long, expected As Variant, _
received As Variant) As String
cnt = cnt + 1
negativeResult = "Error on test " & cnt & "!" & _
" Expected -> " & vbTab & expected & vbTab & _
" Received -> " & vbTab & received

End Function

'---------------------------------------------------------------------------------------
' Method : MainTest
' Purpose: This is where the competitors paste their solution.
'---------------------------------------------------------------------------------------

Public Function MainTest(ByVal consoleInput As String) As String

Dim a As Double
Dim b As Double
Dim c As Double

a = Split(consoleInput)(0)
b = Split(consoleInput)(1)
c = Split(consoleInput)(2)

If c Mod 2 = 0 Then
MainTest = a + b + c
Else
MainTest = a + b - c
End If

End Function

Public Function ReadFileLineByLineToString(path As String) As String

Dim fileNo As Long
fileNo = FreeFile

Open path For Input As #fileNo

Do While Not EOF(fileNo)
Dim textRowInput As String
Line Input #fileNo, textRowInput
ReadFileLineByLineToString = ReadFileLineByLineToString & textRowInput
If Not EOF(fileNo) Then
ReadFileLineByLineToString = ReadFileLineByLineToString & vbCrLf
End If
Loop

Close #fileNo

End Function


The code with the 4 test files is in GitHub here - https://github.com/Vitosh/VBA_personal/tree/master/AlgorithmsWithVBA - feel free to make push requests if you feel like it! :)










share|improve this question











$endgroup$




My idea is to make some testing system for functions, as per the model of CodeForces or TopCoder, but in VBA. There, the users write functions for a problem and the problems are tested vs. predefined tests.



In my case, it will be exactly the same, but the tests would be written on Notepad files.



Long story short, you have to write the function and then the function would be feeded with input parameters from one textfile and the result would be compared with the result from another test file.



The idea of the functions, is that they would be written by a "competitor", as in the aforementioned sites. The functions would be the answer of a predefined problem.



So, let's say that we have defined a problem, which is solvable through this:



If c Mod 2 = 0 Then
MainTest = a + b + c
Else
MainTest = a + b - c
End If


Thus, we need to write 2 notepad files in advance, which consist of the input parameters for a, b and c and the results. These are the notepad files:



2 2 2
2 2
2 2 3
4 54 1
2 2
54 23 6
45 45 10


File with results:



6
1
1
58
100
121
100


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:



Test 1............................................ ok!
Runtime error on 2!
Test 3............................................ ok!
Error on test 4! Expected -> 57 Received -> 58
Runtime error on 5!
Error on test 6! Expected -> 83 Received -> 121
Test 7............................................ ok!



Another possible predefined problem may sound like - "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".



And this is the whole competitive testing system:



Option Explicit

Public Sub Main()

Dim totalTests As Long
Dim pathInputTests As String
Dim pathOutputTests As String

Dim inputTests As Variant
Dim outputTests As Variant

Dim cntTests As Long
Dim cnt As Long

pathInputTests = "C:DesktopTest001.txt"
pathOutputTests = "C:DesktopResult001.txt"

inputTests = Split(ReadFileLineByLineToString(pathInputTests), vbCrLf)
outputTests = Split(ReadFileLineByLineToString(pathOutputTests), vbCrLf)

For cnt = LBound(inputTests) To UBound(inputTests)

Dim expectedValue As Variant
Dim receivedValue As Variant

On Error Resume Next

expectedValue = MainTest(inputTests(cnt))
receivedValue = outputTests(cnt)

If Err.Number <> 0 Then
Debug.Print runtimeError(cnt)
Err.Clear
Else
If expectedValue = receivedValue Then
Debug.Print positiveResult(cnt)
Else
Debug.Print negativeResult(cnt, expectedValue, receivedValue)
End If
End If

Next cnt

End Sub

Public Function runtimeError(ByVal cnt As Long) As String
cnt = cnt + 1
runtimeError = "Runtime error on " & cnt & "!"
End Function

Public Function positiveResult(ByVal cnt As Long) As String
cnt = cnt + 1
positiveResult = "Test " & cnt & "..................................... ok!"
End Function

Public Function negativeResult(ByVal cnt As Long, expected As Variant, _
received As Variant) As String
cnt = cnt + 1
negativeResult = "Error on test " & cnt & "!" & _
" Expected -> " & vbTab & expected & vbTab & _
" Received -> " & vbTab & received

End Function

'---------------------------------------------------------------------------------------
' Method : MainTest
' Purpose: This is where the competitors paste their solution.
'---------------------------------------------------------------------------------------

Public Function MainTest(ByVal consoleInput As String) As String

Dim a As Double
Dim b As Double
Dim c As Double

a = Split(consoleInput)(0)
b = Split(consoleInput)(1)
c = Split(consoleInput)(2)

If c Mod 2 = 0 Then
MainTest = a + b + c
Else
MainTest = a + b - c
End If

End Function

Public Function ReadFileLineByLineToString(path As String) As String

Dim fileNo As Long
fileNo = FreeFile

Open path For Input As #fileNo

Do While Not EOF(fileNo)
Dim textRowInput As String
Line Input #fileNo, textRowInput
ReadFileLineByLineToString = ReadFileLineByLineToString & textRowInput
If Not EOF(fileNo) Then
ReadFileLineByLineToString = ReadFileLineByLineToString & vbCrLf
End If
Loop

Close #fileNo

End Function


The code with the 4 test files is in GitHub here - https://github.com/Vitosh/VBA_personal/tree/master/AlgorithmsWithVBA - feel free to make push requests if you feel like it! :)







algorithm vba excel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 5 '18 at 21:41









200_success

131k17157422




131k17157422










asked Feb 2 '18 at 16:00









VityataVityata

182217




182217





bumped to the homepage by Community 14 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 14 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.













  • $begingroup$
    Please see What to do when someone answers. I have rolled back Rev 4 → 3.
    $endgroup$
    – 200_success
    Feb 5 '18 at 21:42










  • $begingroup$
    @200_success - why did you rolled back? The edit was improving the understanding of the question or I have missed something?
    $endgroup$
    – Vityata
    Feb 5 '18 at 21:44










  • $begingroup$
    We don't allow the code to be modified once an answer has been posted.
    $endgroup$
    – 200_success
    Feb 5 '18 at 22:10
















  • $begingroup$
    Please see What to do when someone answers. I have rolled back Rev 4 → 3.
    $endgroup$
    – 200_success
    Feb 5 '18 at 21:42










  • $begingroup$
    @200_success - why did you rolled back? The edit was improving the understanding of the question or I have missed something?
    $endgroup$
    – Vityata
    Feb 5 '18 at 21:44










  • $begingroup$
    We don't allow the code to be modified once an answer has been posted.
    $endgroup$
    – 200_success
    Feb 5 '18 at 22:10















$begingroup$
Please see What to do when someone answers. I have rolled back Rev 4 → 3.
$endgroup$
– 200_success
Feb 5 '18 at 21:42




$begingroup$
Please see What to do when someone answers. I have rolled back Rev 4 → 3.
$endgroup$
– 200_success
Feb 5 '18 at 21:42












$begingroup$
@200_success - why did you rolled back? The edit was improving the understanding of the question or I have missed something?
$endgroup$
– Vityata
Feb 5 '18 at 21:44




$begingroup$
@200_success - why did you rolled back? The edit was improving the understanding of the question or I have missed something?
$endgroup$
– Vityata
Feb 5 '18 at 21:44












$begingroup$
We don't allow the code to be modified once an answer has been posted.
$endgroup$
– 200_success
Feb 5 '18 at 22:10




$begingroup$
We don't allow the code to be modified once an answer has been posted.
$endgroup$
– 200_success
Feb 5 '18 at 22:10










1 Answer
1






active

oldest

votes


















0












$begingroup$

You have split your input code across multiple functions - whereas you should encapsulate your input function to provide a single valid output. The easiest way to explain this is to look at the MainTest Function



  • The input is a single string

  • The MainTest function then has to parse that string

  • There is no error checking to see if the string or the parsing is
    valid

Inputs and Outputs of MainTest should be consistent with what it does.
Your examples are Integer/Long but your code uses Double. Happy this is just brevity for code example sake.



  • Your input is string but it does number operations

  • Your output is string, but the answers inside are numbers

  • All conversions are implicit (see note earlier about no error
    checking)

A neat MainTest would be like (sticking with Double instead of Long)



Public Function MainTest(ByVal a As Double, b as Double, c as Double) As Double


Similarly, you can modify ReadFileLineByLineToString to return the array. You can then just add to the array as you read each line!



Public Function ReadFileLineByLineToString(path As String) As String()


Of course (arrays)



Dim inputTests() As Variant
Dim outputTests() As Variant


Just before you call expectedValue = MainTest(inputTests(cnt)), Split InputTests(cnt) (e.g. Inputs = split(InputTests(cnt), " ") where Inputs is String() and InputNums = validated Double() from Inputs) and check that you have the right number of elements and that they are numbers (basic error checking). You would then call MainTest as



expectedValue = MainTest(InputNums(0), InputNums(1), InputNums(2))


There are many other places in your code where this sort of thinking can be applied. Consider using Option Strict and well as Option Explicit.






share|improve this answer









$endgroup$












  • $begingroup$
    Hi, thanks for the feedback. Probably you did not get the idea of the code. Its idea is to be a bit more robust, thus if another task is given it should be applicable. Imagine a task, which sounds as trivial as "Just give me the next letter in the alphabet". Then, when the input is "AB", you should return "BC". This is why I am using Strings here Function MainTest(ByVal consoleInput As String) As String. Furthermore, this is VBA, thus Option Strict does not exist there.
    $endgroup$
    – Vityata
    Feb 3 '18 at 11:37










  • $begingroup$
    @Vityata: But you are not doing string manipulation as a MainTest, you are doing arithmetic in this example. Either way, you have to re-write your code base significantly for different operations. My point about using ReadFileLineByLineToString properly still stands. My other points about proper error checking to catch expected errors still stands - you do not have any basic error checking to ensure that your input is correct. For these reasons, your code is not as robust as you think.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:35










  • $begingroup$
    @ThomasInzina: OK, point about Option Strict noted. However, including robust error checking to check inputs is not about "unit tests" - you are not testing anything if the test function itself fails (as opposed to the operation that is being tested).
    $endgroup$
    – AJD
    Feb 4 '18 at 4:37










  • $begingroup$
    @Vityata: Noting that in the OP you mentioned pre-defined tests, of which MainTest is an example. You haven't clarified who writes the function, or where it is implemented.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:40










  • $begingroup$
    That makes sense.
    $endgroup$
    – user109261
    Feb 4 '18 at 6:33











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f186611%2ftesting-system-reading-from-notepad-files-for-vba%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0












$begingroup$

You have split your input code across multiple functions - whereas you should encapsulate your input function to provide a single valid output. The easiest way to explain this is to look at the MainTest Function



  • The input is a single string

  • The MainTest function then has to parse that string

  • There is no error checking to see if the string or the parsing is
    valid

Inputs and Outputs of MainTest should be consistent with what it does.
Your examples are Integer/Long but your code uses Double. Happy this is just brevity for code example sake.



  • Your input is string but it does number operations

  • Your output is string, but the answers inside are numbers

  • All conversions are implicit (see note earlier about no error
    checking)

A neat MainTest would be like (sticking with Double instead of Long)



Public Function MainTest(ByVal a As Double, b as Double, c as Double) As Double


Similarly, you can modify ReadFileLineByLineToString to return the array. You can then just add to the array as you read each line!



Public Function ReadFileLineByLineToString(path As String) As String()


Of course (arrays)



Dim inputTests() As Variant
Dim outputTests() As Variant


Just before you call expectedValue = MainTest(inputTests(cnt)), Split InputTests(cnt) (e.g. Inputs = split(InputTests(cnt), " ") where Inputs is String() and InputNums = validated Double() from Inputs) and check that you have the right number of elements and that they are numbers (basic error checking). You would then call MainTest as



expectedValue = MainTest(InputNums(0), InputNums(1), InputNums(2))


There are many other places in your code where this sort of thinking can be applied. Consider using Option Strict and well as Option Explicit.






share|improve this answer









$endgroup$












  • $begingroup$
    Hi, thanks for the feedback. Probably you did not get the idea of the code. Its idea is to be a bit more robust, thus if another task is given it should be applicable. Imagine a task, which sounds as trivial as "Just give me the next letter in the alphabet". Then, when the input is "AB", you should return "BC". This is why I am using Strings here Function MainTest(ByVal consoleInput As String) As String. Furthermore, this is VBA, thus Option Strict does not exist there.
    $endgroup$
    – Vityata
    Feb 3 '18 at 11:37










  • $begingroup$
    @Vityata: But you are not doing string manipulation as a MainTest, you are doing arithmetic in this example. Either way, you have to re-write your code base significantly for different operations. My point about using ReadFileLineByLineToString properly still stands. My other points about proper error checking to catch expected errors still stands - you do not have any basic error checking to ensure that your input is correct. For these reasons, your code is not as robust as you think.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:35










  • $begingroup$
    @ThomasInzina: OK, point about Option Strict noted. However, including robust error checking to check inputs is not about "unit tests" - you are not testing anything if the test function itself fails (as opposed to the operation that is being tested).
    $endgroup$
    – AJD
    Feb 4 '18 at 4:37










  • $begingroup$
    @Vityata: Noting that in the OP you mentioned pre-defined tests, of which MainTest is an example. You haven't clarified who writes the function, or where it is implemented.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:40










  • $begingroup$
    That makes sense.
    $endgroup$
    – user109261
    Feb 4 '18 at 6:33















0












$begingroup$

You have split your input code across multiple functions - whereas you should encapsulate your input function to provide a single valid output. The easiest way to explain this is to look at the MainTest Function



  • The input is a single string

  • The MainTest function then has to parse that string

  • There is no error checking to see if the string or the parsing is
    valid

Inputs and Outputs of MainTest should be consistent with what it does.
Your examples are Integer/Long but your code uses Double. Happy this is just brevity for code example sake.



  • Your input is string but it does number operations

  • Your output is string, but the answers inside are numbers

  • All conversions are implicit (see note earlier about no error
    checking)

A neat MainTest would be like (sticking with Double instead of Long)



Public Function MainTest(ByVal a As Double, b as Double, c as Double) As Double


Similarly, you can modify ReadFileLineByLineToString to return the array. You can then just add to the array as you read each line!



Public Function ReadFileLineByLineToString(path As String) As String()


Of course (arrays)



Dim inputTests() As Variant
Dim outputTests() As Variant


Just before you call expectedValue = MainTest(inputTests(cnt)), Split InputTests(cnt) (e.g. Inputs = split(InputTests(cnt), " ") where Inputs is String() and InputNums = validated Double() from Inputs) and check that you have the right number of elements and that they are numbers (basic error checking). You would then call MainTest as



expectedValue = MainTest(InputNums(0), InputNums(1), InputNums(2))


There are many other places in your code where this sort of thinking can be applied. Consider using Option Strict and well as Option Explicit.






share|improve this answer









$endgroup$












  • $begingroup$
    Hi, thanks for the feedback. Probably you did not get the idea of the code. Its idea is to be a bit more robust, thus if another task is given it should be applicable. Imagine a task, which sounds as trivial as "Just give me the next letter in the alphabet". Then, when the input is "AB", you should return "BC". This is why I am using Strings here Function MainTest(ByVal consoleInput As String) As String. Furthermore, this is VBA, thus Option Strict does not exist there.
    $endgroup$
    – Vityata
    Feb 3 '18 at 11:37










  • $begingroup$
    @Vityata: But you are not doing string manipulation as a MainTest, you are doing arithmetic in this example. Either way, you have to re-write your code base significantly for different operations. My point about using ReadFileLineByLineToString properly still stands. My other points about proper error checking to catch expected errors still stands - you do not have any basic error checking to ensure that your input is correct. For these reasons, your code is not as robust as you think.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:35










  • $begingroup$
    @ThomasInzina: OK, point about Option Strict noted. However, including robust error checking to check inputs is not about "unit tests" - you are not testing anything if the test function itself fails (as opposed to the operation that is being tested).
    $endgroup$
    – AJD
    Feb 4 '18 at 4:37










  • $begingroup$
    @Vityata: Noting that in the OP you mentioned pre-defined tests, of which MainTest is an example. You haven't clarified who writes the function, or where it is implemented.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:40










  • $begingroup$
    That makes sense.
    $endgroup$
    – user109261
    Feb 4 '18 at 6:33













0












0








0





$begingroup$

You have split your input code across multiple functions - whereas you should encapsulate your input function to provide a single valid output. The easiest way to explain this is to look at the MainTest Function



  • The input is a single string

  • The MainTest function then has to parse that string

  • There is no error checking to see if the string or the parsing is
    valid

Inputs and Outputs of MainTest should be consistent with what it does.
Your examples are Integer/Long but your code uses Double. Happy this is just brevity for code example sake.



  • Your input is string but it does number operations

  • Your output is string, but the answers inside are numbers

  • All conversions are implicit (see note earlier about no error
    checking)

A neat MainTest would be like (sticking with Double instead of Long)



Public Function MainTest(ByVal a As Double, b as Double, c as Double) As Double


Similarly, you can modify ReadFileLineByLineToString to return the array. You can then just add to the array as you read each line!



Public Function ReadFileLineByLineToString(path As String) As String()


Of course (arrays)



Dim inputTests() As Variant
Dim outputTests() As Variant


Just before you call expectedValue = MainTest(inputTests(cnt)), Split InputTests(cnt) (e.g. Inputs = split(InputTests(cnt), " ") where Inputs is String() and InputNums = validated Double() from Inputs) and check that you have the right number of elements and that they are numbers (basic error checking). You would then call MainTest as



expectedValue = MainTest(InputNums(0), InputNums(1), InputNums(2))


There are many other places in your code where this sort of thinking can be applied. Consider using Option Strict and well as Option Explicit.






share|improve this answer









$endgroup$



You have split your input code across multiple functions - whereas you should encapsulate your input function to provide a single valid output. The easiest way to explain this is to look at the MainTest Function



  • The input is a single string

  • The MainTest function then has to parse that string

  • There is no error checking to see if the string or the parsing is
    valid

Inputs and Outputs of MainTest should be consistent with what it does.
Your examples are Integer/Long but your code uses Double. Happy this is just brevity for code example sake.



  • Your input is string but it does number operations

  • Your output is string, but the answers inside are numbers

  • All conversions are implicit (see note earlier about no error
    checking)

A neat MainTest would be like (sticking with Double instead of Long)



Public Function MainTest(ByVal a As Double, b as Double, c as Double) As Double


Similarly, you can modify ReadFileLineByLineToString to return the array. You can then just add to the array as you read each line!



Public Function ReadFileLineByLineToString(path As String) As String()


Of course (arrays)



Dim inputTests() As Variant
Dim outputTests() As Variant


Just before you call expectedValue = MainTest(inputTests(cnt)), Split InputTests(cnt) (e.g. Inputs = split(InputTests(cnt), " ") where Inputs is String() and InputNums = validated Double() from Inputs) and check that you have the right number of elements and that they are numbers (basic error checking). You would then call MainTest as



expectedValue = MainTest(InputNums(0), InputNums(1), InputNums(2))


There are many other places in your code where this sort of thinking can be applied. Consider using Option Strict and well as Option Explicit.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 2 '18 at 20:12









AJDAJD

1,3521313




1,3521313











  • $begingroup$
    Hi, thanks for the feedback. Probably you did not get the idea of the code. Its idea is to be a bit more robust, thus if another task is given it should be applicable. Imagine a task, which sounds as trivial as "Just give me the next letter in the alphabet". Then, when the input is "AB", you should return "BC". This is why I am using Strings here Function MainTest(ByVal consoleInput As String) As String. Furthermore, this is VBA, thus Option Strict does not exist there.
    $endgroup$
    – Vityata
    Feb 3 '18 at 11:37










  • $begingroup$
    @Vityata: But you are not doing string manipulation as a MainTest, you are doing arithmetic in this example. Either way, you have to re-write your code base significantly for different operations. My point about using ReadFileLineByLineToString properly still stands. My other points about proper error checking to catch expected errors still stands - you do not have any basic error checking to ensure that your input is correct. For these reasons, your code is not as robust as you think.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:35










  • $begingroup$
    @ThomasInzina: OK, point about Option Strict noted. However, including robust error checking to check inputs is not about "unit tests" - you are not testing anything if the test function itself fails (as opposed to the operation that is being tested).
    $endgroup$
    – AJD
    Feb 4 '18 at 4:37










  • $begingroup$
    @Vityata: Noting that in the OP you mentioned pre-defined tests, of which MainTest is an example. You haven't clarified who writes the function, or where it is implemented.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:40










  • $begingroup$
    That makes sense.
    $endgroup$
    – user109261
    Feb 4 '18 at 6:33
















  • $begingroup$
    Hi, thanks for the feedback. Probably you did not get the idea of the code. Its idea is to be a bit more robust, thus if another task is given it should be applicable. Imagine a task, which sounds as trivial as "Just give me the next letter in the alphabet". Then, when the input is "AB", you should return "BC". This is why I am using Strings here Function MainTest(ByVal consoleInput As String) As String. Furthermore, this is VBA, thus Option Strict does not exist there.
    $endgroup$
    – Vityata
    Feb 3 '18 at 11:37










  • $begingroup$
    @Vityata: But you are not doing string manipulation as a MainTest, you are doing arithmetic in this example. Either way, you have to re-write your code base significantly for different operations. My point about using ReadFileLineByLineToString properly still stands. My other points about proper error checking to catch expected errors still stands - you do not have any basic error checking to ensure that your input is correct. For these reasons, your code is not as robust as you think.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:35










  • $begingroup$
    @ThomasInzina: OK, point about Option Strict noted. However, including robust error checking to check inputs is not about "unit tests" - you are not testing anything if the test function itself fails (as opposed to the operation that is being tested).
    $endgroup$
    – AJD
    Feb 4 '18 at 4:37










  • $begingroup$
    @Vityata: Noting that in the OP you mentioned pre-defined tests, of which MainTest is an example. You haven't clarified who writes the function, or where it is implemented.
    $endgroup$
    – AJD
    Feb 4 '18 at 4:40










  • $begingroup$
    That makes sense.
    $endgroup$
    – user109261
    Feb 4 '18 at 6:33















$begingroup$
Hi, thanks for the feedback. Probably you did not get the idea of the code. Its idea is to be a bit more robust, thus if another task is given it should be applicable. Imagine a task, which sounds as trivial as "Just give me the next letter in the alphabet". Then, when the input is "AB", you should return "BC". This is why I am using Strings here Function MainTest(ByVal consoleInput As String) As String. Furthermore, this is VBA, thus Option Strict does not exist there.
$endgroup$
– Vityata
Feb 3 '18 at 11:37




$begingroup$
Hi, thanks for the feedback. Probably you did not get the idea of the code. Its idea is to be a bit more robust, thus if another task is given it should be applicable. Imagine a task, which sounds as trivial as "Just give me the next letter in the alphabet". Then, when the input is "AB", you should return "BC". This is why I am using Strings here Function MainTest(ByVal consoleInput As String) As String. Furthermore, this is VBA, thus Option Strict does not exist there.
$endgroup$
– Vityata
Feb 3 '18 at 11:37












$begingroup$
@Vityata: But you are not doing string manipulation as a MainTest, you are doing arithmetic in this example. Either way, you have to re-write your code base significantly for different operations. My point about using ReadFileLineByLineToString properly still stands. My other points about proper error checking to catch expected errors still stands - you do not have any basic error checking to ensure that your input is correct. For these reasons, your code is not as robust as you think.
$endgroup$
– AJD
Feb 4 '18 at 4:35




$begingroup$
@Vityata: But you are not doing string manipulation as a MainTest, you are doing arithmetic in this example. Either way, you have to re-write your code base significantly for different operations. My point about using ReadFileLineByLineToString properly still stands. My other points about proper error checking to catch expected errors still stands - you do not have any basic error checking to ensure that your input is correct. For these reasons, your code is not as robust as you think.
$endgroup$
– AJD
Feb 4 '18 at 4:35












$begingroup$
@ThomasInzina: OK, point about Option Strict noted. However, including robust error checking to check inputs is not about "unit tests" - you are not testing anything if the test function itself fails (as opposed to the operation that is being tested).
$endgroup$
– AJD
Feb 4 '18 at 4:37




$begingroup$
@ThomasInzina: OK, point about Option Strict noted. However, including robust error checking to check inputs is not about "unit tests" - you are not testing anything if the test function itself fails (as opposed to the operation that is being tested).
$endgroup$
– AJD
Feb 4 '18 at 4:37












$begingroup$
@Vityata: Noting that in the OP you mentioned pre-defined tests, of which MainTest is an example. You haven't clarified who writes the function, or where it is implemented.
$endgroup$
– AJD
Feb 4 '18 at 4:40




$begingroup$
@Vityata: Noting that in the OP you mentioned pre-defined tests, of which MainTest is an example. You haven't clarified who writes the function, or where it is implemented.
$endgroup$
– AJD
Feb 4 '18 at 4:40












$begingroup$
That makes sense.
$endgroup$
– user109261
Feb 4 '18 at 6:33




$begingroup$
That makes sense.
$endgroup$
– user109261
Feb 4 '18 at 6:33

















draft saved

draft discarded
















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f186611%2ftesting-system-reading-from-notepad-files-for-vba%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar