master > master: code - assertions korrigiert (index == -1 ist in Ordnung, wenn erwartet)
This commit is contained in:
parent
965cd48ae6
commit
82962e376d
@ -26,8 +26,11 @@ def preChecks(L: List[int], **_):
|
||||
return;
|
||||
|
||||
def postChecks(L: List[int], x: int, index: int, **_):
|
||||
value = L[index] if index >= 0 else None;
|
||||
assert value == x, 'Der Algorithmus hat versagt.';
|
||||
if x in L:
|
||||
assert index >= 0, 'Der Algorithmus sollte nicht -1 zurückgeben.';
|
||||
assert L[index] == x, 'Der Algorithmus hat den falschen Index bestimmt.';
|
||||
else:
|
||||
assert index == -1, 'Der Algorithmus sollte -1 zurückgeben.';
|
||||
return;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -25,16 +25,19 @@ def preChecks(L: List[int], **_):
|
||||
assert L == sorted(L), 'Ungültiger Input: L muss aufsteigend sortiert sein!';
|
||||
return;
|
||||
|
||||
def postChecks(L: List[int], x: int, p: int, **_):
|
||||
value = L[p] if p >= 0 else None;
|
||||
assert value == x, 'Der Algorithmus hat versagt.';
|
||||
def postChecks(L: List[int], x: int, index: int, **_):
|
||||
if x in L:
|
||||
assert index >= 0, 'Der Algorithmus sollte nicht -1 zurückgeben.';
|
||||
assert L[index] == x, 'Der Algorithmus hat den falschen Index bestimmt.';
|
||||
else:
|
||||
assert index == -1, 'Der Algorithmus sollte -1 zurückgeben.';
|
||||
return;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# ALGORITHM interpolation
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@algorithmInfos(name='Interpolationssuchalgorithmus', outputnames='p', checks=True, metrics=True, preChecks=preChecks, postChecks=postChecks)
|
||||
@algorithmInfos(name='Interpolationssuchalgorithmus', outputnames='index', checks=True, metrics=True, preChecks=preChecks, postChecks=postChecks)
|
||||
def InterpolationSearch(L: List[int], x: int, u: int, v: int) -> int:
|
||||
'''
|
||||
Inputs: L = Liste von Zahlen, x = Zahl, [u, v] = Suchinterval.
|
||||
|
@ -28,8 +28,8 @@ def preChecks(L: List[int], i: int, **_):
|
||||
return;
|
||||
|
||||
def postChecks(L: List[int], i: int, value: int, **_):
|
||||
L_ = sorted(L);
|
||||
assert L_[i-1] == value, 'Der Algorithmus hat versagt.';
|
||||
L = sorted(L);
|
||||
assert L[i-1] == value, 'Der Algorithmus hat versagt.';
|
||||
return;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -28,8 +28,11 @@ def preChecks(L: List[int], **_):
|
||||
return;
|
||||
|
||||
def postChecks(L: List[int], x: int, index: int, **_):
|
||||
value = L[index] if index >= 0 else None;
|
||||
assert value == x, 'Der Algorithmus hat versagt.';
|
||||
if x in L:
|
||||
assert index >= 0, 'Der Algorithmus sollte nicht -1 zurückgeben.';
|
||||
assert L[index] == x, 'Der Algorithmus hat den falschen Index bestimmt.';
|
||||
else:
|
||||
assert index == -1, 'Der Algorithmus sollte -1 zurückgeben.';
|
||||
return;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -26,8 +26,11 @@ def preChecks(L: List[int], **_):
|
||||
return;
|
||||
|
||||
def postChecks(L: List[int], x: int, index: int, **_):
|
||||
value = L[index] if index >= 0 else None;
|
||||
assert value == x, 'Der Algorithmus hat versagt.';
|
||||
if x in L:
|
||||
assert index >= 0, 'Der Algorithmus sollte nicht -1 zurückgeben.';
|
||||
assert L[index] == x, 'Der Algorithmus hat den falschen Index bestimmt.';
|
||||
else:
|
||||
assert index == -1, 'Der Algorithmus sollte -1 zurückgeben.';
|
||||
return;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
Loading…
x
Reference in New Issue
Block a user