Groups | Search | Server Info | Login | Register
Groups > de.alt.folklore.computer > #50992
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | ram@zedat.fu-berlin.de (Stefan Ram) |
| Newsgroups | de.alt.folklore.computer |
| Subject | Re: Chatbot-Demo |
| Date | 30 Jun 2025 12:15:13 GMT |
| Organization | Stefan Ram |
| Lines | 184 |
| Expires | 1 Jun 2026 11:59:58 GMT |
| Message-ID | <Tests-20250630130820@ram.dialup.fu-berlin.de> (permalink) |
| References | <Beispiel-20250629142849@ram.dialup.fu-berlin.de> <prompt-20250629143415@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.uni-berlin.de D+pyIhXtyxg8cwZqfGA/tAI7tmw/t/yatJvKASZN3N7Evc |
| Cancel-Lock | sha1:tLkM/mJ0UT6GuRqpzIbXtz9MGEc= sha256:EVpkQ9UtDSBG8UPHrNKizYOjhn3cHYARZD8A0/foqBM= |
| X-Copyright | (C) Copyright 2025 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. |
| X-No-Archive | Yes |
| Archive | no |
| X-No-Archive-Readme | "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. |
| X-No-Html | yes |
| Content-Language | de-DE-1901 |
| Xref | csiph.com de.alt.folklore.computer:50992 |
Show key headers only | View raw
ram@zedat.fu-berlin.de (Stefan Ram) schrieb oder zitierte:
>|Bitte schreibe Tests für eine Python-Funktion "length", deren
Die erste Antwort des Chatbots setzte eine bestimmte Python-
Erweiterung "pytest" voraus. Ich habe ihn dann noch gebeten,
den Code so umzuschreiben, daß er auch ohne "pytest" läuft.
Dadurch ergibt sich aber nun gegen Ende des Codes eine etwas
längliche Aufzählung "Liste aller Testfunktionen". Man könnte
diese auch wieder verkürzen, aber ich lasse es jetzt mal so.
In den generierten Tests bemerkt man:
- Einige Tests sind redundant und wiederholen im Prinzip nur
andere Tests.
- In einigen Tests hat der Chatbot die Zeichen nicht ganz
richtig gezählt. Eingaben werden für Chatbots in lexikalische
Einheiten gewandelt, die oft mehrere Zeichen zusammenfassen
und manchmal keine Leerzeichen mehr enthalten.
Bei der Erzeugung von Ausgaben geschieht vermutlich etwas
Ähnliches. Daher haben Chatbots Schwierigkeiten, wenn es um
den Umgang mit einzelnen Schriftzeichen und Leerzeichen geht.
Hier sind also nun die vom Chatbot generierten Tests:
# Test-Suite für die Funktion length(obj)
import sys
def run_test(test_func):
try:
test_func()
print(f"{test_func.__name__}: OK")
return True
except AssertionError as e:
print(f"{test_func.__name__}: FAIL ({e})")
return False
except Exception as e:
print(f"{test_func.__name__}: ERROR ({e})")
return False
def test_empty_list():
assert length([]) == 0
def test_list_with_empty_string():
assert length(['']) == 0
def test_list_with_single_string():
assert length(['abc']) == 3
def test_list_with_multiple_strings():
assert length(['a', 'bc', 'def']) == 6
def test_list_with_nested_empty_lists():
assert length([[], [[]], [[[]]]]) == 0
def test_list_with_nested_strings():
assert length([['a', ['bc']], 'd']) == 4
def test_list_with_deep_nesting():
assert length([[[[[['hello']]]]]]) == 5
def test_list_with_empty_strings_nested():
assert length([['', ['', ['']]], '']) == 0
def test_list_with_mixed_empty_and_nonempty_strings():
assert length(['', ['a', '', ['bc', '']]]) == 3
def test_list_with_long_string():
s = 'x' * 1000
assert length([s]) == 1000
def test_list_with_multiple_types():
# Nur Listen und Strings erlaubt, keine anderen Typen!
assert length(['a', ['b', ['c']]]) == 3
def test_list_with_multiple_empty_levels():
assert length([[], [[[], []]], []]) == 0
def test_list_with_strings_and_empty_lists():
assert length(['abc', [], ['d', []], 'ef']) == 6
def test_list_with_unicode_strings():
assert length(['ü', 'ß', '你好']) == 4 # 'ü'->1, 'ß'->1, '你好'->2
def test_list_with_large_structure():
data = [['a'] * 100] * 10 # 10 Listen mit je 100 'a'
assert length(data) == 1000
def test_list_with_extreme_nesting_and_empty_strings():
data = [[[[[[['']]]]]]]
assert length(data) == 0
def test_list_with_only_empty_strings():
assert length(['', ['', ''], ['']]) == 0
def test_list_with_strings_containing_spaces():
assert length([' ', ' ', 'abc ']) == 6
def test_list_with_mixed_content():
assert length(['a', ['bc', '', ['def', ['']]], 'g']) == 7
# Aggressive Tests
def test_list_with_very_deep_nesting():
data = 'x'
for _ in range(1000):
data = [data]
assert length(data) == 1
def test_list_with_large_number_of_strings():
data = ['a'] * 10000
assert length(data) == 10000
def test_list_with_large_number_of_empty_strings():
data = [''] * 10000
assert length(data) == 0
def test_list_with_long_strings_and_nesting():
s = 'abc' * 1000
data = [[s, [s]], s]
assert length(data) == 3 * 1000 * 3 # 3 Strings à 3000 Zeichen
def test_list_with_mixed_empty_and_long_strings():
data = ['', [''], [['']], 'x' * 5000]
assert length(data) == 5000
def test_list_with_strings_with_newlines():
assert length(['a\nb', ['c\nd', 'e']]) == 6
# Optional: Test für sehr große Tiefe (kann RecursionError auslösen)
def test_list_with_extreme_depth():
data = 'x'
for _ in range(2000):
data = [data]
try:
result = length(data)
assert result == 1
except RecursionError:
print("test_list_with_extreme_depth: SKIPPED (Recursion limit reached)")
return
print("test_list_with_extreme_depth: OK")
if __name__ == "__main__":
# Liste aller Testfunktionen
tests = [
test_empty_list,
test_list_with_empty_string,
test_list_with_single_string,
test_list_with_multiple_strings,
test_list_with_nested_empty_lists,
test_list_with_nested_strings,
test_list_with_deep_nesting,
test_list_with_empty_strings_nested,
test_list_with_mixed_empty_and_nonempty_strings,
test_list_with_long_string,
test_list_with_multiple_types,
test_list_with_multiple_empty_levels,
test_list_with_strings_and_empty_lists,
test_list_with_unicode_strings,
test_list_with_large_structure,
test_list_with_extreme_nesting_and_empty_strings,
test_list_with_only_empty_strings,
test_list_with_strings_containing_spaces,
test_list_with_mixed_content,
test_list_with_very_deep_nesting,
test_list_with_large_number_of_strings,
test_list_with_large_number_of_empty_strings,
test_list_with_long_strings_and_nesting,
test_list_with_mixed_empty_and_long_strings,
test_list_with_strings_with_newlines,
test_list_with_extreme_depth,
]
passed = 0
for test in tests:
if test.__name__ == "test_list_with_extreme_depth":
test()
continue
if run_test(test):
passed += 1
print(f"\n{passed}/{len(tests)} Tests bestanden.")
Lies morgen weiter: Der Prompt zur Generierung der Funktion "length"!
Back to de.alt.folklore.computer | Previous | Next — Previous in thread | Next in thread | Find similar
Chatbot-Demo ram@zedat.fu-berlin.de (Stefan Ram) - 2025-06-29 13:29 +0000
Re: Chatbot-Demo ram@zedat.fu-berlin.de (Stefan Ram) - 2025-06-29 13:37 +0000
Re: Chatbot-Demo Ulf Kutzner <user2991@newsgrouper.org.invalid> - 2025-06-29 13:47 +0000
Re: Chatbot-Demo Marc Haber <mh+usenetspam1118@zugschl.us> - 2025-06-30 10:22 +0200
Re: Chatbot-Demo Ulf Kutzner <user2991@newsgrouper.org.invalid> - 2025-06-30 08:32 +0000
Re: Chatbot-Demo ram@zedat.fu-berlin.de (Stefan Ram) - 2025-06-30 12:15 +0000
Re: Chatbot-Demo ram@zedat.fu-berlin.de (Stefan Ram) - 2025-07-01 10:22 +0000
Re: Chatbot-Demo michaelnoeusenet@mac.com (Michael Noe) - 2025-07-01 21:31 +0200
Re: Chatbot-Demo ram@zedat.fu-berlin.de (Stefan Ram) - 2025-07-02 12:24 +0000
Re: Chatbot-Demo Thomas Koenig <tkoenig@netcologne.de> - 2025-07-02 16:56 +0000
Re: Chatbot-Demo michaelnoeusenet@mac.com (Michael Noe) - 2025-07-03 18:00 +0200
Re: Chatbot-Demo mlelstv@serpens.de (Michael van Elst) - 2025-07-03 16:37 +0000
Re: Chatbot-Demo michaelnoeusenet@mac.com (Michael Noe) - 2025-07-03 22:07 +0200
Re: Chatbot-Demo ram@zedat.fu-berlin.de (Stefan Ram) - 2025-07-03 13:00 +0000
Re: Chatbot-Demo ram@zedat.fu-berlin.de (Stefan Ram) - 2025-07-04 14:08 +0000
42 (was: Chatbot-Demo) michaelnoeusenet@mac.com (Michael Noe) - 2025-07-05 17:48 +0200
Nicht auch noch $HIER! (was: Chatbot-Demo) Kay Martinen <usenet@martinen.de> - 2025-06-29 16:47 +0200
Re: Nicht auch noch $HIER! michaelnoeusenet@mac.com (Michael Noe) - 2025-06-29 17:41 +0200
Re: Nicht auch noch $HIER! Thomas Koenig <tkoenig@netcologne.de> - 2025-06-29 20:41 +0000
Re: Nicht auch noch $HIER! Andreas Bockelmann <xotzil@gmx.de> - 2025-07-02 08:33 +0200
csiph-web