diff --git a/pysd/py_backend/functions.py b/pysd/py_backend/functions.py index fcfeb348..8e1a1c77 100644 --- a/pysd/py_backend/functions.py +++ b/pysd/py_backend/functions.py @@ -519,14 +519,21 @@ def __str__(self): class Time(object): - def __init__(self): - self._t = None + def __init__(self, t=None, dt=None): + self._t = t + self._step = dt self.stage = None def __call__(self): return self._t + def step(self): + return self._step + def update(self, value): + if self._t is not None: + self._step = value - self._t + self._t = value @@ -889,13 +896,13 @@ def pulse_magnitude(time, magnitude, start, repeat_time=0): t = time() small = 1e-6 # What is considered zero according to Vensim Help if repeat_time <= small: - if abs(t - start) < time_step: - return magnitude * time_step + if abs(t - start) < time.step(): + return magnitude * time.step() else: return 0 else: - if abs((t - start) % repeat_time) < time_step: - return magnitude * time_step + if abs((t - start) % repeat_time) < time.step(): + return magnitude * time.step() else: return 0 diff --git a/tests/.coverage b/tests/.coverage deleted file mode 100644 index e1cd8c47..00000000 --- a/tests/.coverage +++ /dev/null @@ -1 +0,0 @@ -!coverage.py: This is a private format, don't read it directly!{"lines": {"/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/exp/test_exp.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 20, 30, 133, 33, 43, 46, 136, 56, 59, 138, 69, 72, 81, 84, 94, 97, 107, 110, 120, 123], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/samples/SIR/SIR.py": [256, 2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 153, 25, 179, 35, 38, 176, 51, 188, 191, 64, 140, 258, 204, 77, 86, 89, 98, 101, 230, 114, 243, 217, 166, 127], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/rounding/test_rounding.py": [2, 3, 5, 6, 8, 137, 10, 11, 12, 13, 14, 15, 16, 17, 18, 147, 21, 150, 152, 31, 34, 134, 44, 47, 57, 60, 70, 73, 83, 86, 95, 98, 108, 111, 121, 124], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/pysd/utils.py": [1, 2, 3, 4, 7, 31, 34, 55, 56, 57, 60, 81, 82, 83, 84, 85, 86, 87, 90, 91, 196, 197, 199, 200, 202, 203, 206, 209, 212, 214, 218, 220, 223, 226, 227, 228, 229, 231, 232, 236, 238, 240, 243, 267, 268, 269, 270, 271, 272, 273, 274, 281, 282, 283, 285, 286, 287, 288, 289, 291, 293, 294, 296, 299, 321, 322, 325, 344, 345, 346, 347, 348, 349, 351, 353, 355], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/ln/test_ln.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 20, 30, 133, 33, 43, 46, 136, 56, 59, 138, 69, 72, 81, 84, 94, 97, 107, 110, 120, 123], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/pysd/pysd.py": [18, 20, 21, 22, 23, 24, 25, 35, 36, 54, 55, 71, 72, 73, 74, 75, 77, 78, 92, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 104, 106, 107, 108, 109, 111, 112, 118, 119, 120, 121, 122, 123, 124, 125, 128, 129, 130, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 216, 217, 218, 219, 220, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 248, 249, 250, 251, 252, 253, 254, 255, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 288, 289, 290, 291, 292, 314, 315, 316, 317, 318, 319, 320, 321, 322, 329, 330, 332, 333, 334, 335, 336, 337, 341, 342, 345, 346, 347, 348, 349, 350, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 383, 384, 386, 387, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 413, 414, 415, 416, 417, 420], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript_individually_defined_1_of_2d_arrays/subscript_individually_defined_1_of_2d_arrays.py": [2, 3, 4, 5, 6, 8, 10, 11, 140, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 155, 34, 37, 168, 170, 47, 50, 51, 52, 54, 55, 56, 59, 69, 130, 72, 143, 82, 83, 84, 85, 86, 87, 88, 152, 91, 165, 101, 104, 114, 117, 127], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/if_stmt/if_stmt.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 18, 28, 31, 41, 44, 54, 57, 70, 80, 83, 93, 96, 97, 98], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/number_handling/test_number_handling.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 32, 35, 45, 48, 136, 58, 61, 139, 71, 74, 141, 84, 87, 97, 100, 110, 113, 123, 126], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript_1d_arrays/test_subscript_1d_arrays.py": [2, 3, 4, 5, 6, 135, 8, 137, 10, 11, 12, 13, 14, 15, 16, 17, 131, 20, 150, 153, 155, 30, 133, 33, 43, 46, 136, 132, 58, 59, 60, 61, 63, 64, 65, 66, 69, 130, 140, 79, 56, 82, 92, 95, 105, 108, 118, 121], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript_docs/subscript_docs.py": [2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 19, 33, 46, 59, 72, 82, 85, 98, 100], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/pysd/functions.py": [7, 9, 10, 11, 14, 34, 36, 39, 40, 41, 42, 43, 44, 45, 47, 49, 52, 53, 54, 55, 56, 57, 59, 60, 62, 63, 69, 88, 89, 90, 91, 92, 94, 97, 103, 109, 112, 119, 120, 123, 127, 128, 131, 141, 142, 145, 149], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript_individually_defined_1d_arrays/subscript_individually_defined_1d_arrays.py": [2, 3, 4, 5, 6, 8, 137, 10, 11, 12, 13, 14, 15, 16, 17, 131, 20, 151, 132, 154, 156, 30, 133, 33, 134, 43, 46, 136, 56, 57, 58, 59, 138, 62, 63, 64, 65, 66, 67, 70, 141, 80, 83, 93, 96, 106, 109, 61, 119, 122], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/chained_initialization/test_chained_initialization.py": [128, 256, 2, 3, 5, 6, 243, 8, 265, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 281, 25, 154, 283, 218, 253, 112, 278, 35, 164, 38, 167, 48, 177, 51, 180, 87, 151, 138, 190, 64, 193, 268, 74, 203, 77, 206, 141, 215, 90, 99, 228, 102, 231, 61, 240, 115, 125], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/__init__.py": [1], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/logicals/test_logicals.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 32, 35, 45, 48, 136, 58, 61, 139, 71, 74, 141, 84, 87, 97, 100, 110, 113, 123, 126], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/unit_test_pysd.py": [1, 2, 3, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 22, 23, 29, 31, 32, 33, 34, 35, 37, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 57, 59, 60, 61, 62, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 80, 81, 82, 85, 89, 90, 91, 95, 97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 113, 114, 115, 117, 118, 120, 121, 123, 125, 126, 128, 129, 131, 132, 135, 136, 138, 139, 141, 142, 144, 145, 147, 148, 150, 151, 153, 154, 157, 159, 161, 172, 174, 175, 177, 179, 185], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test_utils.py": [2, 4, 5, 6, 7, 10, 11, 14, 15, 22, 23, 24, 25, 26, 27, 28, 31, 33, 37, 73, 74, 77, 80, 84, 85, 86, 87, 88, 89, 90, 91, 96, 97], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/samples/teacup/teacup.py": [2, 3, 5, 6, 8, 137, 10, 11, 12, 13, 14, 15, 16, 17, 18, 147, 21, 150, 151, 152, 31, 34, 134, 43, 46, 56, 59, 69, 72, 82, 85, 95, 98, 108, 111, 121, 124], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/pysd/vensim2py.py": [9, 11, 12, 13, 14, 17, 73, 75, 76, 78, 79, 80, 81, 83, 84, 85, 86, 87, 89, 97, 98, 100, 103, 171, 172, 173, 175, 176, 177, 178, 180, 181, 182, 183, 184, 186, 187, 188, 189, 190, 191, 193, 194, 196, 199, 254, 257, 258, 260, 261, 263, 264, 265, 266, 267, 268, 269, 271, 272, 274, 275, 277, 278, 280, 281, 283, 284, 286, 287, 289, 290, 292, 294, 295, 296, 297, 300, 324, 368, 369, 370, 371, 373, 375, 376, 377, 378, 379, 380, 381, 382, 384, 387, 388, 389, 390, 391, 392, 393, 396, 397, 398, 399, 400, 404, 405, 406, 407, 409, 410, 416, 417, 418, 419, 420, 447, 451, 453, 454, 455, 456, 457, 458, 459, 462, 463, 465, 469, 470, 471, 472, 473, 475, 476, 477, 479, 480, 481, 482, 484, 485, 486, 488, 489, 491, 492, 494, 495, 496, 498, 501, 502, 503, 504, 506, 507, 508, 509, 511, 513, 514, 515, 516, 517, 519, 521, 522, 523, 524, 525, 526, 528, 529, 531, 533, 534, 535, 538, 542, 569, 570, 573, 574, 575, 576, 577, 580, 581, 582, 583, 584, 585, 588, 589, 590, 591, 592, 597, 600, 601, 602, 603, 604, 606, 607, 610, 613, 614, 615, 616, 618], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/integration_test_pysd.py": [2, 4, 7, 9, 10, 11, 12, 14, 15, 16, 19, 20, 21, 22, 24, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 39, 40, 41, 42, 44, 45, 46, 47, 49, 50, 51, 52, 54, 55, 56, 57, 59, 60, 61, 62, 64, 65, 66, 69, 70, 71, 72, 74, 75, 76, 79, 80, 81, 82, 84, 85, 86, 87, 89, 90, 91, 94, 95, 96, 97, 99, 100, 101, 102, 104, 105, 106, 109, 110, 111, 114, 115, 116, 117, 119, 120, 121, 122, 124, 125, 126, 127, 129, 130, 131, 132, 134, 135, 136, 139, 140, 141, 144, 145, 146, 149, 150, 151, 152, 154, 155, 156, 157, 159, 160, 161, 162, 164, 165, 166, 167, 169, 170, 171, 174, 175, 176, 177, 179, 180, 181, 182], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/input_functions/test_inputs.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 149, 23, 152, 33, 162, 36, 165, 46, 175, 49, 178, 179, 180, 59, 62, 139, 72, 75, 84, 87, 97, 100, 110, 113, 136, 123, 126], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/pysd/builder.py": [6, 9, 10, 11, 14, 36, 37, 39, 40, 41, 60, 61, 62, 63, 65, 66, 67, 68, 71, 72, 74, 75, 78, 102, 103, 104, 105, 106, 107, 113, 114, 116, 117, 118, 119, 121, 123, 124, 125, 126, 127, 128, 129, 130, 132, 133, 134, 137, 139, 140, 141, 142, 143, 144, 157, 158, 159, 161, 162, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 227, 228, 252, 253, 254, 255, 256, 257, 258, 259, 260, 262, 263, 264, 265, 266, 267, 268, 269, 270, 272, 273, 281, 282, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 309, 310, 311, 312, 313, 314, 315], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/function_capitalization/test_function_capitalization.py": [2, 3, 5, 6, 135, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 148, 22, 151, 32, 161, 35, 164, 166, 45, 48, 138, 58, 61, 70, 73, 83, 86, 96, 99, 109, 112, 122, 125], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/abs/test_abs.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 20, 30, 133, 33, 43, 46, 136, 56, 59, 138, 68, 71, 81, 84, 94, 97, 107, 110, 120, 123], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/builtin_max/builtin_max.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 18, 28, 31, 41, 44, 54, 57, 70, 80, 83, 93, 96, 97, 98], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/sqrt/test_sqrt.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 20, 30, 133, 33, 43, 46, 136, 56, 59, 138, 69, 72, 81, 84, 94, 97, 107, 110, 120, 123], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/unit_test_functions.py": [1, 4, 5, 6, 8, 11], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/unit_test_builder.py": [1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 35, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 52, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 81, 93, 94, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 110, 122, 123, 125, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 144, 156, 157, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191, 192, 194, 195, 218, 258], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/samples/teacup/Teacup.py": [2, 3, 5, 6, 8, 137, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 150, 152, 34, 43, 46, 59, 72, 85, 98, 111, 121, 124], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript_subranges_equal/test_subscript_subrange_equal.py": [2, 3, 4, 5, 6, 8, 10, 11, 12, 130, 14, 15, 16, 152, 18, 19, 20, 21, 22, 23, 24, 25, 26, 155, 29, 165, 39, 168, 42, 52, 55, 65, 68, 140, 143, 78, 80, 81, 82, 83, 85, 86, 87, 88, 91, 101, 104, 114, 117, 170, 127], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/special_characters/test_special_variable_names.py": [128, 2, 3, 5, 6, 193, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 26, 154, 219, 164, 39, 177, 52, 180, 65, 203, 75, 78, 141, 206, 91, 100, 103, 232, 167, 112, 115, 245, 247], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript_subranges/test_subscript_subrange.py": [129, 2, 3, 4, 5, 6, 8, 10, 11, 12, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 154, 28, 164, 38, 167, 41, 51, 54, 151, 64, 67, 77, 79, 80, 81, 82, 139, 142, 86, 87, 90, 100, 103, 113, 116, 169, 84, 126, 85], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/unit_test_utils.py": [1, 2, 3, 4, 7, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 77, 79, 80, 82, 83, 84, 85, 86, 87, 89, 90, 91, 93, 94, 96, 97, 98, 100, 101, 103, 107, 109, 110, 111, 112, 113, 114, 115, 117, 118, 119, 120, 121, 123, 124, 125], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/trig/test_trig.py": [128, 2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 151, 25, 154, 35, 164, 38, 167, 48, 177, 51, 180, 138, 190, 64, 193, 74, 203, 77, 206, 141, 208, 87, 90, 207, 100, 103, 61, 112, 115, 125], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript_3d_arrays/test_subscript_3d_arrays.py": [2, 3, 4, 5, 6, 8, 10, 11, 12, 130, 14, 15, 16, 17, 18, 19, 20, 21, 22, 152, 25, 155, 38, 168, 170, 48, 49, 50, 51, 52, 53, 58, 71, 143, 91, 104, 114, 117], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/speed_test.py": [1, 2, 4, 7, 9, 10, 15, 16, 18, 22, 23], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/euler_step_vs_saveper/test_euler_step_vs_saveper.py": [2, 3, 132, 5, 6, 135, 8, 137, 10, 11, 12, 13, 14, 15, 16, 19, 29, 32, 42, 45, 136, 55, 58, 68, 71, 81, 84, 97, 107, 110, 119, 122], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/pysd/__init__.py": [1, 2, 3, 4], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscripted_flows/test_subscripted_flows.py": [128, 129, 2, 3, 4, 5, 6, 8, 44, 10, 11, 12, 13, 14, 15, 16, 17, 18, 131, 21, 132, 159, 133, 34, 177, 31, 171, 172, 173, 174, 47, 176, 136, 178, 181, 126, 57, 59, 60, 61, 62, 191, 64, 65, 194, 67, 196, 70, 162, 80, 82, 83, 84, 66, 87, 88, 89, 90, 93, 103, 106, 146, 116, 117, 118, 119, 121, 122, 123, 125, 85, 149], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript_2d_arrays/test_subscript_2d_arrays.py": [2, 3, 4, 5, 6, 8, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 155, 158, 133, 34, 91, 37, 168, 171, 173, 47, 50, 51, 52, 54, 55, 56, 59, 69, 130, 72, 82, 85, 86, 87, 89, 90, 143, 94, 104, 107, 146, 117, 120], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/subscript multiples/test_multiple_subscripts.py": [129, 2, 3, 4, 5, 6, 8, 108, 10, 11, 12, 13, 142, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 158, 81, 32, 91, 167, 168, 169, 170, 172, 45, 174, 175, 178, 155, 55, 132, 88, 58, 188, 191, 86, 68, 71, 201, 204, 173, 83, 84, 213, 214, 215, 216, 89, 218, 219, 220, 94, 223, 90, 145, 104, 233, 106, 107, 236, 109, 110, 112, 113, 114, 115, 116, 246, 119, 249, 251, 42, 85], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/unit_test_vensim2py.py": [1, 4, 5, 6, 7, 8, 9, 10, 13, 15, 16, 17, 18, 19, 22, 24, 25, 26, 27, 28, 32, 33, 34, 35, 36, 39, 40, 41, 42, 43, 44, 47, 48, 49, 50, 51, 52, 55, 56, 57, 58, 61, 62, 63, 64, 67, 68, 69, 70, 73, 74, 75, 76, 77, 78, 81, 82, 83, 84, 87, 88, 89, 90, 91, 94, 95, 96, 97, 101, 103, 104, 105, 106, 107, 109, 110, 111, 112, 113, 116, 117, 118, 121, 122, 123, 126, 127, 128, 131, 132, 133, 136, 137, 138, 139, 140, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 157, 158, 159, 160, 161, 164, 165, 166, 169, 170, 171, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 198, 213, 221, 222, 223, 224, 225, 226, 227, 230, 231, 232, 233, 234, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 269, 270, 271, 272, 273, 274, 275, 276, 279, 280, 281, 282, 283, 284, 287, 288, 289, 290, 291, 292, 293, 296, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/exponentiation/exponentiation.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 20, 30, 33, 43, 46, 59, 69, 72, 82, 85, 95, 98, 108, 111, 121, 124, 125, 126], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/test-models/tests/builtin_min/builtin_min.py": [2, 3, 5, 6, 8, 10, 11, 12, 13, 14, 15, 18, 28, 31, 41, 44, 54, 57, 70, 80, 83, 93, 96, 97, 98], "/Users/houghton/Google_Drive/Academic Projects/PYSD/pysd/tests/integration_test_factory.py": [1, 2, 3, 5, 6, 8, 9, 10, 11, 13, 35, 20, 21, 22, 24, 38, 37]}} \ No newline at end of file diff --git a/tests/unit_test_functions.py b/tests/unit_test_functions.py index 912196ad..594f31bd 100644 --- a/tests/unit_test_functions.py +++ b/tests/unit_test_functions.py @@ -61,6 +61,37 @@ def test_pulse_chain(self): # after train self.assertEqual(functions.pulse_train(lambda: 15, 1, 3, 5, 13), 0) + def test_pulse_magnitude(self): + from pysd import functions + + # Pulse function with repeat time + # before first impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(0, 1), 10, 2, 5), 0) + # first impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(2, 1), 10, 2, 5), 10) + # after first impulse and before second + self.assertEqual(functions.pulse_magnitude(functions.Time(4, 1), 10, 2, 5), 0) + # second impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(7, 1), 10, 2, 5), 10) + # after second and before third impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(9, 1), 10, 2, 5), 0) + # third impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(12, 1), 10, 2, 5), 10) + # after third impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(14, 1), 10, 2, 5), 0) + + # Pulse function without repeat time + # before first impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(0, 1), 10, 2), 0) + # first impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(2, 1), 10, 2), 10) + # after first impulse and before second + self.assertEqual(functions.pulse_magnitude(functions.Time(4, 1), 10, 2), 0) + # second impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(7, 1), 10, 2), 0) + # after second and before third impulse + self.assertEqual(functions.pulse_magnitude(functions.Time(9, 1), 10, 2), 0) + def test_xidz(self): from pysd import functions self.assertEqual(functions.xidz(1, -0.00000001, 5), 5)