mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-01 19:38:20 +08:00
update for python unittest
This commit is contained in:
parent
d365a87c8a
commit
afa5a0df93
@ -2,10 +2,10 @@
|
||||
# -*- coding: utf8 -*-
|
||||
# cp936
|
||||
|
||||
#===============================================================================
|
||||
# ===============================================================================
|
||||
# 作者:fasiondog
|
||||
# 历史:1)20120927, Added by fasiondog
|
||||
#===============================================================================
|
||||
# ===============================================================================
|
||||
|
||||
import unittest
|
||||
|
||||
@ -24,16 +24,16 @@ class DatetimeTest(unittest.TestCase):
|
||||
self.assertEqual(Datetime(140001010000), Datetime.min())
|
||||
self.assertEqual(Datetime(999912310000), Datetime.max())
|
||||
|
||||
self.assert_(d == Datetime(201209272301))
|
||||
self.assert_(d != Datetime(200101010000))
|
||||
self.assert_(d >= Datetime(201209272301))
|
||||
self.assert_(d >= Datetime(201209272259))
|
||||
self.assert_(d <= Datetime(201209272301))
|
||||
self.assert_(d <= Datetime(201209272302))
|
||||
self.assert_(not (d > Datetime(201209272301)))
|
||||
self.assert_(d > Datetime(201209272259))
|
||||
self.assert_(not (d < Datetime(201209272301)))
|
||||
self.assert_(d < Datetime(201209272302))
|
||||
self.assertEqual(d, Datetime(201209272301))
|
||||
self.assertNotEqual(d, Datetime(200101010000))
|
||||
self.assertGreaterEqual(d, Datetime(201209272301))
|
||||
self.assertTrue(d >= Datetime(201209272259))
|
||||
self.assertTrue(d <= Datetime(201209272301))
|
||||
self.assertTrue(d <= Datetime(201209272302))
|
||||
self.assertTrue(not (d > Datetime(201209272301)))
|
||||
self.assertTrue(d > Datetime(201209272259))
|
||||
self.assertTrue(not (d < Datetime(201209272301)))
|
||||
self.assertTrue(d < Datetime(201209272302))
|
||||
|
||||
d = Datetime(200101010159)
|
||||
self.assertEqual(str(d), "2001-01-01 01:59:00")
|
||||
|
@ -48,10 +48,10 @@ class IndicatorTest(unittest.TestCase):
|
||||
self.assertEqual(m.name, "AddIndicator")
|
||||
self.assertEqual(len(m), 4)
|
||||
self.assertEqual(m.empty(), False)
|
||||
self.assert_(abs(m[0] - 1) < 0.0001)
|
||||
self.assert_(abs(m[1] - 2) < 0.0001)
|
||||
self.assert_(abs(m[2] - 3) < 0.0001)
|
||||
self.assert_(abs(m[3] - 4) < 0.0001)
|
||||
self.assertTrue(abs(m[0] - 1) < 0.0001)
|
||||
self.assertTrue(abs(m[1] - 2) < 0.0001)
|
||||
self.assertTrue(abs(m[2] - 3) < 0.0001)
|
||||
self.assertTrue(abs(m[3] - 4) < 0.0001)
|
||||
|
||||
b = toPriceList([1, 2, 3, 4])
|
||||
x = PRICELIST(b)
|
||||
@ -59,10 +59,10 @@ class IndicatorTest(unittest.TestCase):
|
||||
m = m(x)
|
||||
self.assertEqual(len(m), 4)
|
||||
self.assertEqual(m.empty(), False)
|
||||
self.assert_(abs(m[0] - 2) < 0.0001)
|
||||
self.assert_(abs(m[1] - 3) < 0.0001)
|
||||
self.assert_(abs(m[2] - 4) < 0.0001)
|
||||
self.assert_(abs(m[3] - 5) < 0.0001)
|
||||
self.assertTrue(abs(m[0] - 2) < 0.0001)
|
||||
self.assertTrue(abs(m[1] - 3) < 0.0001)
|
||||
self.assertTrue(abs(m[2] - 4) < 0.0001)
|
||||
self.assertTrue(abs(m[3] - 5) < 0.0001)
|
||||
|
||||
def test_operator(self):
|
||||
a = toPriceList([0, 1, 2, 3, 5])
|
||||
@ -76,16 +76,16 @@ class IndicatorTest(unittest.TestCase):
|
||||
self.assertEqual(a[3], 7)
|
||||
|
||||
a = x1 + 1.1
|
||||
self.assert_(abs(a[0] - 1.1) < 0.0001)
|
||||
self.assert_(abs(a[1] - 2.1) < 0.0001)
|
||||
self.assert_(abs(a[2] - 3.1) < 0.0001)
|
||||
self.assert_(abs(a[3] - 4.1) < 0.0001)
|
||||
self.assertTrue(abs(a[0] - 1.1) < 0.0001)
|
||||
self.assertTrue(abs(a[1] - 2.1) < 0.0001)
|
||||
self.assertTrue(abs(a[2] - 3.1) < 0.0001)
|
||||
self.assertTrue(abs(a[3] - 4.1) < 0.0001)
|
||||
|
||||
a = 2.1 + x1
|
||||
self.assert_(abs(a[0] - 2.1) < 0.0001)
|
||||
self.assert_(abs(a[1] - 3.1) < 0.0001)
|
||||
self.assert_(abs(a[2] - 4.1) < 0.0001)
|
||||
self.assert_(abs(a[3] - 5.1) < 0.0001)
|
||||
self.assertTrue(abs(a[0] - 2.1) < 0.0001)
|
||||
self.assertTrue(abs(a[1] - 3.1) < 0.0001)
|
||||
self.assertTrue(abs(a[2] - 4.1) < 0.0001)
|
||||
self.assertTrue(abs(a[3] - 5.1) < 0.0001)
|
||||
|
||||
a = x2 - x1
|
||||
self.assertEqual(a[0], 1)
|
||||
@ -124,10 +124,10 @@ class IndicatorTest(unittest.TestCase):
|
||||
self.assertEqual(a[3], 6)
|
||||
|
||||
a = x2 / x1
|
||||
self.assert_(isinf(a[0]))
|
||||
self.assertTrue(isinf(a[0]))
|
||||
self.assertEqual(a[1], 2)
|
||||
self.assertEqual(a[2], 1.5)
|
||||
self.assert_(abs(a[3] - 4.0 / 3.0) < 0.0001)
|
||||
self.assertTrue(abs(a[3] - 4.0 / 3.0) < 0.0001)
|
||||
|
||||
a = x1 / 0.5
|
||||
self.assertEqual(a[0], 0)
|
||||
@ -136,10 +136,10 @@ class IndicatorTest(unittest.TestCase):
|
||||
self.assertEqual(a[3], 6)
|
||||
|
||||
a = 2. / x1
|
||||
self.assert_(isinf(a[0]))
|
||||
self.assertTrue(isinf(a[0]))
|
||||
self.assertEqual(a[1], 2.0)
|
||||
self.assertEqual(a[2], 1.)
|
||||
self.assert_(abs(a[3] - 2.0/3.0) < 0.0001)
|
||||
self.assertTrue(abs(a[3] - 2.0/3.0) < 0.0001)
|
||||
|
||||
a = x1 > x2
|
||||
self.assertEqual(a[0], 0 > 1)
|
||||
@ -180,19 +180,19 @@ class IndicatorTest(unittest.TestCase):
|
||||
self.assertEqual(a.empty(), False)
|
||||
self.assertEqual(v.empty(), False)
|
||||
|
||||
self.assert_(abs(o[0] - 96.05) < 0.0001)
|
||||
self.assert_(abs(h[0] - 99.98) < 0.0001)
|
||||
self.assert_(abs(l[0] - 95.79) < 0.0001)
|
||||
self.assert_(abs(c[0] - 99.98) < 0.0001)
|
||||
self.assert_(abs(a[0] - 49.4) < 0.0001)
|
||||
self.assert_(abs(v[0] - 1260) < 0.0001)
|
||||
self.assertTrue(abs(o[0] - 96.05) < 0.0001)
|
||||
self.assertTrue(abs(h[0] - 99.98) < 0.0001)
|
||||
self.assertTrue(abs(l[0] - 95.79) < 0.0001)
|
||||
self.assertTrue(abs(c[0] - 99.98) < 0.0001)
|
||||
self.assertTrue(abs(a[0] - 49.4) < 0.0001)
|
||||
self.assertTrue(abs(v[0] - 1260) < 0.0001)
|
||||
|
||||
self.assert_(abs(o[1] - 104.3) < 0.0001)
|
||||
self.assert_(abs(h[1] - 104.39) < 0.0001)
|
||||
self.assert_(abs(l[1] - 99.98) < 0.0001)
|
||||
self.assert_(abs(c[1] - 104.39) < 0.0001)
|
||||
self.assert_(abs(a[1] - 8.4) < 0.0001)
|
||||
self.assert_(abs(v[1] - 197) < 0.0001)
|
||||
self.assertTrue(abs(o[1] - 104.3) < 0.0001)
|
||||
self.assertTrue(abs(h[1] - 104.39) < 0.0001)
|
||||
self.assertTrue(abs(l[1] - 99.98) < 0.0001)
|
||||
self.assertTrue(abs(c[1] - 104.39) < 0.0001)
|
||||
self.assertTrue(abs(a[1] - 8.4) < 0.0001)
|
||||
self.assertTrue(abs(v[1] - 197) < 0.0001)
|
||||
|
||||
def test_MA(self):
|
||||
a = toPriceList([0, 1, 2, 3])
|
||||
@ -200,10 +200,10 @@ class IndicatorTest(unittest.TestCase):
|
||||
m = MA(x, 2)
|
||||
self.assertEqual(len(m), 4)
|
||||
self.assertEqual(m.discard, 0)
|
||||
self.assert_(abs(m[0] - 0.0) < 0.0001)
|
||||
self.assert_(abs(m[1] - 0.5) < 0.0001)
|
||||
self.assert_(abs(m[2] - 1.5) < 0.0001)
|
||||
self.assert_(abs(m[3] - 2.5) < 0.0001)
|
||||
self.assertTrue(abs(m[0] - 0.0) < 0.0001)
|
||||
self.assertTrue(abs(m[1] - 0.5) < 0.0001)
|
||||
self.assertTrue(abs(m[2] - 1.5) < 0.0001)
|
||||
self.assertTrue(abs(m[3] - 2.5) < 0.0001)
|
||||
|
||||
def test_pickle(self):
|
||||
if not constant.pickle_support:
|
||||
|
@ -2,10 +2,10 @@
|
||||
# -*- coding: utf8 -*-
|
||||
# gb18030
|
||||
|
||||
#===============================================================================
|
||||
# ===============================================================================
|
||||
# 作者:fasiondog
|
||||
# 历史:1)20130220, Added by fasiondog
|
||||
#===============================================================================
|
||||
# ===============================================================================
|
||||
|
||||
import unittest
|
||||
|
||||
@ -33,14 +33,14 @@ class KDataTest(unittest.TestCase):
|
||||
self.assertEqual(k.end_pos, 10)
|
||||
self.assertEqual(k.last_pos, 9)
|
||||
self.assertEqual(k[0].datetime, Datetime(199012190000))
|
||||
self.assert_(abs(k[0].open - 96.05) < 0.0001)
|
||||
self.assert_(abs(k[0].high - 99.980) < 0.0001)
|
||||
self.assert_(abs(k[0].low - 95.79) < 0.0001)
|
||||
self.assert_(abs(k[0].close - 99.98) < 0.0001)
|
||||
self.assert_(abs(k[0].amount - 49.4) < 0.0001)
|
||||
self.assert_(abs(k[0].volume - 1260) < 0.0001)
|
||||
self.assert_(abs(k[1].open - 104.3) < 0.0001)
|
||||
self.assert_(abs(k[9].open - 127.61) < 0.0001)
|
||||
self.assertTrue(abs(k[0].open - 96.05) < 0.0001)
|
||||
self.assertTrue(abs(k[0].high - 99.980) < 0.0001)
|
||||
self.assertTrue(abs(k[0].low - 95.79) < 0.0001)
|
||||
self.assertTrue(abs(k[0].close - 99.98) < 0.0001)
|
||||
self.assertTrue(abs(k[0].amount - 49.4) < 0.0001)
|
||||
self.assertTrue(abs(k[0].volume - 1260) < 0.0001)
|
||||
self.assertTrue(abs(k[1].open - 104.3) < 0.0001)
|
||||
self.assertTrue(abs(k[9].open - 127.61) < 0.0001)
|
||||
|
||||
def test_pickle(self):
|
||||
if not constant.pickle_support:
|
||||
@ -61,4 +61,4 @@ class KDataTest(unittest.TestCase):
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(KDataTest)
|
||||
return unittest.TestLoader().loadTestsFromTestCase(KDataTest)
|
||||
|
@ -36,12 +36,12 @@ class StockTest(unittest.TestCase):
|
||||
|
||||
s1 = sm['sh000001']
|
||||
s2 = sm['sh000001']
|
||||
self.assert_(s1 == s2)
|
||||
self.assert_(not (s1 != s2))
|
||||
self.assertTrue(s1 == s2)
|
||||
self.assertTrue(not (s1 != s2))
|
||||
|
||||
s2 = sm['sz000001']
|
||||
self.assert_(not (s1 == s2))
|
||||
self.assert_(s1 != s2)
|
||||
self.assertTrue(not (s1 == s2))
|
||||
self.assertTrue(s1 != s2)
|
||||
|
||||
def test_pickle(self):
|
||||
if not constant.pickle_support:
|
||||
@ -79,7 +79,7 @@ class StockTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(stk.valid, False)
|
||||
stk.valid = True
|
||||
self.assert_(stk.valid)
|
||||
self.assertTrue(stk.valid)
|
||||
|
||||
self.assertNotEqual(stk.type, constant.STOCKTYPE_A)
|
||||
stk.type = constant.STOCKTYPE_A
|
||||
@ -113,14 +113,14 @@ class StockTest(unittest.TestCase):
|
||||
self.assertEqual(len(k), 1)
|
||||
self.assertEqual(k[0], KRecord(Datetime(20010101), 5.0, 9.0, 4.0, 6.5, 1000.0, 100000.0))
|
||||
|
||||
self.assert_(stk not in sm)
|
||||
self.assertTrue(stk not in sm)
|
||||
sm.add_stock(stk)
|
||||
self.assert_(stk in sm)
|
||||
self.assertTrue(stk in sm)
|
||||
stk2 = sm['ab000001']
|
||||
self.assert_(not stk2.is_null())
|
||||
self.assert_(stk2, stk)
|
||||
self.assertTrue(not stk2.is_null())
|
||||
self.assertTrue(stk2, stk)
|
||||
sm.remove_stock("ab000001")
|
||||
self.assert_(stk not in sm)
|
||||
self.assertTrue(stk not in sm)
|
||||
|
||||
|
||||
def suite():
|
||||
|
Loading…
Reference in New Issue
Block a user