... | @@ -13,6 +13,71 @@ AssertAreNotEqualStrings(String expected, String actual, String message) |
... | @@ -13,6 +13,71 @@ AssertAreNotEqualStrings(String expected, String actual, String message) |
|
AssertIsTrue(Boolean condition, String message)
|
|
AssertIsTrue(Boolean condition, String message)
|
|
AssertIsFalse(Boolean condition, String message)
|
|
AssertIsFalse(Boolean condition, String message)
|
|
```
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
The code to be tested (file Prime.fcode):
|
|
|
|
```
|
|
|
|
Function Main
|
|
|
|
Output IsPrime(3)
|
|
|
|
Output IsPrime(7)
|
|
|
|
Output IsPrime(11)
|
|
|
|
Output IsPrime(41)
|
|
|
|
End
|
|
|
|
|
|
|
|
Function IsPrime (Integer number)
|
|
|
|
Declare Boolean prime
|
|
|
|
|
|
|
|
If number=2
|
|
|
|
Assign prime = True
|
|
|
|
False:
|
|
|
|
If number==3
|
|
|
|
Assign prime = True
|
|
|
|
False:
|
|
|
|
If number==5
|
|
|
|
Assign prime = True
|
|
|
|
False:
|
|
|
|
Assign prime = False
|
|
|
|
End
|
|
|
|
End
|
|
|
|
End
|
|
|
|
Return Boolean prime
|
|
|
|
```
|
|
|
|
|
|
|
|
The unit tests are in a separate file. To assign the test with a code file, use the suffix Test (PrimeTest.fcode):
|
|
|
|
```
|
|
|
|
Function TestIsPrimeWhenNonPrimeReturnsFalse
|
|
|
|
... prepare non prime numbers input
|
|
|
|
Declare Integer Array nonPrimes[10]
|
|
|
|
|
|
|
|
... some predefined non prime numbers
|
|
|
|
Assign nonPrimes[0] = 0
|
|
|
|
Assign nonPrimes[1] = 1
|
|
|
|
Assign nonPrimes[2] = 4
|
|
|
|
Assign nonPrimes[3] = 9
|
|
|
|
|
|
|
|
... some random non prime numbers
|
|
|
|
Declare Integer i
|
|
|
|
For i = 4 to Size(nonPrimes)-1
|
|
|
|
Assign nonPrimes[i] = (Random(100)+2)*(Random(100)+2)
|
|
|
|
End
|
|
|
|
|
|
|
|
... test generated non prime numbers
|
|
|
|
For i = 0 to Size(nonPrimes)-1
|
|
|
|
Declare Boolean actual
|
|
|
|
Assign actual = IsPrime(nonPrimes[i])
|
|
|
|
Call AssertAreEqualBools(false, actual,"For "&nonPrimes[i]&" test "&(i+1)&"/"&Size(nonPrimes))
|
|
|
|
End
|
|
|
|
End
|
|
|
|
|
|
|
|
... more tests should be done
|
|
|
|
```
|
|
|
|
|
|
|
|
To run the test, you can run the CLI test command:
|
|
|
|
```
|
|
|
|
fg test PrimeTest.fcode
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Video
|
|
## Video
|
|
|
|
|
|
[Flowgorithm-unit_tests](/uploads/709f2a554270e4c51d17636cf85eff38/Flowgorithm-unit_tests.mp4) |
|
[Flowgorithm-unit_tests](/uploads/709f2a554270e4c51d17636cf85eff38/Flowgorithm-unit_tests.mp4) |
|
|
|
\ No newline at end of file |