Tests protect you from your future self.
say you have the following function:
private Sub operation(a As Int, b As Int, c As String) As Int
Select c
Case "disguisse"
Return (a + b) * 3 / 2
Case "encrypt"
Return (a * b * 2) + 5
End Select
End Sub
and i use it like this:
operation(5,3,"disguissse")
i will always expect a 12 to be returned.
But in the future, like a couple of months later, a new feature is implemented that changes the function, say you or a coworker
private Sub operation(a As Int, b As Int, c As String) As Int
Select c
Case "disguisse"
Return a + b * 3 / 2
Case "encrypt"
Return (a * b * 2) + 5
End Select
End Sub
as you can see parentheses has been removed. and now the same function returns 9
if i was careful enough to create a test, say something as simple as:
assert(operation(5, 3, "disguisse"), 12)
private Sub assert(fun As Int, expected As Int) As Boolean
If fun <> expected Then
Log($"function returned ${fun} but was expected to return ${expected}"$)
End If
Return fun = expected
End Sub
the moment i run my unit tests, this particular test will fail. so the solution becomes.
private Sub operation(a As Int, b As Int, c As String) As Int
Select c
Case "disguisse"
Return (a + b) * 3 / 2
Case "disguisse_2"
Return a + b * 3 / 2
Case "encrypt"
Return (a * b * 2) + 5
End Select
End Sub
and thats the sole pourpose of tests, take into consideration, that people write code for years on a single project and small projects become large codebases, if you don't prepare for that, you won't scale.