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;
|
return;
|
||||||
|
|
||||||
def postChecks(L: List[int], x: int, index: int, **_):
|
def postChecks(L: List[int], x: int, index: int, **_):
|
||||||
value = L[index] if index >= 0 else None;
|
if x in L:
|
||||||
assert value == x, 'Der Algorithmus hat versagt.';
|
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;
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -25,16 +25,19 @@ def preChecks(L: List[int], **_):
|
|||||||
assert L == sorted(L), 'Ungültiger Input: L muss aufsteigend sortiert sein!';
|
assert L == sorted(L), 'Ungültiger Input: L muss aufsteigend sortiert sein!';
|
||||||
return;
|
return;
|
||||||
|
|
||||||
def postChecks(L: List[int], x: int, p: int, **_):
|
def postChecks(L: List[int], x: int, index: int, **_):
|
||||||
value = L[p] if p >= 0 else None;
|
if x in L:
|
||||||
assert value == x, 'Der Algorithmus hat versagt.';
|
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;
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# ALGORITHM interpolation
|
# 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:
|
def InterpolationSearch(L: List[int], x: int, u: int, v: int) -> int:
|
||||||
'''
|
'''
|
||||||
Inputs: L = Liste von Zahlen, x = Zahl, [u, v] = Suchinterval.
|
Inputs: L = Liste von Zahlen, x = Zahl, [u, v] = Suchinterval.
|
||||||
|
@ -28,8 +28,8 @@ def preChecks(L: List[int], i: int, **_):
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
def postChecks(L: List[int], i: int, value: int, **_):
|
def postChecks(L: List[int], i: int, value: int, **_):
|
||||||
L_ = sorted(L);
|
L = sorted(L);
|
||||||
assert L_[i-1] == value, 'Der Algorithmus hat versagt.';
|
assert L[i-1] == value, 'Der Algorithmus hat versagt.';
|
||||||
return;
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -28,8 +28,11 @@ def preChecks(L: List[int], **_):
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
def postChecks(L: List[int], x: int, index: int, **_):
|
def postChecks(L: List[int], x: int, index: int, **_):
|
||||||
value = L[index] if index >= 0 else None;
|
if x in L:
|
||||||
assert value == x, 'Der Algorithmus hat versagt.';
|
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;
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -26,8 +26,11 @@ def preChecks(L: List[int], **_):
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
def postChecks(L: List[int], x: int, index: int, **_):
|
def postChecks(L: List[int], x: int, index: int, **_):
|
||||||
value = L[index] if index >= 0 else None;
|
if x in L:
|
||||||
assert value == x, 'Der Algorithmus hat versagt.';
|
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;
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
Loading…
x
Reference in New Issue
Block a user