test_class_mechanical_equipment.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import unittest
5 import math
6 import rosunit
7 from phm_hazard_rate_calculation.class_mechanical_equipment import MechanicalEquipment
8 
9 PKG = 'phm_hazard_rate_calculation'
10 NAME = 'test_class_mechanical_equipment'
11 
12 
13 class TestMechanicalEquipment(unittest.TestCase):
15 
16 # Get FUNCTIONS - START -
17 
19  result = self.m_eq.get_sp_lambda()
20  test_result = 0.0
21 
22  self.assertAlmostEqual(result, test_result, 5)
23 
25  result = self.m_eq.get_gr_lambda()
26  test_result = 0.0
27 
28  self.assertAlmostEqual(result, test_result, 5)
29 
31  result = self.m_eq.get_be_lambda()
32  test_result = 0.0
33 
34  self.assertAlmostEqual(result, test_result, 5)
35 
36 
38  result = self.m_eq.get_ac_lambda()
39  test_result = 0.0
40 
41  self.assertAlmostEqual(result, test_result, 5)
42 
43 
45  result = self.m_eq.get_sh_lambda()
46  test_result = 0.0
47 
48  self.assertAlmostEqual(result, test_result, 5)
49 
50 
52  result = self.m_eq.get_em_lambda()
53  test_result = 1.0
54 
55  self.assertAlmostEqual(result, test_result, 5)
56 
57 
59  result = self.m_eq.get_cp_lambda()
60  test_result = 0.0
61 
62  self.assertAlmostEqual(result, test_result, 5)
63 
64 
66  result = self.m_eq.get_bat_lambda()
67  test_result = 0.0
68 
69  self.assertAlmostEqual(result, test_result, 5)
70 
71 
72 # ATTRIBUTES - END -
73 
74 # SPRING FORMULAS - START -
75 
76  def test_sp_c_dw_func(self):
77  self.m_eq.sp_c_dw_func(0.5)
78  result = self.m_eq.get_sp_c_dw()
79  test_result = 203.54162426216158
80 
81  # result = float(pow((0.5 / 0.085), 3))
82 
83  self.assertAlmostEqual(result, test_result, 5)
84 
85 
86  def test_sp_c_dc_func(self):
87  self.m_eq.sp_c_dc_func(0.5)
88  result = self.m_eq.get_sp_c_dc()
89  test_result = 2.436396322815999
90 
91  # result = float(pow(0.58 / 0.5, 6))
92 
93  self.assertAlmostEqual(result, test_result, 5)
94 
95 
96  def test_sp_c_n_func(self):
97  self.m_eq.sp_c_n_func(5)
98  result = self.m_eq.get_sp_c_n()
99  test_result = 21.951999999999995
100 
101  # result = float(pow(14 / 5, 3))
102 
103  self.assertAlmostEqual(result, test_result, 5)
104 
105 
106  def test_sp_c_l_func(self):
107  self.m_eq.sp_c_l_func(7, 5)
108  result = self.m_eq.get_sp_c_l()
109  test_result = 6.530383015126816
110 
111  # result = float(pow((7 - 5) / 1.07, 3))
112 
113  self.assertAlmostEqual(result, test_result, 5)
114 
115 
116  def test_sp_c_k_func(self):
117  self.m_eq.sp_c_k_func(9, 5)
118  result = self.m_eq.get_sp_c_k()
119  test_result = 0.7314342657282276
120 
121  # r = float(9 / 5)
122  # k_w = float(((4 * r - 1) / (4 * r + 1)) + (0.616 / r))
123  # result = float(pow(k_w / 1.219, 3))
124 
125  self.assertAlmostEqual(result, test_result, 5)
126 
127 
129  self.m_eq.sp_c_cs_func(25)
130  result = self.m_eq.get_sp_c_cs()
131  test_result = 0.1
132 
133  self.assertAlmostEqual(result, test_result, 2)
134 
135 
137  self.m_eq.sp_c_cs_func(250)
138  result = self.m_eq.get_sp_c_cs()
139  test_result = 0.8333333333333334
140 
141  # result = float(250 / 300)
142 
143  self.assertAlmostEqual(result, test_result, 5)
144 
145 
147  self.m_eq.sp_c_cs_func(350)
148  result = self.m_eq.get_sp_c_cs()
149  test_result = 1.5879629629629632
150 
151  # result = float(pow(350 / 300, 3))
152 
153  self.assertAlmostEqual(result, test_result, 5)
154 
155 
156 # SPRING FORMULAS - END -
157 
158 # BEARING FORMULAS - START -
160  result = self.m_eq.bearing_l_10_func(2, 30, 6, 5)
161  test_result = 83333.33333333334
162 
163  # result = float((pow(10, 6) / (60 * 5)) * pow((30 / 6), 2))
164 
165  self.assertAlmostEqual(result, test_result, 5)
166 
167 
169  self.m_eq.be_lambda_be_b_func(2, 30, 6, 5, 10)
170  result = self.m_eq.get_be_lambda_be_b()
171  test_result = 1.1999999999999997e-06
172 
173  # l_10 = float((pow(10, 6) / (60 * 5)) * pow((30 / 6), 2))
174  # result = float(1 / (l_10 * 10))
175 
176  self.assertAlmostEqual(result, test_result, 5)
177 
178 
180  self.m_eq.be_lambda_be_b_func(2, 30, 6, None, 10)
181  result = self.m_eq.get_be_lambda_be_b()
182  test_result = 1.0
183 
184  self.assertAlmostEqual(result, test_result, 5)
185 
186 
187  def test_be_c_y_func(self):
188  self.m_eq.be_c_y_func(2, 30, 6)
189  result = self.m_eq.get_be_c_y()
190  test_result = 25.0
191 
192  # result = float(pow((30 / 6), 2))
193 
194  self.assertAlmostEqual(result, test_result, 5)
195 
196 
198  self.m_eq.be_c_r_func(5, True)
199  result = self.m_eq.get_be_c_r()
200  test_result = 0.10730901231734431
201 
202  # result = float(float(0.223) / float(pow(math.log(float(100) / float(5)), (2/3))))
203 
204  self.assertAlmostEqual(result, test_result, 5)
205 
206 
208  self.m_eq.be_c_r_func(5, False)
209  result = self.m_eq.get_be_c_r()
210  test_result = 1.0
211 
212  self.assertAlmostEqual(result, test_result, 2)
213 
214 
216  self.m_eq.be_c_v_func(30, 5, True)
217  result = self.m_eq.get_be_c_v()
218  test_result = 2.6314897044644194
219 
220  # result = float(pow((30 / 5), (0.54)))
221 
222  self.assertAlmostEqual(result, test_result, 5)
223 
224 
226  self.m_eq.be_c_v_func(30, 5, False)
227  result = self.m_eq.get_be_c_v()
228  test_result = 1.0
229 
230  self.assertAlmostEqual(result, test_result, 2)
231 
232 
234  self.m_eq.be_c_cw_func(0.9, True)
235  result = self.m_eq.get_be_c_cw()
236  test_result = 11.0
237 
238  self.assertAlmostEqual(result, test_result, 2)
239 
240 
242  self.m_eq.be_c_cw_func(0.5, True)
243  result = self.m_eq.get_be_c_cw()
244  test_result = 9.6875
245 
246  # result = float(1.0 + (25.50 * 0.5) - (16.25 * pow(0.5, 2)))
247 
248  self.assertAlmostEqual(result, test_result, 5)
249 
250 
252  self.m_eq.be_c_cw_func(0.9, False)
253  result = self.m_eq.get_be_c_cw()
254  test_result = 1.0
255 
256  self.assertAlmostEqual(result, test_result, 2)
257 
258 
260  self.m_eq.be_c_t_func(150)
261  result = self.m_eq.get_be_c_t()
262  test_result = 1.0
263 
264  self.assertAlmostEqual(result, test_result, 2)
265 
266 
268  self.m_eq.be_c_t_func(200)
269  result = self.m_eq.get_be_c_t()
270  test_result = 1.3053792885584978
271 
272  # result = float(pow((200 / 183), 3))
273 
274  self.assertAlmostEqual(result, test_result, 5)
275 
276 # BEARING FORMULAS - END -
277 
278 # GEAR FORMULAS - START -
279 
281  self.m_eq.gr_lambda_gr_b_func(100, 10, True)
282  result = self.m_eq.get_gr_lambda_gr_b()
283  test_result = 600.0
284 
285  # result = float(100 * 60 * (1 / revolutions))
286 
287  self.assertAlmostEqual(result, test_result, 5)
288 
289 
291  self.m_eq.gr_lambda_gr_b_func(1, 1, False)
292  result = self.m_eq.get_gr_lambda_gr_b()
293  test_result = 1.0
294 
295  self.assertAlmostEqual(result, test_result, 5)
296 
297 
298  def test_c_gs_func_1(self):
299  self.m_eq.c_gs_func(100, 10, True)
300  result = self.m_eq.get_gr_c_gs()
301  test_result = 6.011872336272722
302 
303  # result = float(1.0 + pow((100 / 10), 0.7))
304 
305  self.assertAlmostEqual(result, test_result, 5)
306 
307 
308  def test_c_gs_func_2(self):
309  self.m_eq.c_gs_func(100, 10, False)
310  result = self.m_eq.get_gr_c_gs()
311  test_result = 1.0
312 
313  self.assertAlmostEqual(result, test_result, 5)
314 
315 
316  def test_c_gp_func_1(self):
317  self.m_eq.c_gp_func(100, 10, True)
318  result = self.m_eq.get_gr_c_gp()
319  test_result = 1264243.85515232
320 
321  # result = float(0.5 + pow(((100 / 10) / 0.5), 4.69))
322 
323  self.assertAlmostEqual(result, test_result, 5)
324 
325 
326  def test_c_gp_func_2(self):
327  self.m_eq.c_gp_func(100, 10, False)
328  result = self.m_eq.get_gr_c_gp()
329  test_result = 1.0
330 
331  self.assertAlmostEqual(result, test_result, 5)
332 
333 
334  def test_c_ga_func_1(self):
335  self.m_eq.c_ga_func(1, True)
336  result = self.m_eq.get_gr_c_ga()
337  test_result = 175211.67808855648
338 
339  # result = float(pow((1 / 0.006), 2.36))
340 
341  self.assertAlmostEqual(result, test_result, 5)
342 
343 
344  def test_c_ga_func_2(self):
345  self.m_eq.c_ga_func(1, False)
346  result = self.m_eq.get_gr_c_ga()
347  test_result = 1.0
348 
349  self.assertAlmostEqual(result, test_result, 5)
350 
351 
352  def test_c_gl_func_1(self):
353  self.m_eq.c_gl_func(100, 10, True)
354  result = self.m_eq.get_gr_c_gl()
355  test_result = 4.467368504525316
356 
357  # result = float(1.0 + pow((100 / 10), 0.54))
358 
359  self.assertAlmostEqual(result, test_result, 5)
360 
361 
362  def test_c_gl_func_2(self):
363  self.m_eq.c_gl_func(100, 10, False)
364  result = self.m_eq.get_gr_c_gl()
365  test_result = 1.0
366 
367  self.assertAlmostEqual(result, test_result, 5)
368 
369 
370  def test_c_gt_func_1(self):
371  self.m_eq.c_gt_func(150)
372  result = self.m_eq.get_gr_c_gt()
373  test_result = 1.0
374 
375  self.assertAlmostEqual(result, test_result, 5)
376 
377 
378  def test_c_gt_func_2(self):
379  self.m_eq.c_gt_func(200)
380  result = self.m_eq.get_gr_c_gt()
381  test_result = 1.064516129032258
382 
383  # result = float((460 + 200) / 620)
384 
385  self.assertAlmostEqual(result, test_result, 5)
386 
387 # GEAR FORMULAS - END -
388 
389 # ACTUATOR FORMULAS - START -
390 
391  def test_ac_n_o_func(self):
392  self.m_eq.ac_n_o_func(0.5, 0.1, 0.5, 0.1, 0.5, 0.4, 0.2)
393  result = self.m_eq.ac_n_o
394  test_result = 2.320515320283925
395 
396  self.assertAlmostEqual(result, test_result, 5)
397 
398 
400  self.m_eq.ac_n_o = 2
401  self.m_eq.ac_lambda_ac_b_func()
402  result = self.m_eq.get_ac_lambda_ac_b()
403  test_result = 500000.0
404 
405  self.assertAlmostEqual(result, test_result, 5)
406 
407 
409  self.m_eq.ac_c_h_func(10, 5, True)
410  result = self.m_eq.get_ac_c_h()
411  test_result = 2.0
412 
413  # result = float(10 / 5)
414 
415  self.assertAlmostEqual(result, test_result, 5)
416 
417 
419  self.m_eq.ac_c_h_func(10, 5, False)
420  result = self.m_eq.get_ac_c_h()
421  test_result = 1.0
422 
423  self.assertAlmostEqual(result, test_result, 5)
424 
425 
426  def test_ac_c_s_func(self):
427  self.m_eq.ac_c_s_func(150)
428  result = self.m_eq.ac_c_s
429  test_result = 15.0
430 
431  # result = float(150 / 10)
432 
433  self.assertAlmostEqual(result, test_result, 5)
434 
435 
437  self.m_eq.ac_c_h = 5
438  self.m_eq.ac_c_s = 5
439  self.m_eq.ac_c_n = 2
440  self.m_eq.ac_c_cp_func(True)
441  result = self.m_eq.get_ac_c_cp()
442  test_result = 50.0
443 
444  # result = float(5 * 5 * 2)
445 
446  self.assertAlmostEqual(result, test_result, 5)
447 
448 
450  self.m_eq.ac_c_cp_func(False)
451  result = self.m_eq.get_ac_c_cp()
452  test_result = 1.0
453 
454  self.assertAlmostEqual(result, test_result, 5)
455 
456 
457 # ACTUATOR FORMULAS - END -
458 
459 # ELECTRIC MOTORS FORMULAS - START -
460 
462  self.m_eq.elec_mot_lambda_wi_b_func(150)
463  result = self.m_eq.get_em_lambda_wi_b()
464  test_result = 6666.666666666667
465 
466  # result = float((1.0 * pow(10, 6)) / 150)
467 
468  self.assertAlmostEqual(result, test_result, 5)
469 
470 
472  self.m_eq.elec_mot_c_t_func(80)
473  result = self.m_eq.get_em_c_t()
474  test_result = 16.0
475 
476  # result = float(pow(2, ((float(80) - 40) / 10)))
477 
478  self.assertAlmostEqual(result, test_result, 5)
479 
480 
482  self.m_eq.elec_mot_c_t_func(None)
483  result = self.m_eq.get_em_c_t()
484  test_result = 1.0
485 
486  self.assertAlmostEqual(result, test_result, 5)
487 
488 
490  self.m_eq.em_motor_phase = 1
491  self.m_eq.elec_mot_c_v_func(25, 5, 5, True)
492  result = self.m_eq.get_em_c_v()
493  test_result = 1125899906842624.0
494 
495  # result = pow(2, 10 * (float(25) / float(5)))
496 
497  self.assertAlmostEqual(result, test_result, 5)
498 
499 
501  self.m_eq.em_motor_phase = 3
502  self.m_eq.elec_mot_c_v_func(25, 5, 5, True)
503  result = self.m_eq.get_em_c_v()
504  test_result = 6.656854249492381
505 
506  # result = float(1 + pow(0.40 * float(5), 2.5))
507 
508  self.assertAlmostEqual(result, test_result, 5)
509 
510 
512  self.m_eq.em_motor_phase = 0
513  self.m_eq.elec_mot_c_v_func(25, 5, 5, True)
514  result = self.m_eq.get_em_c_v()
515  test_result = 1.0
516 
517  self.assertAlmostEqual(result, test_result, 5)
518 
519 
521  self.m_eq.elec_mot_c_v_func(25, 5, 5, False)
522  result = self.m_eq.get_em_c_v()
523  test_result = 1.0
524 
525  self.assertAlmostEqual(result, test_result, 5)
526 
527 
529  self.m_eq.elec_mot_v_u_func(25, 5, True)
530  result = self.m_eq.get_em_v_u()
531  test_result = 500.0
532 
533  # result = float(100 * (25 / 5))
534 
535  self.assertAlmostEqual(result, test_result, 5)
536 
537 
539  self.m_eq.elec_mot_v_u_func(25, 5, False)
540  result = self.m_eq.get_em_v_u()
541  test_result = 1.0
542 
543  self.assertAlmostEqual(result, test_result, 5)
544 
545 
547  self.m_eq.elec_mot_alt_func(3000)
548  result = self.m_eq.get_em_c_alt()
549  test_result = 1.0
550 
551  self.assertAlmostEqual(result, test_result, 5)
552 
553 
555  self.m_eq.elec_mot_alt_func(3750)
556  result = self.m_eq.get_em_c_alt()
557  test_result = 1.036
558 
559  # result = float(1.00 + (8 * pow(10, -5)) * (3750 - 3300))
560 
561  self.assertAlmostEqual(result, test_result, 5)
562 
563 
565  self.m_eq.elec_mot_lambda_c_func(35)
566  result = self.m_eq.get_em_lambda_c()
567  test_result = 35.0
568 
569  self.assertAlmostEqual(result, test_result, 5)
570 
571 # ELECTRIC MOTORS FORMULAS - END -
572 
573 # SHAFTS MOTORS FORMULAS - START -
574 
576  self.m_eq.sh_lambda_sh_b_func(35)
577  result = self.m_eq.get_sh_lambda_sh_b()
578  test_result = 0.02857142857142857
579 
580  # result = float(1 / 35)
581 
582  self.assertAlmostEqual(result, test_result, 5)
583 
584 
586  self.m_eq.sh_c_f_func(35, 0)
587  result = self.m_eq.get_sh_c_f()
588  test_result = 35.0
589 
590  self.assertAlmostEqual(result, test_result, 5)
591 
592 
594  self.m_eq.sh_c_f_func(35, 1)
595  result = self.m_eq.get_sh_c_f()
596  test_result = 0.7892532499999999
597 
598  # result = float(0.94 - (0.0046 * 35) + 8.37 * pow(10, -6) * pow(35, 2))
599 
600  self.assertAlmostEqual(result, test_result, 5)
601 
602 
604  self.m_eq.sh_c_f_func(35, 2)
605  result = self.m_eq.get_sh_c_f()
606  test_result = 0.9170418625000001
607 
608  # result = float(1.07 - 0.0051 * 35 + 2.21 * pow(10, -5) * pow(35, 2) - 3.57 * pow(10, -8) * pow(35, 3))
609 
610  self.assertAlmostEqual(result, test_result, 5)
611 
612 
614  self.m_eq.sh_c_f_func(35, 3)
615  result = self.m_eq.get_sh_c_f()
616  test_result = 0.6171854999999999
617 
618  # result = float(0.75 - 4.06 * pow(10, -3) * 35 + 7.58 * pow(10, -6) * pow(35, 2))
619 
620  self.assertAlmostEqual(result, test_result, 5)
621 
622 
624  self.m_eq.sh_c_f_func(35, 4)
625  result = self.m_eq.get_sh_c_f()
626  test_result = 1.0
627 
628  self.assertAlmostEqual(result, test_result, 5)
629 
630 
632  result = self.m_eq.sh_c_f_hot_rolled(35)
633  test_result = 0.7892532499999999
634 
635  # result = float(0.94 - (0.0046 * 35) + 8.37 * pow(10, -6) * pow(35, 2))
636 
637  self.assertAlmostEqual(result, test_result, 5)
638 
639 
641  result = self.m_eq.sh_c_f_macined(35)
642  test_result = 0.9170418625000001
643 
644  # result = float(1.07 - 0.0051 * 35 + 2.21 * pow(10, -5) * pow(35, 2) - 3.57 * pow(10, -8) * pow(35, 3))
645 
646  self.assertAlmostEqual(result, test_result, 5)
647 
648 
650  result = self.m_eq.sh_c_f_forged(35)
651  test_result = 0.6171854999999999
652 
653  # result = float(0.75 - 4.06 * pow(10, -3) * 35 + 7.58 * pow(10, -6) * pow(35, 2))
654 
655  self.assertAlmostEqual(result, test_result, 5)
656 
657 
659  self.m_eq.sh_c_t_func(150)
660  result = self.m_eq.get_sh_c_t()
661  test_result = 1.0
662 
663  self.assertAlmostEqual(result, test_result, 5)
664 
665 
667  self.m_eq.sh_c_t_func(200)
668  result = self.m_eq.get_sh_c_t()
669  test_result = 1.064516129032258
670 
671  # result = float((460 + 200) / 620)
672 
673  self.assertAlmostEqual(result, test_result, 5)
674 
675 
676  def test_sh_c_dy_func(self):
677  section_dict = {"X": {'length': 3, 'I': 5}, "Y": {'length': 4, 'I': 3}}
678  self.m_eq.sh_c_dy_func(3, 4, 5, section_dict)
679  result = self.m_eq.get_sh_c_dy()
680  test_result = 0.030654222222222225
681 
682  self.assertAlmostEqual(result, test_result, 5)
683 
684 
686  result = self.m_eq.shaft_moment_of_inertia_func(3)
687  test_result = 0.5890486225480862
688 
689  # result = float((math.pi * 3 * 4) / 64)
690 
691  self.assertAlmostEqual(result, test_result, 5)
692 
693 
695  self.m_eq.sh_c_sc_r_func(10, 5, 2, True)
696  result = self.m_eq.get_sh_c_sc_r()
697  test_result = 0.014583783731925789
698 
699  # result = float(pow((0.3) / (10 / 2), (0.2)) * pow((5 / 2), ((1.0) - (10 / 2))))
700 
701  self.assertAlmostEqual(result, test_result, 5)
702 
703 
705  self.m_eq.sh_c_sc_r_func(10, 5, 2, False)
706  result = self.m_eq.get_sh_c_sc_r()
707  test_result = 1.0
708 
709  self.assertAlmostEqual(result, test_result, 5)
710 
711 
712  def test_sh_c_sc_func(self):
713  self.m_eq.sh_c_sc_r_func(10, 5, 2, True)
714  self.m_eq.sh_c_sc_g = 5
715  self.m_eq.sh_c_sc_func()
716  result = self.m_eq.get_sh_c_sc()
717  test_result = 5.014583783731925789
718 
719  self.assertAlmostEqual(result, test_result, 5)
720 
721 # SHAFTS MOTORS FORMULAS - END -
722 
723 # MECHANICAL COUPLINGS MOTORS FORMULAS - START -
724 
726  self.m_eq.cp_lambda_cp_b = 5
727  self.m_eq.cp_c_sf = 4
728  self.m_eq.cp_lambda_h = 3
729  self.m_eq.lambda_cp_func()
730  result = self.m_eq.get_cp_lambda()
731  test_result = 2.3e-05
732 
733  self.assertAlmostEqual(result, test_result, 5)
734 
735 # MECHANICAL COUPLINGS MOTORS FORMULAS - END -
736 
737 # BATTERY FORMULAS - START -
738 
740  self.m_eq.bat_lambda_0 = 5
741  self.m_eq.lambda_bat_func()
742  result = self.m_eq.get_bat_lambda()
743  test_result = 5e-09
744 
745  # result = float(5 * pow(10, -9))
746 
747  self.assertAlmostEqual(result, test_result, 5)
748 
749 # BATTERY FORMULAS - END -
750 
751 
752 if __name__ == '__main__':
753  rosunit.unitrun(PKG, NAME, TestMechanicalEquipment, sysargs = "--cov", coverage_packages=[str(PKG)])


phm_hazard_rate_calculation
Author(s):
autogenerated on Thu Aug 13 2020 16:41:45