xautodl/tests/test_synthetic_utils.py

32 lines
1.1 KiB
Python
Raw Normal View History

2021-04-13 19:04:46 +02:00
#####################################################
# Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2021.03 #
#####################################################
2021-04-22 17:08:43 +02:00
# pytest tests/test_synthetic_utils.py -s #
2021-04-13 19:04:46 +02:00
#####################################################
import sys, random
import unittest
import pytest
from pathlib import Path
lib_dir = (Path(__file__).parent / ".." / "lib").resolve()
print("library path: {:}".format(lib_dir))
if str(lib_dir) not in sys.path:
sys.path.insert(0, str(lib_dir))
2021-05-09 12:53:18 +02:00
from datasets.synthetic_core import TimeStamp
2021-04-13 19:04:46 +02:00
2021-04-26 14:16:38 +02:00
class TestTimeStamp(unittest.TestCase):
"""Test the timestamp generator."""
2021-04-22 13:12:21 +02:00
def test_simple(self):
2021-04-26 14:16:38 +02:00
for mode in (None, "train", "valid", "test"):
generator = TimeStamp(0, 1)
print(generator)
for idx, (i, xtime) in enumerate(generator):
self.assertTrue(i == idx)
if idx == 0:
self.assertTrue(xtime == 0)
if idx + 1 == len(generator):
self.assertTrue(abs(xtime - 1) < 1e-8)