test failed due to randint difference between python 2 and 3

This commit is contained in:
Edwin Eefting 2020-05-18 16:40:51 +02:00
parent 8bb9769a8b
commit 2fe854905d

View File

@ -1,5 +1,8 @@
from basetest import *
#randint is different in python 2 vs 3
randint_compat = lambda lo, hi: lo + int(random.random() * (hi + 1 - lo))
class Thing:
def __init__(self, timestamp):
@ -18,36 +21,32 @@ class TestThinner(unittest2.TestCase):
# return super().setUp()
def test_incremental(self):
ok=['2023-01-01 10:09:50',
'2024-01-01 20:06:35',
'2025-01-01 09:59:44',
'2026-01-01 18:06:41',
'2026-03-08 02:27:07',
'2026-04-07 02:29:04',
'2026-05-07 18:39:31',
'2026-06-06 06:06:14',
'2026-07-06 03:53:12',
'2026-08-05 06:23:43',
'2026-09-04 21:13:46',
'2026-10-04 00:50:48',
'2026-11-03 01:52:55',
'2026-12-03 15:04:25',
'2027-01-01 09:02:16',
'2027-01-02 09:59:16',
'2027-01-28 09:54:49',
'2027-02-01 08:59:47',
'2027-02-04 03:24:33',
'2027-02-11 01:51:49',
'2027-02-18 04:09:25',
'2027-02-19 14:21:39',
'2027-02-20 13:41:38',
'2027-02-21 07:33:50',
'2027-02-22 07:39:18',
'2027-02-23 07:52:18',
'2027-02-24 02:16:31',
'2027-02-24 02:17:08',
'2027-02-24 05:26:13',
'2027-02-24 12:56:41']
ok=['2023-01-03 10:53:16',
'2024-01-02 15:43:29',
'2025-01-01 06:15:32',
'2026-01-01 02:48:23',
'2026-04-07 20:07:36',
'2026-05-07 02:30:29',
'2026-06-06 01:19:46',
'2026-07-06 06:38:09',
'2026-08-05 05:08:53',
'2026-09-04 03:33:04',
'2026-10-04 05:27:09',
'2026-11-04 04:01:17',
'2026-12-03 13:49:56',
'2027-01-01 17:02:00',
'2027-01-03 04:26:42',
'2027-02-01 14:16:02',
'2027-02-12 03:31:02',
'2027-02-18 00:33:10',
'2027-02-26 21:09:54',
'2027-03-02 08:05:18',
'2027-03-03 16:46:09',
'2027-03-04 06:39:14',
'2027-03-06 03:35:41',
'2027-03-08 12:24:42',
'2027-03-08 20:34:57']
@ -62,8 +61,8 @@ class TestThinner(unittest2.TestCase):
for i in range(0,5000):
#increase random amount of time and maybe add a thing
now=now+random.randint(0,3600*24)
if random.random()>=0:
now=now+randint_compat(0,3600*24)
if random.random()>=0.5:
things.append(Thing(now))
(keeps, removes)=thinner.thin(things, now=now)
@ -74,49 +73,41 @@ class TestThinner(unittest2.TestCase):
for thing in things:
result.append(str(thing))
print("Thinner result:")
print("Thinner result incremental:")
pprint.pprint(result)
self.assertEqual(result, ok)
def test_full(self):
ok=['2022-02-24 15:54:37',
'2023-01-01 10:09:50',
'2024-01-01 20:06:35',
'2025-01-01 09:59:44',
'2026-01-01 18:06:41',
'2026-03-01 23:23:58',
'2026-03-08 02:27:07',
'2026-04-07 02:29:04',
'2026-05-07 18:39:31',
'2026-06-06 06:06:14',
'2026-07-06 03:53:12',
'2026-08-05 06:23:43',
'2026-09-04 21:13:46',
'2026-10-04 00:50:48',
'2026-11-03 01:52:55',
'2026-12-03 15:04:25',
'2027-01-01 09:02:16',
'2027-01-02 09:59:16',
'2027-01-25 20:00:35',
'2027-01-28 09:54:49',
'2027-02-01 08:59:47',
'2027-02-04 03:24:33',
'2027-02-11 01:51:49',
'2027-02-18 04:09:25',
'2027-02-19 14:21:39',
'2027-02-20 13:41:38',
'2027-02-21 07:33:50',
'2027-02-22 07:39:18',
'2027-02-23 07:52:18',
'2027-02-24 02:16:31',
'2027-02-24 02:17:08',
'2027-02-24 05:26:13',
'2027-02-24 12:56:41']
ok=['2022-03-09 01:56:23',
'2023-01-03 10:53:16',
'2024-01-02 15:43:29',
'2025-01-01 06:15:32',
'2026-01-01 02:48:23',
'2026-03-14 09:08:04',
'2026-04-07 20:07:36',
'2026-05-07 02:30:29',
'2026-06-06 01:19:46',
'2026-07-06 06:38:09',
'2026-08-05 05:08:53',
'2026-09-04 03:33:04',
'2026-10-04 05:27:09',
'2026-11-04 04:01:17',
'2026-12-03 13:49:56',
'2027-01-01 17:02:00',
'2027-01-03 04:26:42',
'2027-02-01 14:16:02',
'2027-02-08 02:41:14',
'2027-02-12 03:31:02',
'2027-02-18 00:33:10',
'2027-02-26 21:09:54',
'2027-03-02 08:05:18',
'2027-03-03 16:46:09',
'2027-03-04 06:39:14',
'2027-03-06 03:35:41',
'2027-03-08 12:24:42',
'2027-03-08 20:34:57']
#some arbitrary date
now=1589229252
@ -128,8 +119,8 @@ class TestThinner(unittest2.TestCase):
for i in range(0,5000):
#increase random amount of time and maybe add a thing
now=now+random.randint(0,3600*24)
if random.random()>=0:
now=now+randint_compat(0,3600*24)
if random.random()>=0.5:
things.append(Thing(now))
(things, removes)=thinner.thin(things, now=now)
@ -138,7 +129,7 @@ class TestThinner(unittest2.TestCase):
for thing in things:
result.append(str(thing))
print("Thinner result:")
print("Thinner result full:")
pprint.pprint(result)
self.assertEqual(result, ok)