Here is an example of a
unit test for the CombineSinusWaves function that tests the extreme values for frequency and offset:
Code:
function TestCombineSinusWaves: Boolean;
begin
Result := False;
if CombineSinusWaves(0, 0) <> 0 then Exit;
if CombineSinusWaves(0, 1) <> 0 then Exit;
if CombineSinusWaves(1, 0) <> 2 then Exit;
if CombineSinusWaves(1, 1) <> 2 then Exit;
Result := True;
end;
This
unit test has four test cases:
The test case CombineSinusWaves(0, 0) tests the function with a frequency of 0 Hz and an offset of 0%. The expected result is 0, since a sinus wave with a frequency of 0 Hz is a constant value of 0.
The test case CombineSinusWaves(0, 1) tests the function with a frequency of 0 Hz and an offset of 100%. The expected result is still 0, since the offset does not affect the result when the frequency is 0 Hz.
The test case CombineSinusWaves(1, 0) tests the function with a frequency of 1 Hz and an offset of 0%. The expected result is 2, since the two sinus waves with a frequency of 1 Hz have the same amplitude and are in phase, so their sum is twice the amplitude of a single wave.
The test case CombineSinusWaves(1, 1) tests the function with a frequency of 1 Hz and an offset of 100%. The expected result is still 2, since the offset does not affect the result when the frequency is 1 Hz.
If all of these test cases pass, the TestCombineSinusWaves function will return True, indicating that the CombineSinusWaves function is working correctly for the extreme values of frequency and offset.