add time module and move fixed-point iteration to own function
This commit is contained in:
95
tests/test_time_of_day.py
Normal file
95
tests/test_time_of_day.py
Normal file
@@ -0,0 +1,95 @@
|
||||
"""Test of fit module.
|
||||
|
||||
:Date: 2019-06-01
|
||||
|
||||
.. module:: test_fit
|
||||
:platform: *nix, Windows
|
||||
:synopsis: Test of fit module.
|
||||
|
||||
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
|
||||
"""
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
import unittest
|
||||
from time import mktime
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('../src'))
|
||||
from time_of_day import (in_seconds, seconds, seconds_norm,
|
||||
minutes, minutes_norm, hours, hours_norm, days, days_norm,
|
||||
transform)
|
||||
|
||||
# tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec,
|
||||
# tm_wday, tm_yday, tm_isdst
|
||||
T = mktime((2000, 11, 30, 0, 10, 20, 3, 335, -1))
|
||||
|
||||
|
||||
class TestTimeOfDay(unittest.TestCase):
|
||||
|
||||
def test_in_seconds(self):
|
||||
"""test in_seconds"""
|
||||
t = in_seconds(T)
|
||||
self.assertEqual(t, 975539420.0)
|
||||
|
||||
def test_seconds(self):
|
||||
"""test seconds"""
|
||||
t = seconds(T)
|
||||
self.assertEqual(t, 20.0)
|
||||
|
||||
def test_seconds_norm(self):
|
||||
"""test seconds_norm"""
|
||||
t = seconds_norm(T)
|
||||
self.assertEqual(t, 20.0/60) # 0.3333333333333333
|
||||
|
||||
def test_minutes(self):
|
||||
"""test minutes"""
|
||||
t = minutes(T)
|
||||
self.assertEqual(t, T/60%60) # 10.333333333954215
|
||||
|
||||
def test_minutes_norm(self):
|
||||
"""test minutes_norm"""
|
||||
t = minutes_norm(T)
|
||||
self.assertEqual(t, T/60%60/60) # 0.17222222223257025
|
||||
|
||||
def test_hours(self):
|
||||
"""test hours"""
|
||||
t = hours(T)
|
||||
self.assertEqual(t, T/60/60%24) # 23.172222222259734
|
||||
|
||||
def test_hours_norm(self):
|
||||
"""test hours_norm"""
|
||||
t = hours_norm(T)
|
||||
self.assertEqual(t, T/60/60%24/24) # 0.9655092592608222
|
||||
|
||||
def test_days(self):
|
||||
"""test days"""
|
||||
t = days(T)
|
||||
self.assertEqual(t, T/60/60/24%365.2425) # 333.69050925926
|
||||
|
||||
def test_days_norm(self):
|
||||
"""test days_norm"""
|
||||
t = days_norm(T)
|
||||
# 0.9136135834664915
|
||||
self.assertEqual(t, T/60/60/24%365.2425/365.2425)
|
||||
|
||||
def test_transform_minutes(self):
|
||||
"""test transform minutes"""
|
||||
min_norm = minutes_norm(T)
|
||||
x_len = 30
|
||||
x_offset = -8
|
||||
x_pos = transform(min_norm, x_len, x_offset)
|
||||
# -2.8333333330228925
|
||||
self.assertEqual(x_pos, min_norm*x_len + x_offset)
|
||||
|
||||
def test_transform_hours(self):
|
||||
"""test transform hours"""
|
||||
h_norm = hours_norm(T)
|
||||
y_len = 20
|
||||
y_offset = -10
|
||||
y_pos = transform(h_norm, y_len, y_offset)
|
||||
# 9.310185185216444
|
||||
self.assertEqual(y_pos, h_norm*y_len + y_offset)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user