mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #22551 from basepi/test.fib
Make test.fib much more naive
This commit is contained in:
commit
148ee03629
@ -253,8 +253,10 @@ def arg_repr(*args, **kwargs):
|
|||||||
|
|
||||||
def fib(num):
|
def fib(num):
|
||||||
'''
|
'''
|
||||||
Return a Fibonacci sequence up to but not including the passed number,
|
Return the num-th Fibonacci number, and the time it took to compute in
|
||||||
and the time it took to compute in seconds. Used for performance tests.
|
seconds. Used for performance tests.
|
||||||
|
|
||||||
|
This function is designed to have terrible performance.
|
||||||
|
|
||||||
CLI Example:
|
CLI Example:
|
||||||
|
|
||||||
@ -264,12 +266,18 @@ def fib(num):
|
|||||||
'''
|
'''
|
||||||
num = int(num)
|
num = int(num)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
fib_a, fib_b = 0, 1
|
if num < 2:
|
||||||
ret = [0]
|
return num, time.time() - start
|
||||||
while fib_b < num:
|
return _fib(num-1) + _fib(num-2), time.time() - start
|
||||||
ret.append(fib_b)
|
|
||||||
fib_a, fib_b = fib_b, fib_a + fib_b
|
|
||||||
return ret, time.time() - start
|
def _fib(num):
|
||||||
|
'''
|
||||||
|
Helper method for test.fib, doesn't calculate the time.
|
||||||
|
'''
|
||||||
|
if num < 2:
|
||||||
|
return num
|
||||||
|
return _fib(num-1) + _fib(num-2)
|
||||||
|
|
||||||
|
|
||||||
def collatz(start):
|
def collatz(start):
|
||||||
|
@ -28,9 +28,9 @@ class TestSyndic(integration.SyndicCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.run_function(
|
self.run_function(
|
||||||
'test.fib',
|
'test.fib',
|
||||||
['40'],
|
['20'],
|
||||||
)[0][-1],
|
)[0],
|
||||||
34
|
6765
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,10 +88,10 @@ class PublishModuleTest(integration.ModuleCase,
|
|||||||
'''
|
'''
|
||||||
ret = self.run_function(
|
ret = self.run_function(
|
||||||
'publish.full_data',
|
'publish.full_data',
|
||||||
['minion', 'test.fib', 40]
|
['minion', 'test.fib', 20]
|
||||||
)
|
)
|
||||||
self.assertTrue(ret)
|
self.assertTrue(ret)
|
||||||
self.assertEqual(ret['minion']['ret'][0][-1], 34)
|
self.assertEqual(ret['minion']['ret'][0], 6765)
|
||||||
|
|
||||||
def test_kwarg(self):
|
def test_kwarg(self):
|
||||||
'''
|
'''
|
||||||
|
@ -73,9 +73,9 @@ class TestModuleTest(integration.ModuleCase,
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.run_function(
|
self.run_function(
|
||||||
'test.fib',
|
'test.fib',
|
||||||
['40'],
|
['20'],
|
||||||
)[0][-1],
|
)[0],
|
||||||
34
|
6765
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_collatz(self):
|
def test_collatz(self):
|
||||||
|
@ -34,10 +34,6 @@ class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||||||
out = self.run_call('-l quiet test.fib 3')
|
out = self.run_call('-l quiet test.fib 3')
|
||||||
|
|
||||||
expect = ['local:',
|
expect = ['local:',
|
||||||
' |_',
|
|
||||||
' - 0',
|
|
||||||
' - 1',
|
|
||||||
' - 1',
|
|
||||||
' - 2']
|
' - 2']
|
||||||
self.assertEqual(expect, out[:-1])
|
self.assertEqual(expect, out[:-1])
|
||||||
|
|
||||||
@ -45,7 +41,7 @@ class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||||||
out = self.run_call('-l quiet --out txt test.fib 3')
|
out = self.run_call('-l quiet --out txt test.fib 3')
|
||||||
|
|
||||||
expect = [
|
expect = [
|
||||||
'local: ([0, 1, 1, 2]'
|
'local: (2'
|
||||||
]
|
]
|
||||||
|
|
||||||
self.assertEqual(''.join(expect), ''.join(out).rsplit(",", 1)[0])
|
self.assertEqual(''.join(expect), ''.join(out).rsplit(",", 1)[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user