Ejemplo n.º 1
0
 def test_validate__non_uniform_timespan(self):
     """ Test TimeSpan.validate with a non-uniform timespan. """
     test_tspan = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     tspan = TimeSpan(test_tspan)
     with self.assertRaises(TimespanError):
         tspan.items = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10]
         tspan.validate()
Ejemplo n.º 2
0
 def test_validate__negative_start(self):
     """ Test TimeSpan.validate with an initial time < 0. """
     test_tspan = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     tspan = TimeSpan(test_tspan)
     with self.assertRaises(TimespanError):
         tspan.items = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
         tspan.validate()
Ejemplo n.º 3
0
 def test_validate__all_same_values(self):
     """ Test TimeSpan.validate with an empty data structure. """
     test_tspan = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     tspan = TimeSpan(test_tspan)
     with self.assertRaises(TimespanError):
         tspan.items = [2, 2, 2, 2, 2, 2, 2, 2, 2]
         tspan.validate()
Ejemplo n.º 4
0
 def test_linspace__invalid_num_points(self):
     """ Test TimeSpan.linspace with invalid num_points. """
     test_values = ["5", 0, -1, -2, -5, -10, 4.5, [40]]
     for test_val in test_values:
         with self.subTest(num_points=test_val):
             with self.assertRaises(TimespanError):
                 tspan = TimeSpan.linspace(t=30, num_points=test_val)
Ejemplo n.º 5
0
 def test_linspace__invalid_t(self):
     """ Test TimeSpan.linspace with invalid t. """
     test_values = [None, "5", 0, -0.5, -1, -2, -5, -10, [20.5]]
     for test_val in test_values:
         with self.subTest(t=test_val):
             with self.assertRaises(TimespanError):
                 tspan = TimeSpan.linspace(t=test_val, num_points=301)
Ejemplo n.º 6
0
 def test_arange__invalid_t(self):
     """ Test TimeSpan.arange with invalid t. """
     test_values = [None, "5", 0, -0.5, -1, -2, -5, -10, [20.5]]
     for test_val in test_values:
         with self.subTest(t=test_val):
             with self.assertRaises(TimespanError):
                 tspan = TimeSpan.arange(0.1, t=test_val)
Ejemplo n.º 7
0
 def test_arange__invalid_increment(self):
     """ Test TimeSpan.arange with invalid increment type. """
     test_values = [None, "0.05", 0, -1, -2, -5, -10, [0.05]]
     for test_val in test_values:
         with self.subTest(imcrement=test_val):
             with self.assertRaises(TimespanError):
                 tspan = TimeSpan.arange(test_val, t=30)
Ejemplo n.º 8
0
 def test_constructor__valid_data_structures(self):
     """ Test the TimeSpan constructor with valid data structures. """
     test_tspans = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                    (1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
                    range(11)]
     for test_tspan in test_tspans:
         with self.subTest(tspan=test_tspan, tspan_type=type(test_tspan)):
             tspan = TimeSpan(test_tspan)
             self.assertEqual(tspan, numpy.array(test_tspan))
Ejemplo n.º 9
0
 def test_constructor__invalid_items(self):
     """ Test the TimeSpan constructor with an invalid data structure type. """
     test_tspans = [
         None, "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]", 20, 50.5,
         set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
     ]
     for test_tspan in test_tspans:
         with self.subTest(items=test_tspan):
             with self.assertRaises(TimespanError):
                 TimeSpan(test_tspan)
Ejemplo n.º 10
0
 def test_linspace__no_num_points(self):
     """ Test TimeSpan.linspace without passing num_points. """
     tspan = TimeSpan.linspace(t=30)
     self.assertEqual(tspan, numpy.linspace(0, 30, int(30 / 0.05) + 1))
Ejemplo n.º 11
0
 def test_linspace__no_t(self):
     """ Test TimeSpan.linspace without passing t. """
     tspan = TimeSpan.linspace(num_points=201)
     self.assertEqual(tspan, numpy.linspace(0, 20, 201))
Ejemplo n.º 12
0
 def test_linspace(self):
     """ Test TimeSpan.linspace. """
     tspan = TimeSpan.linspace(t=30, num_points=301)
     self.assertEqual(tspan, numpy.linspace(0, 30, 301))
Ejemplo n.º 13
0
 def test_constructor(self):
     """ Test the TimeSpan constructor. """
     test_tspan = numpy.linspace(0, 20, 401)
     tspan = TimeSpan(test_tspan)
     self.assertEqual(tspan, test_tspan)
Ejemplo n.º 14
0
 def setUp(self):
     """ Setup a clean valid timespan for testing. """
     self.tspan = TimeSpan.linspace(t=100, num_points=101)
Ejemplo n.º 15
0
 def test_linspace__no_args(self):
     """ Test TimeSpan.linspace without passing any args. """
     tspan = TimeSpan.linspace()
     self.assertEqual(tspan, numpy.linspace(0, 20, 401))
Ejemplo n.º 16
0
 def test_arange(self):
     """ Test TimeSpan.arange. """
     tspan = TimeSpan.arange(0.1, t=30)
     self.assertEqual(tspan, numpy.arange(0, 30.1, 0.1))
Ejemplo n.º 17
0
 def test_arange__no_t(self):
     """ Test TimeSpan.arange. """
     tspan = TimeSpan.arange(0.1)
     self.assertEqual(tspan, numpy.arange(0, 20.1, 0.1))