Passed
Push — develop ( 51eafa...7602af )
by Plexxi
06:51 queued 03:20
created

PascalRowAction   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 26
rs 10
c 3
b 0
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 2 1
C _compute_pascal_row() 0 22 8
1
import math
2
3
4
from st2actions.runners.pythonrunner import Action
5
6
7
class PascalRowAction(Action):
8
    def run(self, **kwargs):
9
        return PascalRowAction._compute_pascal_row(**kwargs)
10
11
    @staticmethod
12
    def _compute_pascal_row(row_index=0):
13
        if row_index == 'a':
14
            return False, "This is suppose to fail don't worry!!"
15
16
        elif row_index == 'b':
17
            return None
18
19
        elif row_index == 'c':
20
            return False, None
21
22
        elif row_index == 'd':
23
            return "succeeded", [1, 2, 3, 4]
24
25
        elif row_index == 5:
26
            return [math.factorial(row_index) /
27
                    (math.factorial(i) * math.factorial(row_index - i))
28
                    for i in range(row_index + 1)]
29
        else:
30
            return True, [math.factorial(row_index) /
31
                          (math.factorial(i) * math.factorial(row_index - i))
32
                          for i in range(row_index + 1)]
33