1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
##############################################################################
# Copyright (c) 2016 CENGN and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import unittest
from storperf.utilities import math as math
class MathAverageTest(unittest.TestCase):
def setUp(self):
unittest.TestCase.setUp(self)
def test_empty_series(self):
expected = None
data_series = []
actual = math.average(data_series)
self.assertEqual(expected, actual)
def test_integer_series(self):
expected = 19.75
data_series = [5, 12, 7, 55]
actual = math.average(data_series)
self.assertEqual(expected, actual)
def test_float_series(self):
expected = 63.475899999999996
data_series = [78.6, 45.187, 33.334, 96.7826]
actual = math.average(data_series)
self.assertEqual(expected, actual)
def test_float_int_mix(self):
expected = 472.104
data_series = [10, 557.33, 862, 56.99, 874.2]
actual = math.average(data_series)
self.assertEqual(expected, actual)
def test_negative_values(self):
expected = -17.314
data_series = [-15.654, 59.5, 16.25, -150, 3.334]
actual = math.average(data_series)
self.assertEqual(expected, actual)
def test_single_value(self):
expected = -66.6667
data_series = [-66.6667]
actual = math.average(data_series)
self.assertEqual(expected, actual)
|