Einzelnen Beitrag anzeigen

Benutzerbild von Phoenix
Phoenix
(Moderator)

Registriert seit: 25. Jun 2002
Ort: Hausach
7.606 Beiträge
 
#13

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)

  Alt 15. Dez 2022, 10:41
Schließlich hat der Chatbot seine Intelligenz ja auch nur aus dem Internet und der dort herumgeisternde Code ist zuweilen schon recht grenzwertig, was das Pacman-Beispiel ja sehr deutlich aufzeigt.
Ich denke auch, das ist copy and paste von irgendwo gefundenem Code.
Ist es nicht. ChatGPT erstellt ein semantisches und syntaktisches Modell der generierten Antwort (und damit auch des generierten Codes).
Du kannst ihm spezifisch sagen was Du geändert haben möchtest, z.B. das Du möchtest das der Methodenname mit Combine beginnt statt mit Add. Er versteht auch - zumindest grob - den Inhalt der Funktion und kann passende Unit-Tests generieren:

Zitat von Phoenix:
Now please write a unit test for this function that tests specifically the extreme values for frequency and offset
Zitat von ChatGPT:
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.
Sebastian Gingter
Phoenix - 不死鳥, Microsoft MVP, Rettungshundeführer
Über mich: Sebastian Gingter @ Thinktecture Mein Blog: https://gingter.org
  Mit Zitat antworten Zitat